Java Map Reverse sort(Map> dataNodes, boolean reverse)

Here you can find the source of sort(Map> dataNodes, boolean reverse)

Description

sort

License

Apache License

Declaration

private static Map<Long, List<String>> sort(Map<String, Map<Long, Long>> dataNodes, boolean reverse) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import static java.util.Collections.reverseOrder;
import java.util.ArrayList;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    private static Map<Long, List<String>> sort(Map<String, Map<Long, Long>> dataNodes, boolean reverse) {
        Map<Long, List<String>> result = getSortedMap(reverse);
        for (String hostName : dataNodes.keySet()) {
            Map<Long, Long> usage = dataNodes.get(hostName);
            long space = usage.values().iterator().next();
            List<String> hosts = result.get(space);
            if (hosts == null) {
                hosts = new ArrayList<>();
            }//  w w w. ja v  a2 s.co  m
            hosts.add(hostName);
            result.put(space, hosts);
        }
        return result;
    }

    private static Map<Long, List<String>> getSortedMap(boolean reverse) {
        if (reverse) {
            return new TreeMap<>(reverseOrder());
        } else {
            return new TreeMap<>();
        }
    }
}

Related

  1. reverseMap(Map map)
  2. reverseMap(Map keyIdMap, Map keyValueMap)
  3. reverseMapLookup(Map map, V value)
  4. reverseMapping(Map value2keys, Map map)
  5. reverseMapping(Map map)
  6. sort(Map source, boolean reverse)
  7. sortByUsedSpace(Map> dataNodes, boolean reverse)
  8. sortByValue(Map map, boolean reverse)
  9. sortByValue(Map map, boolean doReverse)