package eu.dnetlib.enabling.aas.utils;

import eu.dnetlib.enabling.aas.rmi.TypedString;

/**
 * Common utilities class.
 * @author mhorst
 *
 */
public class CommonUtils {

	/**
	 * Joins two tables of the same TypedString type.
	 * Never returns null.
	 * @param tab1
	 * @param tab2
	 * @return conjoined TypedString[] result table.
	 */
	public static TypedString[] joinTypedStringTables(TypedString[] tab1, TypedString[] tab2) {
		int totalLength=0;
		if (tab1 != null)
			totalLength = tab1.length;
		int table1Length = totalLength;
		if (tab2 != null)
			totalLength += tab2.length;
		TypedString[] result = new TypedString[totalLength];
		if (tab1 != null)
			for (int i=0; i< tab1.length; i++)
				result[i]=tab1[i];
		if (tab2 != null)
			for (int i=0; i< tab2.length; i++)
				result[table1Length+i]=tab2[i];
		return result;
	}
	
	/**
	 * Joins two tables of the same String type.
	 * Never returns null.
	 * @param tab1
	 * @param tab2
	 * @return conjoined String[] result table.
	 */
	public static String[] joinStringTables(String[] tab1, String[] tab2) {
		int totalLength=0;
		if (tab1 != null)
			totalLength = tab1.length;
		int table1Length = totalLength;
		if (tab2 != null)
			totalLength += tab2.length;
		String[] result = new String[totalLength];
		if (tab1 != null)
			for (int i=0; i< tab1.length; i++)
				result[i]=tab1[i];
		if (tab2 != null)
			for (int i=0; i< tab2.length; i++)
				result[table1Length+i]=tab2[i];
		return result;
	}
}
