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(SortedMap<K, ? extends V> m) 

Source Link

Document

Constructs a new tree map containing the same mappings and using the same ordering as the specified sorted map.

Usage

From source file:TComp.java

public static void main(String args[]) {
    TreeMap<String, Double> tm = new TreeMap<String, Double>(new TComp());

    tm.put("J D", new Double(3434.34));
    tm.put("T S", new Double(123.22));
    tm.put("J B", new Double(1378.00));
    tm.put("T H", new Double(99.22));
    tm.put("R S", new Double(-19.08));

    Set<Map.Entry<String, Double>> set = tm.entrySet();

    for (Map.Entry<String, Double> me : set) {
        System.out.print(me.getKey() + ": ");
        System.out.println(me.getValue());
    }//from  ww w.  ja  v  a  2s .c o m
    System.out.println();

    double balance = tm.get("A");
    tm.put("A", balance + 1000);

    System.out.println("A's new balance: " + tm.get("A"));
}

From source file:Main.java

public static void main(String[] args) {
    Map<Month, String> dobCalendar = Employee.persons().stream()
            .collect(Collectors.collectingAndThen(Collectors.groupingBy(p -> p.getDob().getMonth(),
                    Collectors.mapping(Employee::getName, Collectors.joining(" "))), result -> {
                        for (Month m : Month.values()) {
                            result.putIfAbsent(m, "None");
                        }/*from   www. j a v  a  2s . co m*/
                        return Collections.unmodifiableMap(new TreeMap<>(result));
                    }));

    dobCalendar.entrySet().forEach(System.out::println);
}

From source file:gsn.storage.SQLUtils.java

public static void main(String[] args) {
    TreeMap<CharSequence, CharSequence> map = new TreeMap<CharSequence, CharSequence>(
            new CaseInsensitiveComparator());
    String query = "seLect ali.fd, x.x, fdfd.fdfd, *.r, * from x,x, bla, x whEre k";
    map.put("x", "done");
    CharSequence out = newRewrite(query, map);
    System.out.println(out.toString());
    System.out.println(extractProjection(query));
    out = newRewrite(extractProjection(query), map);
    System.out.println(out.toString());
}

From source file:Main.java

public static void log(Map<?, ?> map) {

    TreeMap<Object, Object> tree = new TreeMap<Object, Object>(map);

    for (Map.Entry<Object, Object> entry : tree.entrySet()) {
        System.err.println(String.format("%s = %s", entry.getKey(), entry.getValue()));
    }//from   w  w  w  .ja va  2 s.com

}

From source file:Main.java

public static <K, V> TreeMap<K, V> createTreeMap(Comparator<? super K> comparator) {
    return new TreeMap(comparator);
}

From source file:Main.java

/****
 * TreeMap/*from   w  w  w .j av a  2  s  . c o m*/
 * @return
 */
public static <K, V> Map<K, V> newTreeMap(SortedMap<K, V> map) {
    return new TreeMap<K, V>(map);
}

From source file:Main.java

public static <K, V> TreeMap<K, V> getTreeMap(Comparator<? super K> comparator) {
    return new TreeMap<K, V>(comparator);
}

From source file:Main.java

public static <K, V> TreeMap<K, V> createTreeMap(Comparator<? super K> comparator) {
    if (comparator == null) {
        return null;
    }// ww w.ja  v  a2  s.c o m

    return new TreeMap<K, V>(comparator);
}

From source file:Main.java

public static <K, V> TreeMap<K, V> getTreeMap(Map<? extends K, ? extends V> map) {
    return new TreeMap<K, V>(map);
}

From source file:Main.java

public static <K, V> TreeMap<K, V> getTreeMap(SortedMap<K, ? extends V> map) {
    return new TreeMap<K, V>(map);
}