List of usage examples for java.util NavigableMap lowerEntry
Map.Entry<K, V> lowerEntry(K key);
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:Main.java
public static void main(String[] args) { NavigableMap<String, Integer> navigableMap = new TreeMap<String, Integer>(); String[] letters = { "a", "b", "c" }; int[] ints = { 3, 2, 1 }; for (int i = 0; i < letters.length; i++) { navigableMap.put(letters[i], ints[i]); }/* w ww.j av a 2 s .co m*/ System.out.println("Map = " + navigableMap); System.out.println("Entry < a is " + navigableMap.lowerEntry("a")); }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testLowerEntry() { K[] keys = getSortedKeys();//from w w w. j av a2 s. 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.lowerEntry(getLessThanMinimumKey())); assertNull(map.lowerEntry(keys[0])); assertEquals(keys[0], map.lowerEntry(keys[1]).getKey()); assertEquals(values[0], map.lowerEntry(keys[1]).getValue()); assertEquals(keys[0], map.lowerEntry(getGreaterThanMaximumKey()).getKey()); assertEquals(values[0], map.lowerEntry(getGreaterThanMaximumKey()).getValue()); // is it consistent with other methods assertEquals(map.keySet().toArray()[0], map.lowerEntry(keys[1]).getKey()); // test with two entry map map.put(keys[1], values[1]); assertNull(map.lowerEntry(getLessThanMinimumKey())); assertNull(map.lowerEntry(keys[0])); assertEquals(values[0], map.lowerEntry(keys[1]).getValue()); Entry<K, V> entry = map.lowerEntry(getGreaterThanMaximumKey()); verifyEntry(entry); assertEquals(keys[1], entry.getKey()); try { map.lowerEntry(null); assertTrue("expected exception", useNullKey()); } catch (NullPointerException e) { assertFalse("unexpected NPE", useNullKey()); } map.clear(); assertNull(map.lowerEntry(keys[1])); assertNull(map.lowerEntry(null)); }