class CollectionHelper {

    public static <K, V extends Comparable<V>> Map<K, V> sortByValue(Map<K, V> map, Order order) {
        Validate.notNull(map, "map must not be null");
        Validate.notNull(order, "order must not be null");
        List<Entry<K, V>> list = new LinkedList<>(map.entrySet());
        Collections.sort(list, new EntryValueComparator<>(order));

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

    private  CollectionHelper();

}