List of usage examples for java.util NavigableMap floorEntry
Map.Entry<K, V> floorEntry(K key);
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);//from w w w . j av a 2 s . co m System.out.println(nav.floorEntry("G")); }
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 testFloorEntry() { K[] keys = getSortedKeys();/* w w w .j av a 2 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.floorEntry(getLessThanMinimumKey())); assertEquals(keys[0], map.floorEntry(keys[0]).getKey()); assertEquals(values[0], map.floorEntry(keys[0]).getValue()); assertEquals(keys[0], map.floorEntry(keys[1]).getKey()); assertEquals(values[0], map.floorEntry(keys[1]).getValue()); assertEquals(keys[0], map.floorEntry(getGreaterThanMaximumKey()).getKey()); // is it consistent with other methods assertEquals(map.keySet().toArray()[0], map.floorEntry(keys[1]).getKey()); // test with two entry map map.put(keys[1], values[1]); assertNull(map.floorEntry(getLessThanMinimumKey())); assertEquals(keys[0], map.floorEntry(keys[0]).getKey()); Entry<K, V> entry = map.floorEntry(keys[1]); verifyEntry(entry); assertEquals(keys[1], entry.getKey()); assertEquals(values[1], entry.getValue()); assertEquals(keys[1], map.floorEntry(getGreaterThanMaximumKey()).getKey()); try { map.floorEntry(null); assertTrue("expected exception", useNullKey()); } catch (NullPointerException e) { assertFalse("unexpected NPE", useNullKey()); } map.clear(); assertNull(map.floorEntry(keys[1])); assertNull(map.floorEntry(null)); }
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); }/*from w w w . java 2 s . c om*/ return defaultValue; } LOG.warn("Could not find a higer compatible version for {} {}, using {} instead", what, desiredVersion, ret.getKey()); } return ret.getValue(); }