Example usage for java.util NavigableMap ceilingKey

List of usage examples for java.util NavigableMap ceilingKey

Introduction

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

Prototype

K ceilingKey(K key);

Source Link

Document

Returns the least key greater than or equal to the given key, or null if there is no such key.

Usage

From source file:NavigableMapSample.java

public static void main(String args[]) {
    Calendar now = Calendar.getInstance();
    Locale locale = Locale.getDefault();

    Map<String, Integer> names = now.getDisplayNames(Calendar.DAY_OF_WEEK, Calendar.LONG, locale);
    NavigableMap<String, Integer> nav = new TreeMap<String, Integer>(names);
    System.out.printf("Whole list:%n%s%n", nav);
    System.out.printf("Key ceiling after Sunday: %s%n", nav.ceilingKey("Sunday"));
}

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  a  v  a  2s . c  o  m*/
    System.out.println(nav.ceilingKey("B"));
}

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

public void testCeilingKey() {
    K[] keys = getSortedKeys();//  w  w w  .j a  va2 s  . co  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.ceilingKey(keys[0]));
    assertEquals(keys[0], map.ceilingKey(getLessThanMinimumKey()));
    // is it consistent with other methods
    assertEquals(map.keySet().toArray()[0], map.ceilingKey(getLessThanMinimumKey()));

    // test with two entry map
    map.put(keys[1], values[1]);
    assertEquals(keys[0], map.ceilingKey(getLessThanMinimumKey()));
    assertEquals(keys[0], map.ceilingKey(keys[0]));
    assertEquals(keys[1], map.ceilingKey(keys[1]));
    assertNull(map.ceilingKey(getGreaterThanMaximumKey()));

    try {
        map.ceilingKey(null);
        assertTrue("expected exception", useNullKey());
    } catch (NullPointerException e) {
        assertFalse("unexpected NPE", useNullKey());
    }
    map.clear();
    assertNull(map.ceilingKey(keys[1]));
    assertNull(map.ceilingKey(null));
}