Example usage for java.util NavigableMap ceilingEntry

List of usage examples for java.util NavigableMap ceilingEntry

Introduction

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

Prototype

Map.Entry<K, V> ceilingEntry(K key);

Source Link

Document

Returns a key-value mapping associated with the least key greater than or equal to the given key, or null if there is no such key.

Usage

From source file:Main.java

public static void main(String args[]) {

    NavigableMap<String, String> nav = new TreeMap<String, String>();
    nav.put("A", "a");
    nav.put("B", "b");
    nav.put("C", "c");
    nav.put("D", "d");
    nav.put("E", "e");
    nav.put("F", "f");
    System.out.println(nav);/*  w w w.  j  av a 2 s . co  m*/
    System.out.println(nav.ceilingEntry("B"));
}

From source file:Main.java

public static void main(String[] args) {

    NavigableMap<String, String> nMap = new TreeMap<>();
    nMap.put("CSS", "style");
    nMap.put("HTML", "mark up");
    nMap.put("Oracle", "database");
    nMap.put("XML", "data");
    System.out.println("Navigable Map:" + nMap);

    Entry<String, String> lowerXML = nMap.lowerEntry("XML");
    Entry<String, String> floorXML = nMap.floorEntry("XML");
    Entry<String, String> higherXML = nMap.higherEntry("XML");
    Entry<String, String> ceilingXML = nMap.ceilingEntry("XML");

    System.out.println("Lower:" + lowerXML);
    System.out.println("Floor:" + floorXML);
    System.out.println("Higher:" + higherXML);
    System.out.println("Ceiling:" + ceilingXML);

    // Get the reverse order view of the map
    NavigableMap<String, String> reverseMap = nMap.descendingMap();
    System.out.println("Navigable Map(Reverse  Order):" + reverseMap);

}

From source file:com.google.gwt.emultest.java.util.TreeMapTest.java

public void testCeilingEntry() {
    K[] keys = getSortedKeys();/* w w  w .  jav a2s  .c  o m*/
    V[] values = getSortedValues();
    NavigableMap<K, V> map = createNavigableMap();

    // test with a single entry map
    map.put(keys[0], values[0]);
    assertEquals(keys[0], map.ceilingEntry(keys[0]).getKey());
    assertEquals(values[0], map.ceilingEntry(keys[0]).getValue());
    assertEquals(keys[0], map.ceilingEntry(getLessThanMinimumKey()).getKey());
    // is it consistent with other methods
    assertEquals(map.keySet().toArray()[0], map.ceilingEntry(getLessThanMinimumKey()).getKey());

    // test with two entry map
    map.put(keys[1], values[1]);
    assertEquals(keys[0], map.ceilingEntry(getLessThanMinimumKey()).getKey());
    Entry<K, V> entry = map.ceilingEntry(keys[0]);
    verifyEntry(entry);
    assertEquals(keys[0], entry.getKey());
    assertEquals(keys[1], map.ceilingEntry(keys[1]).getKey());
    assertEquals(values[1], map.ceilingEntry(keys[1]).getValue());
    assertNull(map.ceilingEntry(getGreaterThanMaximumKey()));
}

From source file:org.apache.storm.utils.Utils.java

public static <T> T getCompatibleVersion(NavigableMap<SimpleVersion, T> versionedMap,
        SimpleVersion desiredVersion, String what, T defaultValue) {
    Entry<SimpleVersion, T> ret = versionedMap.ceilingEntry(desiredVersion);
    if (ret == null || ret.getKey().getMajor() != desiredVersion.getMajor()) {
        //Could not find a "fully" compatible version.  Look to see if there is a possibly compatible version right below it
        ret = versionedMap.floorEntry(desiredVersion);
        if (ret == null || ret.getKey().getMajor() != desiredVersion.getMajor()) {
            if (defaultValue != null) {
                LOG.warn("Could not find any compatible {} falling back to using {}", what, defaultValue);
            }/* ww  w  .j a v  a 2 s  .c  o  m*/
            return defaultValue;
        }
        LOG.warn("Could not find a higer compatible version for {} {}, using {} instead", what, desiredVersion,
                ret.getKey());
    }
    return ret.getValue();
}