arraytools.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package de.nplusc.izc.tools.baseTools;
  2. import java.util.Arrays;
  3. /*
  4. * To change this template, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. /**
  8. *
  9. * @author LH
  10. */
  11. public class arraytools {
  12. protected arraytools()
  13. {
  14. }
  15. public static int arrayMaxValue(int[] input)
  16. {
  17. int iMax = 0;
  18. for(int i=0;i<input.length;i++)
  19. {
  20. if(input[i]>iMax)
  21. {
  22. iMax = input[i];
  23. }
  24. }
  25. return iMax;
  26. }
  27. public static int tsvSumUpInCol(String[][] input,int col)
  28. {
  29. int sum = 0;
  30. int value = 0;
  31. for(int i=0;i<input.length;i++)
  32. {
  33. String entry = input[i][col];
  34. Tools.DebugHelperPrint(entry, true, "Toolkit.enableCoreDebug");
  35. value = Integer.valueOf(entry);
  36. sum = sum + value;
  37. }
  38. return sum;
  39. }
  40. public static int tsvCountDiffInCol(String[] input,int col)
  41. {
  42. col = col-1;
  43. String[] line;
  44. int cycles = input.length;
  45. int j=0;
  46. String[] coldat = new String[cycles];
  47. for(int i=0;i<cycles;i++)
  48. {
  49. coldat[i] = "";
  50. }
  51. for (int i=0;i<cycles;i++)
  52. {
  53. line = input[i].split("\t");
  54. String data = line[col];
  55. if(arraySearch(coldat,data,j+1)==false)
  56. {
  57. coldat[j] = data;
  58. j++;
  59. }
  60. }
  61. return j;
  62. //return 0;
  63. }
  64. public static boolean arraySearch(String[] Searchable,String searched,int length)
  65. {
  66. for(int i=0;i<length;i++)
  67. {
  68. if(Searchable[i].equals(searched))
  69. {
  70. i=length;
  71. return true;
  72. }
  73. }
  74. return false;
  75. }
  76. public static int getElemPosInArray(String[] Searchable,String searched)
  77. {
  78. for(int i=0;i<Searchable.length;i++)
  79. {
  80. if(Searchable[i].equals(searched))
  81. {
  82. //i=length;
  83. return i;
  84. }
  85. }
  86. return -1;
  87. }
  88. /*
  89. Disabled Code
  90. public static String[] tsvInCol(String[][]tsv,int Column,int Rows)
  91. {
  92. boolean found = false;
  93. String[] array;
  94. if (found==afalse)
  95. {
  96. array = new String[1];
  97. array[0] = "NotInArray";
  98. }
  99. else
  100. {
  101. array = new String[0];
  102. }
  103. return array;
  104. }
  105. public static String[] tsvInCol(String[][]tsv,int Column)
  106. {
  107. return tsvInCol(tsv,Column,-1);
  108. }
  109. */
  110. public static String ArrayKleben(Object[]o,String k)
  111. {
  112. String ret = "";
  113. for (Object object : o) {
  114. ret +=o+k;
  115. }
  116. return ret.substring(0,ret.length()-k.length());
  117. }
  118. public static Object[] arrayReverse(Object[] array)
  119. {
  120. Object j;
  121. int k, l;
  122. Object[] zahlen2 = new Object[array.length];
  123. for (int i = 0; i < array.length; i++)
  124. {
  125. j = array[i];
  126. k = array.length;
  127. l = k - i - 1;
  128. Tools.DebugHelperPrint(k+"", true, "Toolkit.enableFinerDebug");
  129. zahlen2[l] = array[i];
  130. }
  131. array = zahlen2;
  132. for (Object object : zahlen2)
  133. {
  134. Tools.DebugHelperPrint(object+"", true, "Toolkit.enableFinerDebug");
  135. }
  136. return array;
  137. }
  138. public static <T> T[] concatAll(T[] first, T[]... rest)
  139. {
  140. int totalLength = first.length;
  141. for (T[] array : rest)
  142. {
  143. totalLength += array.length;
  144. }
  145. T[] result = Arrays.copyOf(first, totalLength);
  146. int offset = first.length;
  147. for (T[] array : rest)
  148. {
  149. System.arraycopy(array, 0, result, offset, array.length);
  150. offset += array.length;
  151. }
  152. return result;
  153. }
  154. }