/*********************************************************************************************************
 * 프로그램명 : ArrayUtil.java 프로그램설명 : 프로젝트와 관련된 정보를 얻을수 있는 class 작성자 : 강원중 작성일 : 2004.01.06 변경일 : 2003.11.30
 **********************************************************************************************************/

package kr.co.kihyun.lang;

// FIXME: remove me
public class ArrayUtil {
	public static Long[] delte(Long[] origList, Long[] delList) throws ArrayIndexOutOfBoundsException {
		boolean isEquals;

		if (origList == null || delList == null) {
			return origList;
		}

		for (int i = 0, j = 0; i < origList.length; i++) {
			isEquals = false;
			for (j = 0; j < delList.length; j++) {
				if (origList[i].equals(delList[j])) {
					isEquals = true;
				}
			}

			if (isEquals) {
				origList[i] = null;
			}
		}

		return getNotNullList(origList);
	}

	public static Long[] getNotNullList(Long[] oldList) throws ArrayIndexOutOfBoundsException {
		if (oldList == null) {
			return oldList;
		}

		int count = 0;
		for (int i = 0; i < oldList.length; i++) {
			if (oldList[i] != null) {
				count++;
			}
		}

		Long[] newList = new Long[count];
		count = 0;
		for (int i = 0; i < oldList.length && count < newList.length; i++) {
			if (oldList[i] != null) {
				newList[count] = oldList[i];
				count++;
			}
		}

		return newList;
	}

	public static String[] delte(String[] origList, String[] delList) throws ArrayIndexOutOfBoundsException {
		boolean isEquals;

		if (origList == null || delList == null) {
			return origList;
		}

		for (int i = 0, j = 0; i < origList.length; i++) {
			isEquals = false;
			for (j = 0; j < delList.length; j++) {
				if (origList[i].equals(delList[j])) {
					isEquals = true;
				}
			}

			if (isEquals) {
				origList[i] = "";
			}
		}

		return getNotNullList(origList);
	}

	public static String[] getNotNullList(String[] oldList) throws ArrayIndexOutOfBoundsException {
		if (oldList == null) {
			return oldList;
		}

		int count = 0;
		for (int i = 0; i < oldList.length; i++) {
			if (oldList[i] != null && !oldList[i].trim().equals("")) {
				count++;
			}
		}

		String[] newList = new String[count];
		count = 0;
		for (int i = 0; i < oldList.length && count < newList.length; i++) {
			if (oldList[i] != null && !oldList[i].trim().equals("")) {
				newList[count] = oldList[i];
				count++;
			}
		}

		return newList;
	}
}
