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