im having a hard time understanding Maps and i was asked to make a SortedMap with a different key and value out of another map using a comparator and a supplier. Its said to us that the "teams" key is the name of a team and the value is the information of the team, and the new sorted map has as a key the points that a team has and as a value the colection of team names with that points, the colection is given by the supplier. i dont get how i will make that happen. i thought of verifing if in "teams" there is a key with on of the suppliers name by iterating this one and if there was i would save that name in an List. but after that i dont know how i would build the SortedMap. Any suggestions?
Edited: This was what i did.
public static <C extends Collection<String>> SortedMap<Integer, C> toTable(Map<String, Team> teams, Comparator<Integer> cmp, Supplier<C> supplier) {
SortedMap<Integer, C> sm = new TreeMap<Integer, C>(cmp);
List<C> aux= new ArrayList<C>();
C newTeam = null;
int totalNames = supplier.get().size();
while(totalNames>0) {
if(teams.containsKey(supplier.get().iterator().next()))
aux.add(supplier.get());
totalNames--;
}
int size = aux.size();
while (size>0){
sm.put(1/*how to get a new key*/,aux.iterator().next());
size--;
}
return sm;
}