List of usage examples for java.util NavigableMap lowerKey
K lowerKey(K key);
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 lower before Sunday: %s%n", nav.lowerKey("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 ww . j a v a 2s .c o m*/ System.out.println(nav.lowerKey("G")); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testLowerKey() { K[] keys = getSortedKeys();//ww w .j a v a 2s . c o m V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); // test with a single entry map map.put(keys[0], values[0]); assertNull(map.lowerKey(getLessThanMinimumKey())); assertNull(map.lowerKey(keys[0])); assertEquals(keys[0], map.lowerKey(keys[1])); assertEquals(keys[0], map.lowerKey(getGreaterThanMaximumKey())); // is it consistent with other methods assertEquals(map.keySet().toArray()[0], map.lowerKey(keys[1])); // test with two entry map map.put(keys[1], values[1]); assertNull(map.lowerKey(getLessThanMinimumKey())); assertNull(map.lowerKey(keys[0])); assertEquals(keys[0], map.lowerKey(keys[1])); assertEquals(keys[1], map.lowerKey(getGreaterThanMaximumKey())); try { map.lowerKey(null); assertTrue("expected exception", useNullKey()); } catch (NullPointerException e) { assertFalse("unexpected NPE", useNullKey()); } map.clear(); assertNull(map.lowerKey(keys[1])); assertNull(map.lowerKey(null)); }