ISMPDictionary.java 2.98 KB
package com.sitech.util;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class ISMPDictionary {

	static public String getParent(String ALARM_TYPE) {
		if ((ALARM_TYPE == null) || ALARM_TYPE.equals(""))
			return "";
		String al[] = Formater.split2Array(ALARM_TYPE, "-");
		String KBP_CLASS = "";
		for (int i = 0; i < al.length - 1; i++) {
			if (!al[i + 1].equals("00"))
				KBP_CLASS = KBP_CLASS + "-" + al[i];

			else
				KBP_CLASS = KBP_CLASS + "-" + "00";
		}
		KBP_CLASS = KBP_CLASS + "-" + "00";

		return KBP_CLASS.substring(1);

	}

	static public String getUpParent(String kbpClass) {
		if ((kbpClass == null) || kbpClass.equals("")){
			return "";
		}
		
		int pos = kbpClass.lastIndexOf("-");
		if(pos < 0){
			return "";
		}else{
			return kbpClass.substring(0, pos);
		}
	}
	
	public static void main(String[] args) {
		System.out.println(ISMPDictionary.getUpParent("10"));
	}

	static public ArrayList getGrandsire(String ALARM_TYPE) {
		ArrayList al = new ArrayList();
		if ((ALARM_TYPE == null) || ALARM_TYPE.equals(""))
			return al;
		String pKBP = ALARM_TYPE;
		while (!pKBP.substring(0, 2).equals("00")) {
			al.add(pKBP);
			pKBP = getParent(pKBP);
		}
		al.add(pKBP);
		return al;
	}

	public static List<String> getAllParent(String kbpClass) {
		List<String> result = new ArrayList<String>();
		if ((kbpClass == null) || kbpClass.equals(""))
			return result;
		
		String parentKbpClass = kbpClass;
		while (!parentKbpClass.equals("")) {
			result.add(parentKbpClass);
			parentKbpClass = getUpParent(parentKbpClass);
		}
		return result;
	}

	static public String getKBP_CLASS(String KPI_ID) {
		if ((KPI_ID == null) || KPI_ID.equals(""))
			return "";
		String al[] = Formater.split2Array(KPI_ID, "-");
		String KBP_CLASS = "";
		for (int i = 0; i < 4; i++) {
			if (i < al.length - 2)
				KBP_CLASS = KBP_CLASS + "-" + al[i + 1];
			else
				KBP_CLASS = KBP_CLASS + "-" + "00";
		}
		return KBP_CLASS.substring(1);
	}

	public static boolean compareDate(Date STARTTIME, Date ENDTIME) {
		boolean bool = false;
		if (STARTTIME == null || ENDTIME == null) {
			return true;
		}

		Date TimeCurrent = new Date();
		Calendar cal = Calendar.getInstance();
		cal.setTime(TimeCurrent);

		Calendar cal_STARTTIME = Calendar.getInstance();
		cal_STARTTIME.setTime(STARTTIME);

		Calendar cal_ENDTIME = Calendar.getInstance();
		cal_ENDTIME.setTime(ENDTIME);

		int Time_year = cal.get(Calendar.YEAR);
		int Time_month = cal.get(Calendar.MONTH);
		int Time_day = cal.get(Calendar.DAY_OF_MONTH);

		cal_STARTTIME.set(Calendar.YEAR, Time_year);
		cal_STARTTIME.set(Calendar.MONTH, Time_month);
		cal_STARTTIME.set(Calendar.DAY_OF_MONTH, Time_day);

		cal_ENDTIME.set(Calendar.YEAR, Time_year);
		cal_ENDTIME.set(Calendar.MONTH, Time_month);
		cal_ENDTIME.set(Calendar.DAY_OF_MONTH, Time_day);

		STARTTIME = cal_STARTTIME.getTime();
		ENDTIME = cal_ENDTIME.getTime();

		if (TimeCurrent.after(STARTTIME) && TimeCurrent.before(ENDTIME))
			bool = true;
		return bool;
	}
}