How to use List<PairInt>
Given the code below. I need to replace all occurrences of List<List<Integer>> with List<PairInt>. I could not find this PairInt type/class in a library. Do I need to make a new class and what would that be? Thanks!
public static List<List<Integer>> getIdPairsForOptimal(List<List<Integer>> forwardList,
List<List<Integer>> backwardList, int maxDistance) {
List<List<Integer>> result = new LinkedList<List<Integer>>();
forwardList = forwardList.stream().sorted((x1, x2) -> Integer.compare(x2.get(1), x1.get(1)))
.collect(Collectors.toList());
backwardList = backwardList.stream().sorted((x1, x2) -> Integer.compare(x1.get(1), x2.get(1)))
.collect(Collectors.toList());
int maxDist = maxDistance;
while (true) {
for (List<Integer> l : forwardList) {
for (List<Integer> b : backwardList) {
int forward = l.get(1);
int backward = b.get(1);
int tot = (forward + backward);
if (tot > maxDist) {
break;
}
if (tot == maxDist) {
// print the pair of Id and optimum distance
result.add(Arrays.asList(l.get(0), b.get(0), maxDist));
break;
}
}
}
if (result.size() > 0) {
break;
}
maxDist--;
}
return result;
}
}