Android Comparing points
Currently I'm making an app for Android and I have stumbled upon a problem - I have 12 points (A, B, C, D, E, F, G, Q, N, L, M and K)
. I need to do some stuff with 6 highest points.
To do the calculations I wrote this code:
List<Integer> YPoint = new java.util.ArrayList(Arrays.asList(A.y, B.y, C.y, D.y, E.y, F.y, G.y, K.y, Q.y, L.y, M.y, N.y));
List<Integer> YUpper = new java.util.ArrayList(Arrays.asList());
int Classified = 0;
int Highest = 0;
while(Classified != 6){
Highest = Collections.min(YPoint);
YPoint.remove(Integer.valueOf(Highest));
YUpper.add(Integer.valueOf(Highest));
Classified++;
}
android.graphics.Point Highest1 = new android.graphics.Point();
android.graphics.Point Highest2 = new android.graphics.Point();
android.graphics.Point Highest3 = new android.graphics.Point();
android.graphics.Point Highest4 = new android.graphics.Point();
android.graphics.Point Highest5 = new android.graphics.Point();
android.graphics.Point Highest6 = new android.graphics.Point();
boolean notdone = false;
if(YUpper.contains(A.y)){
if(Highest1.x == 0 && !notdone){Highest1 = A; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = A; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = A; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = A; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = A; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = A; notdone = true;}
notdone = false;
}
if(YUpper.contains(B.y)){
if(Highest1.x == 0 && !notdone){Highest1 = B; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = B; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = B; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = B; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = B; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = B; notdone = true;}
notdone = false;
}
if(YUpper.contains(C.y)){
if(Highest1.x == 0 && !notdone){Highest1 = C; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = C; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = C; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = C; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = C; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = C; notdone = true;}
notdone = false;
}
if(YUpper.contains(E.y)){
if(Highest1.x == 0 && !notdone){Highest1 = E; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = E; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = E; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = E; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = E; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = E; notdone = true;}
notdone = false;
}
if(YUpper.contains(D.y)){
if(Highest1.x == 0 && !notdone){Highest1 = D; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = D; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = D; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = D; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = D; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = D; notdone = true;}
notdone = false;
}
if(YUpper.contains(F.y)){
if(Highest1.x == 0 && !notdone){Highest1 = F; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = F; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = F; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = F; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = F; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = F; notdone = true;}
notdone = false;
}
if(YUpper.contains(G.y)){
if(Highest1.x == 0 && !notdone){Highest1 = G; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = G; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = G; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = G; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = G; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = G; notdone = true;}
notdone = false;
}
if(YUpper.contains(Q.y)){
if(Highest1.x == 0 && !notdone){Highest1 = Q; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = Q; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = Q; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = Q; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = Q; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = Q; notdone = true;}
notdone = false;
}
if(YUpper.contains(K.y)){
if(Highest1.x == 0 && !notdone){Highest1 = K; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = K; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = K; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = K; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = K; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = K; notdone = true;}
notdone = false;
}
if(YUpper.contains(N.y)){
if(Highest1.x == 0 && !notdone){Highest1 = N; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = N; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = N; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = N; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = N; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = N; notdone = true;}
notdone = false;
}
if(YUpper.contains(L.y)){
if(Highest1.x == 0 && !notdone){Highest1 = L; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = L; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = L; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = L; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = L; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = L; notdone = true;}
notdone = false;
}
if(YUpper.contains(M.y)){
if(Highest1.x == 0 && !notdone){Highest1 = M; notdone = true;}
if(Highest2.x == 0 && !notdone){Highest2 = M; notdone = true;}
if(Highest3.x == 0 && !notdone){Highest3 = M; notdone = true;}
if(Highest4.x == 0 && !notdone){Highest4 = M; notdone = true;}
if(Highest5.x == 0 && !notdone){Highest5 = M; notdone = true;}
if(Highest6.x == 0 && !notdone){Highest6 = M; notdone = true;}
notdone = false;
}
YPoint.remove(Integer.valueOf(Highest1.y));
YPoint.remove(Integer.valueOf(Highest2.y));
YPoint.remove(Integer.valueOf(Highest3.y));
YPoint.remove(Integer.valueOf(Highest4.y));
YPoint.remove(Integer.valueOf(Highest5.y));
YPoint.remove(Integer.valueOf(Highest6.y));
Simply put, my code follows this algorithm:
- Make a list of 12 points
Y
coordinates - Get 6
int
's from the list with minY
coordinates(corresponds to highest) - Find points that correspond to those 6 ints from 2
- Make new 6 points and set their coordinates to points from 3 - I duplicate points so I can use them in further calculations.
This code above works, but it's huge and messy. Is there any good and clean alternative for this?
Source: View source