Write me a code that sorts a list of "Test" object regarding their value in a HashMap object.
import java.util.Comparator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; class Test { String name; int rank; public Test(String name, int rank) { this.name = name; this.rank = rank; } public String getName() { return name; } public int getRank() { return rank; } } class Solution { public List<Test> sortTests(List<Test> tests, Map<String, Integer> ranks) { return tests.stream() .distinct() .sorted(Comparator.comparingInt(test -> ranks.getOrDefault(test.getName(), 0))) .collect(Collectors.toList()); } }