@@ -0,0 +1,2453 @@
+/**%0A * %0A */%0Apackage mathsquared.resultswizard2;%0A%0Aimport java.util.Collections;%0Aimport java.util.Comparator;%0Aimport java.util.LinkedHashMap;%0Aimport java.util.LinkedList;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0A/**%0A * Contains methods for working with maps and sorting them.%0A * %0A * @author MathSquared%0A * %0A */%0Apublic class MapSortingUtils %7B%0A    /**%0A     * Returns a version of the given Map sorted by its values.%0A     * %0A     * %3Cp%3E%0A     * Specifically, returns a new Map containing the same keys as %3Ccode%3EtoSort%3C/code%3E whose iteration order follows the natural ordering of its keys. If %3Ccode%3Edescending%3C/code%3E is true, this ordering is reversed.%0A     * %3C/p%3E%0A     * %0A     * %3Cp%3E%0A     * Nulls compare as less than everything else. That is, they will sort before everything else in an ascending sort, and after everything else in a descending sort.%0A     * %3C/p%3E%0A     * %0A     * @param toSort the map to sort%0A     * @param descending true if the highest values should sort to the beginning%0A     * @return a new Map with its keys sorted in the natural order of their associated values%0A     */%0A    public static %3CK, V extends Comparable%3C? super V%3E%3E Map%3CK, V%3E sortValue (Map%3CK, V%3E toSort, boolean descending) %7B%0A        // Set up ascending or descending.%0A        final int mult = (descending) ? -1 : 1; // if descending, multiply all comparisons by -1%0A%0A        // HEAVILY based on http://stackoverflow.com/a/2581754/1979005%0A        List%3CMap.Entry%3CK, V%3E%3E entries = new LinkedList%3CMap.Entry%3CK, V%3E%3E(toSort.entrySet());%0A        Collections.sort(entries, new Comparator%3CMap.Entry%3CK, V%3E%3E() %7B%0A            public int compare (Map.Entry%3CK, V%3E one, Map.Entry%3CK, V%3E two) %7B%0A                if (one == null) %7B // sort nulls less than everything else (before in ascending, after in descending)%0A                    if (two == null) %7B%0A                        return 0;%0A                    %7D else %7B // (null, *)%0A                        return -1 * mult;%0A                    %7D%0A                %7D else %7B%0A                    if (two == null) %7B // (*, null)%0A                        return 1 * mult;%0A                    %7D else %7B%0A                        return mult * one.getValue().compareTo(two.getValue());%0A                    %7D%0A                %7D%0A            %7D%0A        %7D);%0A        Map%3CK, V%3E ret = new LinkedHashMap%3CK, V%3E(); // preserve iteration order%0A        for (Map.Entry%3CK, V%3E x : entries) %7B%0A            ret.put(x.getKey(), x.getValue());%0A        %7D%0A        return ret;%0A    %7D%0A%7D%0A

Add MapSortingUtils and sortValue