Example usage for java.util TreeMap TreeMap

List of usage examples for java.util TreeMap TreeMap

Introduction

In this page you can find the example usage for java.util TreeMap TreeMap.

Prototype

public TreeMap() 

Source Link

Document

Constructs a new, empty tree map, using the natural ordering of its keys.

Usage

From source file:Main.java

public static <K, V> SortedMap<K, V> newSortedMap() {
    return new TreeMap<K, V>();
}

From source file:Main.java

public static <K, V> Map<V, Set<K>> invertMapOfCollection(Map<K, ? extends Collection<V>> mapOfCollection) {
    Map<V, Set<K>> result = new TreeMap<V, Set<K>>();

    for (Entry<K, ? extends Collection<V>> inputEntry : mapOfCollection.entrySet()) {
        K inputKey = inputEntry.getKey();
        Collection<V> inputCollection = inputEntry.getValue();

        for (V inputValue : inputCollection) {
            Set<K> resultSet = result.get(inputValue);
            if (resultSet == null) {
                resultSet = new TreeSet<K>();
                result.put(inputValue, resultSet);
            }/*from w  w w .  ja  v  a 2  s. c o  m*/
            resultSet.add(inputKey);
        }
    }

    return result;
}

From source file:Main.java

/**
 * Converts the given pair of arrays into a sorted map that maps each
 * keys[i] to the corresponding values[i].
 * @return the map (empty map if keys == null or values == null)
 *///from   ww w.j  av a  2  s  . c  o  m
public static <K extends Comparable<? super K>, V> Map<K, V> asMapSorted(K[] keys, V[] values) {
    Map<K, V> map = new TreeMap<K, V>();
    if (keys == null || values == null) {
        return map;
    }

    for (int i = 0, len = Math.min(keys.length, values.length); i < len; i++) {
        map.put(keys[i], values[i]);
    }
    return map;
}

From source file:Main.java

/**
 * Flatten a map of string arrays to a map of strings using the first item in each array.
 * /*from w ww . j av  a 2 s. co m*/
 * @param parameterMap
 *            The map of string arrays.
 * @return A map of strings.
 */
public static Map<String, String> flatten(Map<String, String[]> parameterMap) {
    Map<String, String> result = new TreeMap<String, String>();
    for (String key : parameterMap.keySet()) {
        result.put(key, parameterMap.get(key)[0]);
    }
    return result;
}

From source file:Main.java

/**
 * Get the attribute values of a given name/value pair for
 * the first XML {@code org.w3c.dom.Element} of given name.
 *
 * @param elem the parent XML Element//from   ww w .  j a v  a  2 s. com
 * @param name the name of the child text Element
 * @return attribute name and value Map of named child Element
 */
public static Map<String, String> getAllAttributes(Element elem, String name) {
    Map<String, String> attributes = new TreeMap<String, String>();
    NodeList nodeList = elem.getElementsByTagName(name);
    int length = nodeList.getLength();
    for (int n = 0; n < length; ++n) {
        attributes.put(((Element) nodeList.item(n)).getAttribute("name"),
                ((Element) nodeList.item(n)).getAttribute("value"));
    }
    return attributes;
}

From source file:Main.java

public static <T extends Comparable, U> SortedMap<T, U> removeObjectSortedMap(SortedMap<T, U> map, T key) {
    if (map == null) {
        return new TreeMap<T, U>();
    }//from  ww  w . j  a  va 2 s .  co  m
    map.remove(key);
    return map;
}

From source file:org.apache.asterix.experiment.client.LSMExperimentSetRunner.java

public static void main(String[] args) throws Exception {
    java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(Level.FINEST);
    //        LogManager.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
    LSMExperimentSetRunnerConfig config = new LSMExperimentSetRunnerConfig(
            String.valueOf(System.currentTimeMillis()), 3);
    CmdLineParser clp = new CmdLineParser(config);
    try {//  ww w.  j  a  v  a 2s. c o m
        clp.parseArgument(args);
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        clp.printUsage(System.err);
        System.exit(1);
    }

    final String pkg = "org.apache.asterix.experiment.builder.suite";
    Reflections reflections = //new Reflections("org.apache.asterix.experiment.builder.suite");
            new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(pkg))
                    .filterInputsBy(new FilterBuilder().includePackage(pkg))
                    .setScanners(new TypeElementsScanner().publicOnly(), new MethodParameterScanner()));
    Map<String, AbstractLSMBaseExperimentBuilder> nameMap = new TreeMap<>();
    for (Constructor c : reflections.getConstructorsMatchParams(LSMExperimentSetRunnerConfig.class)) {
        AbstractLSMBaseExperimentBuilder b = (AbstractLSMBaseExperimentBuilder) c.newInstance(config);
        nameMap.put(b.getName(), b);
    }

    Pattern p = config.getRegex() == null ? null : Pattern.compile(config.getRegex());

    SequentialActionList exps = new SequentialActionList();
    for (Map.Entry<String, AbstractLSMBaseExperimentBuilder> e : nameMap.entrySet()) {
        if (p == null || p.matcher(e.getKey()).matches()) {
            exps.add(e.getValue().build());
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info("Added " + e.getKey() + " to run list...");
            }
        }
    }
    exps.perform();
}

From source file:it.imtech.bookimporter.BookUtility.java

/**
 * Restituisce le lingue disponibili in ordine alfabetico
 * @param config//  w  w w  .  j a  v a 2s .  c  o m
 * @param bundle
 * @return TreeMap<String, String>
 */
protected static TreeMap<String, String> getOrderedLanguages(XMLConfiguration config, ResourceBundle bundle) {
    TreeMap<String, String> ordered_res = new TreeMap<String, String>();

    String lang_name;
    String key;

    java.util.List<HierarchicalConfiguration> resources = config.configurationsAt("resources.resource");
    for (HierarchicalConfiguration resource : resources) {
        lang_name = resource.getString("[@descr]");
        key = it.imtech.utility.Utility.getBundleString(lang_name, bundle);

        ordered_res.put(key, resource.getString(""));
    }

    return ordered_res;
}

From source file:Main.java

public static <T, U> SortedMap<T, U> copySortedMap(SortedMap<T, U> m) {
    if (m == null || m.size() == 0) {
        return new TreeMap<T, U>();
    } else {//from w w  w  .jav  a2 s. c om
        return new TreeMap<T, U>(m);
    }
}

From source file:Main.java

public static <T extends Comparable, U> SortedMap<T, U> putObjectSortedMap(SortedMap<T, U> map, T key,
        U value) {//  w w w. ja  va 2  s .c  om
    if (map == null) {
        map = new TreeMap<T, U>();
    }
    map.put(key, value);
    return map;
}