/** * This method returns a {@code ImmutableSortedMap}, consisting of the entries whose keys are * greater than or equals to {@code fromKey}. * * <p>The {@link SortedMap#tailMap} documentation states that a submap of a submap throws an * {@link IllegalArgumentException} if passed a {@code fromKey} less than an earlier {@code * fromKey}. However, this method doesn't throw an exception in that situation, but instead keeps * the original {@code fromKey}. */ @Override public ImmutableSortedMap<K, V> tailMap(K fromKey) { return tailMap(fromKey, true); }
@Override public Entry<K, V> ceilingEntry(K key) { return tailMap(key, true).firstEntry(); }
/** * This method returns a {@code ImmutableSortedMap}, consisting of the entries whose keys are * greater than or equals to {@code fromKey}. * * <p>The {@link SortedMap#tailMap} documentation states that a submap of a submap throws an * {@link IllegalArgumentException} if passed a {@code fromKey} less than an earlier {@code * fromKey}. However, this method doesn't throw an exception in that situation, but instead keeps * the original {@code fromKey}. */ @Override public ImmutableSortedMap<K, V> tailMap(K fromKey) { return tailMap(fromKey, true); }
@Override public Entry<K, V> higherEntry(K key) { return tailMap(key, false).firstEntry(); }
@Override public Entry<K, V> ceilingEntry(K key) { return tailMap(key, true).firstEntry(); }
/** * This method returns a {@code ImmutableSortedMap}, consisting of the entries whose keys ranges * from {@code fromKey} to {@code toKey}, inclusive or exclusive as indicated by the boolean * flags. * * <p>The {@link SortedMap#subMap} documentation states that a submap of a submap throws an {@link * IllegalArgumentException} if passed a {@code fromKey} less than an earlier {@code fromKey}. * However, this method doesn't throw an exception in that situation, but instead keeps the * original {@code fromKey}. Similarly, this method keeps the original {@code toKey}, instead of * throwing an exception, if passed a {@code toKey} greater than an earlier {@code toKey}. * * @since 12.0 */ @Override public ImmutableSortedMap<K, V> subMap( K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { checkNotNull(fromKey); checkNotNull(toKey); checkArgument( comparator().compare(fromKey, toKey) <= 0, "expected fromKey <= toKey but %s > %s", fromKey, toKey); return headMap(toKey, toInclusive).tailMap(fromKey, fromInclusive); }
@Override public Entry<K, V> ceilingEntry(K key) { return tailMap(key, true).firstEntry(); }
@Override public Entry<K, V> higherEntry(K key) { return tailMap(key, false).firstEntry(); }
@Override protected SortedMap<String, Integer> makePopulatedMap() { return ImmutableSortedMap.of("a", 1, "b", 2, "c", 3, "d", 4, "e", 5).tailMap("b"); }
@Override protected SortedMap<String, Integer> makePopulatedMap() { return ImmutableSortedMap.of("a", 1, "b", 2, "c", 3, "d", 4, "e", 5).tailMap("a", false); }
@SuppressWarnings("unchecked") // varargs public void testTailMapExclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).tailMap("three", false); assertThat(map.entrySet()).containsExactly(Maps.immutableEntry("two", 2)); }
/** * This method returns a {@code ImmutableSortedMap}, consisting of the entries whose keys ranges * from {@code fromKey} to {@code toKey}, inclusive or exclusive as indicated by the boolean * flags. * * <p>The {@link SortedMap#subMap} documentation states that a submap of a submap throws an {@link * IllegalArgumentException} if passed a {@code fromKey} less than an earlier {@code fromKey}. * However, this method doesn't throw an exception in that situation, but instead keeps the * original {@code fromKey}. Similarly, this method keeps the original {@code toKey}, instead of * throwing an exception, if passed a {@code toKey} greater than an earlier {@code toKey}. * * @since 12.0 */ @Override public ImmutableSortedMap<K, V> subMap( K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { checkNotNull(fromKey); checkNotNull(toKey); checkArgument( comparator().compare(fromKey, toKey) <= 0, "expected fromKey <= toKey but %s > %s", fromKey, toKey); return headMap(toKey, toInclusive).tailMap(fromKey, fromInclusive); }
@SuppressWarnings("unchecked") // varargs public void testTailMapInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).tailMap("three", true); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("three", 3), Maps.immutableEntry("two", 2)) .inOrder(); }
@Override public Entry<K, V> higherEntry(K key) { return tailMap(key, false).firstEntry(); }
@Override public Entry<K, V> higherEntry(K key) { return tailMap(key, false).firstEntry(); }
@Override public Entry<K, V> ceilingEntry(K key) { return tailMap(key, true).firstEntry(); }
@Override public Entry<K, V> higherEntry(K key) { return tailMap(key, false).firstEntry(); }
@Override public Entry<K, V> higherEntry(K key) { return tailMap(key, false).firstEntry(); }
ImmutableSortedMap<K, V> subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { checkNotNull(fromKey); checkNotNull(toKey); checkArgument(comparator.compare(fromKey, toKey) <= 0); return tailMap(fromKey, fromInclusive).headMap(toKey, toInclusive); }
@SuppressWarnings("unchecked") // varargs public void testTailMapInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).tailMap("three", true); assertThat(map.entrySet()).containsExactly(Maps.immutableEntry("three", 3), Maps.immutableEntry("two", 2)).inOrder(); }