I have multiple Gateways which gives the information of various devices along with the distance. I want to extract information like which device is having a low distance in which gateway. Currently, I combined the results into HashMap within HashMap like this code:
Map<String, Map<String, Double>> averageDistances = calculateAverageDistances(data);
for (Map.Entry<String, Map<String, Double>> entry : averageDistances.entrySet()) {
String gateway = entry.getKey();
System.out.println("Gateway: " + gateway);
Map<String, Double> deviceDistances = entry.getValue();
for (Map.Entry<String, Double> deviceEntry : deviceDistances.entrySet()) {
String device = deviceEntry.getKey();
double averageDistance = deviceEntry.getValue();
System.out.println("Device: " + device + ", Average Distance: " + averageDistance);
}
}
Which is showing the result like that:
Gateway: AC233FC0FA9F
Device: AC233FAC9623, Average Distance: 7.1
Device: AC233FAC9624, Average Distance: 4.3
Gateway: AC233FC0FAAE
Device: AC233FAC9623, Average Distance: 11.850000000000001
Device: AC233FAC9624, Average Distance: 0.8
I want the final result like as a device(AC233FAC9623) is present in both gateways(AC233FC0FA9F and AC233FC0FAAE), it is having a lower distance in the gateway(AC233FC0FA9F) so consider this record only. Same as the device(AC233FAC9624) is having a lower distance in the gateway(AC233FC0FAAE) so consider this record. A final output should be like this:
Gateway: AC233FC0FA9F
Device: AC233FAC9623, Average Distance: 7.1
Gateway: AC233FC0FAAE
Device: AC233FAC9624, Average Distance: 0.8
Can someone hint which data structure should be used here?