@@ -0,0 +1,2794 @@
+/**%0A * %0A */%0Apackage mathsquared.resultswizard2;%0A%0Aimport java.util.Comparator;%0Aimport java.util.Map;%0A%0A/**%0A * Compares two keys based on the values associated with them in the given Map. The values are sorted in descending order. Null values are ranked greater than everything else, placing them last on a sorted list.%0A * %0A * @author MathSquared%0A * @param %3CK%3E the keys of the Map that we are comparing%0A * @param %3CV%3E the values of the Map that we are comparing%0A * %0A */%0Apublic class DescendingMapValueComparator%3CK, V extends Comparable%3CV%3E%3E implements Comparator%3CK%3E %7B%0A    private Map%3CK, V%3E toCompare;%0A%0A    /**%0A     * Constructs a new DescendingMapValueComparator pulling values from the given Map.%0A     * %0A     * @param toCompare a Map from which to pull the values used in comparison%0A     */%0A    public DescendingMapValueComparator (Map%3CK, V%3E toCompare) %7B%0A        this.toCompare = toCompare;%0A    %7D%0A%0A    /**%0A     * Compares two keys based on their values in the given Map. Note that this comparator uses the opposite of the natural ordering of the values.%0A     * %0A     * %3Cp%3E%0A     * Nulls are compared as greater than everything else. This places them at the end of a sorted list.%0A     * %3C/p%3E%0A     * %0A     * %3Cp%3E%0A     * Formally: let %3Ccode%3Ec%3C/code%3E be a DescendingMapValueComparator, %3Ccode%3EfVal%3C/code%3E be equal to %3Ccode%3E%7B@link #DescendingMapValueComparator(Map) toCompare%7D.get(first)%3C/code%3E, and %3Ccode%3EsVal%3C/code%3E be equal to %3Ccode%3EtoCompare.get(second)%3C/code%3E. Then:%0A     * %3C/p%3E%0A     * %0A     * %3Cul%3E%0A     * %3Cli%3EIf %3Ccode%3EfVal%3C/code%3E and %3Ccode%3EsVal%3C/code%3E are both null, this method returns 0.%3C/li%3E%0A     * %3Cli%3EOtherwise, if %3Ccode%3EfVal%3C/code%3E is null but %3Ccode%3EsVal%3C/code%3E is not, this method returns 1.%3C/li%3E%0A     * %3Cli%3EOtherwise, if %3Ccode%3EsVal%3C/code%3E is null but %3Ccode%3EfVal%3C/code%3E is not, this method returns -1.%3C/li%3E%0A     * %3Cli%3EOtherwise, this method returns %3Ccode%3EsVal.compareTo(fVal)%3C/code%3E. If %3Ccode%3EV%3C/code%3E implements %7B@link Comparable%7D correctly, this should be equal to %3Ccode%3E-fVal.compareTo(sVal)%3C/code%3E.%3C/li%3E%0A     * %3C/ul%3E%0A     * %0A     * @param first the first key to compare%0A     * @param second the second key to compare%0A     * @return the descending-order sort of the keys based on their values in %3Ccode%3EtoCompare%3C/code%3E, as described above%0A     */%0A    public int compare (K first, K second) %7B%0A        V fVal = toCompare.get(first);%0A        V sVal = toCompare.get(second);%0A%0A        // Handle nulls%0A        if (fVal == null) %7B%0A            if (sVal == null) %7B%0A                return 0;%0A            %7D else %7B // compare(null, 0)%0A                return 1;%0A            %7D%0A        %7D else %7B%0A            if (sVal == null) %7B // compare(0, null)%0A                return -1;%0A            %7D else %7B%0A                return sVal.compareTo(fVal); // reverse for descending order%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add DescendingMapValueComparator