I have some design problems with Java Comparator Interface.
I have a class which contains a Set of a simple custom data structure:
class data {
Long ID;
int Priority;
...
}
IDs are unique, so it is possible to get the whole data using ID.
and the container class:
class Container {
Set<data> mySet = ...;
List<Long> myList = ...;
...
}
for some inevitable reasons, I need to keep a sorted List of data IDs in parallel. I need the List to be sorted by Priority.
Since, the Comparator should compare Prioritys it should implements Comparator<int>. But the List only contains IDs and the Prioritys are not available directly.
This is the problem. There is only ID in the List. Therefore, the Comparator class has no access to Priority.
How can I design such concept?
mySet.objectfrom that Set for eachIdand check itsPriority.. have agetDataById()method in your class.