/** * This method returns a {@code ImmutableSortedMap}, consisting of the entries whose keys are less * than {@code toKey}. * * <p>The {@link SortedMap#headMap} documentation states that a submap of a submap throws an * {@link IllegalArgumentException} if passed a {@code toKey} greater than an earlier {@code * toKey}. However, this method doesn't throw an exception in that situation, but instead keeps * the original {@code toKey}. */ @Override public ImmutableSortedMap<K, V> headMap(K toKey) { return headMap(toKey, false); }
@Override public Entry<K, V> lowerEntry(K key) { return headMap(key, false).lastEntry(); }
@Override public Entry<K, V> floorEntry(K key) { return headMap(key, true).lastEntry(); }
/** * This method returns a {@code ImmutableSortedMap}, consisting of the entries whose keys are less * than {@code toKey}. * * <p>The {@link SortedMap#headMap} documentation states that a submap of a submap throws an * {@link IllegalArgumentException} if passed a {@code toKey} greater than an earlier {@code * toKey}. However, this method doesn't throw an exception in that situation, but instead keeps * the original {@code toKey}. */ @Override public ImmutableSortedMap<K, V> headMap(K toKey) { return headMap(toKey, false); }
@Override public Entry<K, V> lowerEntry(K key) { return headMap(key, false).lastEntry(); }
@Override public Entry<K, V> floorEntry(K key) { return headMap(key, true).lastEntry(); }
/** * 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> lowerEntry(K key) { return headMap(key, false).lastEntry(); }
@Override public Entry<K, V> floorEntry(K key) { return headMap(key, true).lastEntry(); }
@Override protected SortedMap<String, Integer> makePopulatedMap() { return ImmutableSortedMap.of("a", 1, "b", 2, "c", 3, "d", 4, "e", 5).headMap("c", true); }
@Override protected SortedMap<String, Integer> makePopulatedMap() { return ImmutableSortedMap.of("a", 1, "b", 2, "c", 3, "d", 4, "e", 5).headMap("d"); }
@SuppressWarnings("unchecked") // varargs public void testHeadMapExclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).headMap("three", false); assertThat(map.entrySet()).containsExactly(Maps.immutableEntry("one", 1)); }
/** * 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 testHeadMapInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).headMap("three", true); assertThat(map.entrySet()) .containsExactly(Maps.immutableEntry("one", 1), Maps.immutableEntry("three", 3)) .inOrder(); }
/** * This method returns a {@code ImmutableSortedMap}, consisting of the entries whose keys are less * than {@code toKey}. * * <p>The {@link SortedMap#headMap} documentation states that a submap of a submap throws an * {@link IllegalArgumentException} if passed a {@code toKey} greater than an earlier {@code * toKey}. However, this method doesn't throw an exception in that situation, but instead keeps * the original {@code toKey}. */ @Override public ImmutableSortedMap<K, V> headMap(K toKey) { return headMap(toKey, false); }
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); }
@Override public Entry<K, V> floorEntry(K key) { return headMap(key, true).lastEntry(); }
@Override public Entry<K, V> floorEntry(K key) { return headMap(key, true).lastEntry(); }
@SuppressWarnings("unchecked") // varargs public void testHeadMapExclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).headMap("three", false); assertThat(map.entrySet()).containsExactly(Maps.immutableEntry("one", 1)); }
@SuppressWarnings("unchecked") // varargs public void testHeadMapInclusive() { Map<String, Integer> map = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3).headMap("three", true); assertThat(map.entrySet()).containsExactly( Maps.immutableEntry("one", 1), Maps.immutableEntry("three", 3)).inOrder(); }