/**
 * Copyright © 2008-2009 DRIVER PROJECT (ICM UW)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package eu.dnetlib.resultset.impl;

/**
 * ResultSet utilities.
 * @author Marek Horst
 * @version 0.01
 *
 */
public class ResultSetUtils {

	/**
	 * 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;
	}
	
	/**
	 * Returns subarray of array given as parameter.
	 * All params need to be previously validated. 
	 * @param srcArray
	 * @param fromPosition
	 * @param toPosition
	 * @return result subarray of array given as parameter
	 */
	public static String[] getSubArray(String[] srcArray, int fromPosition, int toPosition) {
		String[] resultArray = new String[toPosition-fromPosition+1];
		int counter=0;
		for (int i=fromPosition; i<=toPosition; i++) {
			resultArray[counter] = srcArray[i];
			counter++;
		}
		return resultArray;
	}
}
