00001 package commandline.Algorithms;
00002 import java.util.ArrayList;
00003
00004 import commandline.debuggingCode.Debug;
00005
00006
00007
00008
00009 public class ArrayHandler {
00010
00014 int[][] gegevens;
00015 public ArrayHandler(int[][] gegevens) {
00016 this.gegevens=gegevens;
00017 }
00018
00019 public int[][] getBeginElementen(int index){
00020 int[][] result=new int[index+1][2];
00021 for(int i =0;i!=result.length;i++){
00022 result[i][0]=gegevens[i][0];
00023 result[i][1]=gegevens[i][1];
00024 }
00025 return result;
00026 }
00027
00028
00029 public int[][] getEindElementen(int index){
00030 int[][] result=new int[gegevens.length-index][2];
00031 for(int i =index;i!=gegevens.length;i++){
00032 result[i-index][0]=gegevens[i][0];
00033 result[i-index][1]=gegevens[i][1];
00034 }
00035 return result;
00036 }
00037
00038 public static float mean(float[] rij){
00039 float sum=totaal(rij);
00040 return sum/(float)(rij.length);
00041 }
00042
00043
00044 public static float totaal(float[] rij){
00045 float sum=0;
00046 for(int i=0;i!=rij.length;i++){
00047 sum+=rij[i];
00048 }
00049
00050 return sum;
00051 }
00052
00053 public static double totaal(double[] rij){
00054 double sum=0;
00055 for(int i=0;i!=rij.length;i++){
00056 sum+=rij[i];
00057 }
00058
00059 return sum;
00060 }
00061
00062
00063 public static float[] repmat(float[] a,int keer){
00064 float[] result=new float[a.length*keer];
00065 for(int i=1;i<=keer;i++){
00066 for(int k=0;k!=a.length;k++){
00067 result[(i-1)*a.length+k]=a[k];
00068 }
00069 }
00070 return result;
00071 }
00072
00073
00074 public static int getMaxPos(float[] rij){
00075 int pos=-1;
00076 float max=Float.NEGATIVE_INFINITY;
00077 for(int i=0;i!=rij.length;i++){
00078 if(rij[i]>max){
00079 pos=i;
00080 max=rij[i];
00081 }
00082
00083 }
00084 if(pos==-1){
00085 Debug.print("ERROR IN ARRAYHANDLER: getMaxPos ; pos:= "+pos);
00086 Debug.print("de rij ziet er als volgt uit:");
00087 printrij(rij);
00088 }
00089
00090 return pos;
00091 }
00092
00093 public static int getMaxPos(ArrayList<Double> rij) {
00094 int pos = -1;
00095 double max = Double.NEGATIVE_INFINITY;
00096 for (int i = 0; i != rij.size(); i++) {
00097 if (rij.get(i) > max) {
00098 pos = i;
00099 max = rij.get(i);
00100 }
00101 }
00102 if (pos == -1) {
00103 Debug.print("ERROR IN ARRAYHANDLER: getMaxPos ; pos:= "
00104 + pos);
00105 Debug.print("de rij ziet er als volgt uit:");
00106 }
00107 return pos;
00108 }
00109
00110 public static int getMaxPos(double[] rij){
00111 int pos=-1;
00112 double max=Float.NEGATIVE_INFINITY;
00113 for(int i=0;i!=rij.length;i++){
00114 if(rij[i]>max){
00115 pos=i;
00116 max=rij[i];
00117 }
00118
00119 }
00120 if(pos==-1){
00121 Debug.print("ERROR IN ARRAYHANDLER: getMaxPos ; pos:= "+pos);
00122 Debug.print("de rij ziet er als volgt uit:");
00123 printrij(rij);
00124 }
00125
00126 return pos;
00127 }
00128
00129
00130
00131 public static int getMinPos(float[] rij){
00132 int pos=-1;
00133 float min=Float.POSITIVE_INFINITY;
00134 for(int i=0;i!=rij.length;i++){
00135 if(rij[i]<min){
00136 pos=i;
00137 min=rij[i];
00138 }
00139
00140 }
00141 if(pos==-1){
00142 Debug.print("ERROR IN ARRAYHANDLER: getMinPos ; pos:= "+pos);
00143 Debug.print("de rij ziet er als volgt uit:");
00144 printrij(rij);
00145 }
00146
00147 return pos;
00148 }
00149
00150 public static int getMinPos(double[] rij){
00151 int pos=-1;
00152 double min=Float.POSITIVE_INFINITY;
00153 for(int i=0;i!=rij.length;i++){
00154 if(rij[i]<min){
00155 pos=i;
00156 min=rij[i];
00157 }
00158
00159 }
00160 if(pos==-1){
00161 Debug.print("ERROR IN ARRAYHANDLER: getMinPos ; pos:= "+pos);
00162 Debug.print("de rij ziet er als volgt uit:");
00163 printrij(rij);
00164 }
00165
00166 return pos;
00167 }
00168
00169
00170 public static int getMinPos(ArrayList<Double> rij){
00171 int pos=-1;
00172 double min=Double.POSITIVE_INFINITY;
00173 for(int i=0;i!=rij.size();i++){
00174 if(rij.get(i)<min){
00175 pos=i;
00176 min=rij.get(i);
00177 }
00178
00179 }
00180 if(pos==-1){
00181 Debug.print("ERROR IN ARRAYHANDLER: getMinPos ; pos:= "+pos);
00182 Debug.print("de rij ziet er als volgt uit:");
00183 }
00184
00185 return pos;
00186 }
00187
00188
00189 public static float[] getPartOfArray(float[][] rij,int kolom){
00190 float[] result=new float[rij.length];
00191 for(int i=0;i!=rij.length;i++){
00192 result[i]=rij[i][kolom];
00193 }
00194 return result;
00195 }
00196
00197 public static void printrij(float[] rij){
00198 Debug.print("[");
00199 for(int i=0;i!=rij.length;i++){
00200 Debug.print(rij[i]+";");
00201 }
00202 Debug.print("]");
00203 }
00204
00205
00206 public static void printrij(int[][] rij){
00207 for(int i=0;i!=rij.length;i++){
00208 printrij_horizontaal(rij[i]);
00209 }
00210
00211 }
00212
00213 public static void printrij(int[] rij){
00214
00215 for(int i=0;i!=rij.length;i++){
00216 Debug.print(""+rij[i]);
00217 }
00218
00219 }
00220
00221 public static void printrij(ArrayList<String> rij){
00222 for(String p:rij){
00223 System.out.print(p);
00224 }
00225 }
00226
00227 public static void printrij(double[] rij){
00228 Debug.print("[");
00229 for(int i=0;i!=rij.length;i++){
00230 Debug.print(""+rij[i]);
00231 }
00232 Debug.print("]");
00233 }
00234
00235 public static void printrij_horizontaal(int[] rij){
00236
00237 for(int i=0;i!=rij.length;i++){
00238 System.out.print(rij[i]+" ");
00239 }Debug.print("");
00240
00241 }
00242
00243 public static void printrij_horizontaal(float[] rij){
00244
00245 for(int i=0;i!=rij.length;i++){
00246 System.out.print(rij[i]+" ");
00247 }
00248
00249 }
00250
00251
00252 public static int[][] Flip(int[][] rij){
00253 int[][] temp=new int[rij.length][2];
00254
00255 for(int i=0;i!=rij.length;i++){
00256 temp[rij.length-i-1][0]=rij[i][0];
00257 temp[rij.length-i-1][1]=rij[i][1];
00258 }
00259
00260 return temp;
00261 }
00262
00263 public static int[] Flip(int[] rij){
00264 int[]temp=new int[rij.length];
00265
00266 for(int i=0;i!=rij.length;i++){
00267 temp[rij.length-i-1]=rij[i];
00268 }
00269
00270 return temp;
00271 }
00272
00273 public static float[] Flip(float[] rij){
00274 float[]temp=new float[rij.length];
00275
00276 for(int i=0;i!=rij.length;i++){
00277 temp[rij.length-i-1]=rij[i];
00278 }
00279
00280 return temp;
00281 }
00282
00283
00284
00285 public static void main (String args[]){
00286 int[][] waarden=new int[5][2];
00287 waarden[0][0]=1;
00288 waarden[0][1]=2;
00289 waarden[4][0]=5;
00290 waarden[4][1]=6;
00291 int[][] reverse=ArrayHandler.Flip(waarden);
00292 for(int i=0;i!=waarden.length;i++){
00293 Debug.print("(" +waarden[i][0] +"," +waarden[i][1]+")");
00294 }
00295 Debug.print("--------------------");
00296 for(int i=0;i!=reverse.length;i++){
00297 Debug.print("(" +reverse[i][0] +"," +reverse[i][1]+")");
00298 }
00299
00300 }
00301
00302 }