package de.nplusc.izc.tools.baseTools;

import java.util.Arrays;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



/**
 *
 * @author LH
 */
public class arraytools {
    protected arraytools()
    {
        
    }
    public static int arrayMaxValue(int[] input)
    {
	int iMax = 0;
	for(int i=0;i<input.length;i++)
	{
	    if(input[i]>iMax)
	    {
		iMax = input[i];
	    }
	}
	return iMax;
    }
    public static int tsvSumUpInCol(String[][] input,int col)
    {
	int sum = 0;
	int value = 0;
	for(int i=0;i<input.length;i++)
	{
	    String entry = input[i][col];
            Tools.DebugHelperPrint(entry, true, "Toolkit.enableCoreDebug");
	    value = Integer.valueOf(entry);
	    sum = sum + value;

	}
	return sum;
    }
    public static int tsvCountDiffInCol(String[] input,int col)
    {
	col = col-1;
	String[] line;
	int cycles = input.length;
	int j=0;
	String[] coldat = new String[cycles];
	for(int i=0;i<cycles;i++)
	{
	    coldat[i] = "";
	}
        for (int i=0;i<cycles;i++)
	{
	    line = input[i].split("\t");
	    String data = line[col];
	    if(arraySearch(coldat,data,j+1)==false)
	    {
		coldat[j] = data;
		j++;
	    }
	    
	}
	return j;
	//return 0;
    }
    public static boolean arraySearch(String[] Searchable,String searched,int length)
    {
	for(int i=0;i<length;i++)
	{
	    if(Searchable[i].equals(searched))
	    {
		i=length;
		return true;
	    }
	}
	return false;
    }
    
    public static int getElemPosInArray(String[] Searchable,String searched)
    {
	for(int i=0;i<Searchable.length;i++)
	{
	    if(Searchable[i].equals(searched))
	    {
		//i=length;
		return i;
	    }
	}
	return -1;
    }
    
	/*
	 Disabled Code
	 public static String[] tsvInCol(String[][]tsv,int Column,int Rows)
	{
		boolean found = false;
		String[] array;
		if (found==afalse)
		{
			array = new String[1];
			array[0] = "NotInArray";
		}
		else
		{
			array = new String[0];
		}
		return array;
	}
	public static String[] tsvInCol(String[][]tsv,int Column)
	{
		return tsvInCol(tsv,Column,-1);
	}
	 */
    public static String ArrayKleben(Object[]o,String k)
    {
        String ret = "";
        for (Object object : o) {
            ret +=o+k;
        }
        
        return ret.substring(0,ret.length()-k.length());
    }
    public static Object[] arrayReverse(Object[] array)
    {

        Object j;
        int k, l;
        Object[] zahlen2 = new Object[array.length];
        for (int i = 0; i < array.length; i++)
        {
            j = array[i];
            k = array.length;
            l = k - i - 1;
            Tools.DebugHelperPrint(k+"", true, "Toolkit.enableFinerDebug");
            zahlen2[l] = array[i];


        }
        array = zahlen2;
        for (Object object : zahlen2)
        {
            Tools.DebugHelperPrint(object+"", true, "Toolkit.enableFinerDebug");
        }
        return array;
    }
    public static <T> T[] concatAll(T[] first, T[]... rest)
    {
        int totalLength = first.length;
        for (T[] array : rest)
        {
            totalLength += array.length;
        }
        T[] result = Arrays.copyOf(first, totalLength);
        int offset = first.length;
        for (T[] array : rest)
        {
            System.arraycopy(array, 0, result, offset, array.length);
            offset += array.length;
        }
        return result;
    }
}
