List of usage examples for java.util NavigableMap higherEntry
Map.Entry<K, V> higherEntry(K key);
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]); }//from ww w .j a va 2 s . c om System.out.println("Map = " + navigableMap); System.out.println("Entry > c is " + navigableMap.higherEntry("c")); }
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.att.aro.core.packetanalysis.impl.VideoUsageAnalysisImpl.java
/** * <pre>/* w w w . j ava 2 s . c o m*/ * Final pass to fix update values if not set already. * Examine startTime for each segment compared with next segment to determine duration when not set. * * Problems occur when there is a missing segment and on the last segment. * Missing segments cause an approximation by dividing the duration by the number of missing segments+1 * The last segment simply repeats the previous duration, this should not skew results by much. */ private void updateDuration() { log.info("updateDuration()"); if (videoUsage != null) { for (AROManifest manifest : videoUsage.getManifests()) { if (manifest != null) { NavigableMap<String, VideoEvent> eventMap = manifest.getSegmentEventList(); if (manifest instanceof ManifestDash && !eventMap.isEmpty()) { int seg = 0; Entry<String, VideoEvent> lastEntry = eventMap.lastEntry(); double lastSeg = lastEntry != null ? lastEntry.getValue().getSegment() : 0; String key = manifest.generateVideoEventKey(0, 0, "z"); Entry<String, VideoEvent> val; Entry<String, VideoEvent> valn; double duration = 0; VideoEvent event; String segNextKey = null; for (seg = 1; seg <= lastSeg; seg++) { segNextKey = manifest.generateVideoEventKey(seg, 0, "z"); val = eventMap.higherEntry(key); valn = eventMap.higherEntry(segNextKey); if (val == null || valn == null) { break; } event = val.getValue(); VideoEvent eventNext = valn.getValue(); duration = eventNext.getSegmentStartTime() - event.getSegmentStartTime(); double deltaSegment = eventNext.getSegment() - event.getSegment(); if (deltaSegment > 1) { duration /= deltaSegment; } updateSegmentDuration(eventMap, key, segNextKey, duration); key = segNextKey; } // handle any segments at the end val = eventMap.higherEntry(key); if (val != null && segNextKey != null) { updateSegmentDuration(eventMap, key, segNextKey, duration); } } } } } }
From source file:com.google.gwt.emultest.java.util.TreeMapTest.java
public void testHigherEntry() { K[] keys = getSortedKeys();//from w w w . j ava 2s .com V[] values = getSortedValues(); NavigableMap<K, V> map = createNavigableMap(); // test with a single entry map map.put(keys[0], values[0]); assertNull(map.higherEntry(keys[0])); assertEquals(keys[0], map.higherEntry(getLessThanMinimumKey()).getKey()); assertEquals(values[0], map.higherEntry(getLessThanMinimumKey()).getValue()); // is it consistent with other methods assertEquals(map.keySet().toArray()[0], map.higherEntry(getLessThanMinimumKey()).getKey()); // test with two entry map map.put(keys[1], values[1]); assertEquals(keys[0], map.higherEntry(getLessThanMinimumKey()).getKey()); Entry<K, V> entry = map.higherEntry(keys[0]); verifyEntry(entry); assertEquals(keys[1], entry.getKey()); assertEquals(values[1], entry.getValue()); assertNull(map.higherEntry(keys[1])); assertNull(map.higherEntry(getGreaterThanMaximumKey())); try { map.higherEntry(null); assertTrue("expected exception", useNullKey()); } catch (NullPointerException e) { assertFalse("unexpected NPE", useNullKey()); } map.clear(); assertNull(map.higherEntry(keys[1])); assertNull(map.higherEntry(null)); }