src/retrieval based query topic analysis/src/edu/virginia/cs/utility/MapUtilities.java
public static <K, V> Map<K, V> sortMapByValue(Map<K, V> unsortMap, final boolean order) {
        List<Map.Entry<K, V>> list = new LinkedList<>(unsortMap.entrySet());
        Collections.sort(list, new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                if (order) {
                    return ((Comparable<V>) ((Map.Entry<K, V>) (o1)).getValue()).compareTo(((Map.Entry<K, V>) (o2)).getValue());
                } else {
                    return ((Comparable<V>) ((Map.Entry<K, V>) (o2)).getValue()).compareTo(((Map.Entry<K, V>) (o1)).getValue());
                }
            }
        });

        Map<K, V> result = new LinkedHashMap<>();
        for (Map.Entry<K, V> entry : list) {
            result.put(entry.getKey(), entry.getValue());
        }

        return result;
    }
/**
     * Method that generate the id of all users for evaluation.
     *
     * @param unsortMap unsorted Map
     * @param order if true, then sort in ascending order, otherwise in
     * descending order
     * @return sorted Map
     */
Method that generate the id of all users for evaluation.
@param unsortMap unsorted Map
@param order if true, then sort in ascending order, otherwise in
descending order
@return sorted Map
Method that generate the id of all users for evaluation . @param unsortMap unsorted Map @param order if true then sort in ascending order otherwise in descending order @return sorted Map
public static <K, V> Map<K, V> sortMapByValue(Map<K, V> unsortMap, final boolean order) {
        List<Map.Entry<K, V>> list = new LinkedList<>(unsortMap.entrySet());
        Collections.sort(list, new Comparator<Object>() {
            @Override
            public int compare(Object o1, Object o2) {
                if (order) {
                    return ((Comparable<V>) ((Map.Entry<K, V>) (o1)).getValue()).compareTo(((Map.Entry<K, V>) (o2)).getValue());
                } else {
                    return ((Comparable<V>) ((Map.Entry<K, V>) (o2)).getValue()).compareTo(((Map.Entry<K, V>) (o1)).getValue());
                }
            }
        });
        Map<K, V> result = new LinkedHashMap<>();
        for (Map.Entry<K, V> entry : list) {
            result.put(entry.getKey(), entry.getValue());
        }
        return result;
    }
public static < K , V > Map < K , V > sortMapByValue ( Map < K , V > unsortMap , final boolean order ) { List < Map . Entry < K , V > > list = new LinkedList < > ( unsortMap . entrySet ( ) ) ; Collections . sort ( list , new Comparator < Object > ( ) { @ Override public int compare ( Object o1 , Object o2 ) { if ( order ) { return ( ( Comparable < V > ) ( ( Map . Entry < K , V > ) ( o1 ) ) . getValue ( ) ) . compareTo ( ( ( Map . Entry < K , V > ) ( o2 ) ) . getValue ( ) ) ; } else { return ( ( Comparable < V > ) ( ( Map . Entry < K , V > ) ( o2 ) ) . getValue ( ) ) . compareTo ( ( ( Map . Entry < K , V > ) ( o1 ) ) . getValue ( ) ) ; } } } ) ; Map < K , V > result = new LinkedHashMap < > ( ) ; for ( Map . Entry < K , V > entry : list ) { result . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } return result ; }
Method that generate the id of all users for evaluation.
Method that generate the id of all users for evaluation .