I have a set of values stored in Map/HashMap. Then I did a triple for loop to compare the values. The values are compared this way: First get the values for 0-1 then compare it to a set of values that starts with 1-x [1-2, 1-3,…1-n]. IF and ONLY IF the value of (e.g 0-1) is BIGGER THAN all the other values in the 1-x set value (e.g: 1-2, 1-3,…1-n), the IF-ELSE statement will trigger an event.
An example of the data is given in the code snippet below:
import java.util.HashMap;
import java.util.Map;
public class CompareSequence{
public static void main(String[] args)
{
Map<String, Integer> myMap = new HashMap<String, Integer>();
myMap.put("0-1", 33);
myMap.put("0-2", 29);
myMap.put("0-3", 14);
myMap.put("0-4", 8);
myMap.put("1-2", 37);
myMap.put("1-3", 45);
myMap.put("1-4", 17);
myMap.put("2-3", 1);
myMap.put("2-4", 16);
myMap.put("3-4", 18);
for(int i = 0; i < 5; i++)
{
for(int j = i+1; j < 5; j++)
{
String testLine = i+"-"+j;
int itemA = myMap.get(testLine);
for(int k = j+1; k < 5; k++)
{
String newLine = j+"-"+k;
int itemB = myMap.get(newLine);
if(itemA > itemB)
{
//IF and ONLY all values of item A that is passed through is bigger than item B
//THEN trigger an event to group item B with A
System.out.println("Item A : " + itemA + " is bigger than item "
+ newLine + " (" +itemB + ")"); // Printing out results to check the loop
}
else
{
System.out.println("Comparison failed: Item " + itemA + " is smaller than " + newLine + " (" + itemB + ")");
}
}
}
}
}
}
Current Result:
Get main value for comparison: myMap.get(0-1) = 33
Get all values related to Key 1-x (set value) ..
myMap.get(1-2) = 37 // This value is bigger than myMap.get(0-1) = 33
myMap.get(1-3) = 45 // This value is bigger than myMap.get(0-1) = 33
myMap.get(1-4) = 17 // This value is smaller than myMap.get(0-1) = 33
In that example given, the IF-ELSE statement should not let it pass, ONLY if all are smaller than 33, should an event be triggered. Is there something different I should do to the IF-ELSE statement or is there a problem with my loop?
Desired Result:
If((myMap.get(0-1) > myMap.get(1-2)) && (myMap.get(0-1) > myMap.get(1-3)) && (myMap.get(0-1) > myMap.get(1-4))...(myMap.get(0-1) > myMap.get(1-n))
{
//Trigger event to group all set values 1-x to value key 0-1
//Then delete all set valued related to 1-x from list
}
Any advice or help would be greatly appreciated. Thank you!
You could try something like this: