@Override public boolean isEmpty() { return !Iterables.any(unfiltered.entrySet(), entryPredicate); }
@Override Iterator<Entry<K, V>> descendingEntryIterator() { return Iterators.filter(unfiltered.descendingMap().entrySet().iterator(), entryPredicate); }
NavigableMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertEquals(ImmutableMap.of("one", 3, "two", 3, "three", 5), map); assertEquals(Integer.valueOf(5), map.get("three")); assertNull(map.get("five")); assertThat(map.entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("three", 5), mapEntry("two", 3)) .inOrder(); assertThat(map.tailMap("onea").entrySet()) .containsExactly(mapEntry("three", 5), mapEntry("two", 3)) .inOrder(); assertThat(map.subMap("one", "two").entrySet()) .containsExactly(mapEntry("one", 3), mapEntry("three", 5)) .inOrder(); assertEquals(ImmutableSortedMap.of("two", 3, "three", 5), map.tailMap("three", true)); assertEquals(ImmutableSortedMap.of("one", 3, "three", 5), map.headMap("two", false)); assertEquals(ImmutableSortedMap.of("three", 5), map.subMap("one", false, "tr", true)); assertEquals("three", map.higherKey("one")); assertEquals("three", map.higherKey("r")); assertEquals("three", map.ceilingKey("r")); assertEquals("one", map.ceilingKey("one")); assertEquals(mapEntry("three", 5), map.higherEntry("one")); assertEquals(mapEntry("one", 3), map.ceilingEntry("one")); assertEquals("one", map.lowerKey("three")); assertEquals("one", map.lowerKey("r")); assertEquals("one", map.floorKey("r")); assertEquals("three", map.floorKey("three"));
Collections.addAll(strings, "one", "two", "three"); NavigableMap<String, Integer> map = Maps.asMap(strings, LENGTH_FUNCTION); assertNull(map.comparator()); assertEquals(ImmutableSortedMap.of("one", 3, "two", 3, "three", 5), map); assertNull(map.get("four")); strings.add("four"); assertEquals(ImmutableSortedMap.of("one", 3, "two", 3, "three", 5, "four", 4), map); assertEquals(Integer.valueOf(4), map.get("four")); SortedMap<String, Integer> headMap = map.headMap("two"); assertEquals(ImmutableSortedMap.of("four", 4, "one", 3, "three", 5), headMap); strings.add("five"); strings.remove("one"); assertEquals(ImmutableSortedMap.of("five", 4, "four", 4, "three", 5), headMap); assertThat(map.entrySet()) .containsExactly( mapEntry("five", 4), mapEntry("four", 4), mapEntry("three", 5), mapEntry("two", 3)) .inOrder(); NavigableMap<String, Integer> tailMap = map.tailMap("s", true); NavigableMap<String, Integer> subMap = map.subMap("a", true, "t", false); assertThat(tailMap.entrySet()) .containsExactly(mapEntry("six", 3), mapEntry("three", 5)) .inOrder(); assertThat(subMap.entrySet()) .containsExactly(mapEntry("five", 4), mapEntry("four", 4), mapEntry("six", 3)) .inOrder();
public void testStandardLastEntry() { NavigableMap<String, Integer> forwarding = new StandardLastEntryForwardingNavigableMap<>(new SafeTreeMap<String, Integer>()); assertNull(forwarding.lastEntry()); forwarding.put("b", 2); assertEquals(immutableEntry("b", 2), forwarding.lastEntry()); forwarding.put("c", 3); assertEquals(immutableEntry("c", 3), forwarding.lastEntry()); forwarding.put("a", 1); assertEquals(immutableEntry("c", 3), forwarding.lastEntry()); forwarding.remove("c"); assertEquals(immutableEntry("b", 2), forwarding.lastEntry()); }
@GwtIncompatible // NavigableMap void ensureNotDirectlyModifiable(NavigableMap<Integer, String> unmod) { try { unmod.put(4, "four"); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } try { unmod.putAll(Collections.singletonMap(4, "four")); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } try { unmod.remove(4); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } try { unmod.pollFirstEntry(); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } try { unmod.pollLastEntry(); fail("UnsupportedOperationException expected"); } catch (UnsupportedOperationException expected) { } }
@GwtIncompatible // NavigableMap public void testAsMapNavigableSubViewKeySetsDoNotSupportAdd() { NavigableMap<String, Integer> map = Maps.asMap(Sets.<String>newTreeSet(), LENGTH_FUNCTION); try { map.descendingKeySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } try { map.subMap("a", true, "z", false).keySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } try { map.tailMap("a", true).keySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } try { map.headMap("r", true).keySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } try { map.headMap("r", false).tailMap("m", true).keySet().add("a"); fail(); } catch (UnsupportedOperationException expected) { } }
int getCurrentSize() { int currentSize = 0; for (Class<?> type : sortedSizes.keySet()) { for (Integer size : sortedSizes.get(type).keySet()) { ArrayAdapterInterface<?> adapter = getAdapterFromType(type); currentSize += size * sortedSizes.get(type).get(size) * adapter.getElementSizeInBytes(); } } return currentSize; }
@Override public Set<Range<C>> asDescendingSetOfRanges() { Set<Range<C>> result = asDescendingSetOfRanges; return (result == null) ? asDescendingSetOfRanges = new AsRanges(rangesByLowerBound.descendingMap().values()) : result; }
public Range getSpan() { if (lowIndexedRanges.isEmpty()) { throw new IllegalStateException("Can not get span if no ranges exist"); } return lowIndexedRanges.firstEntry().getValue().span(lowIndexedRanges.lastEntry().getValue()); }
@Override public Collection<V> values() { return delegate.values(); }