@Override public E lower(E element) { int index = headIndex(element, false) - 1; return (index == -1) ? null : elements.get(index); }
@Override public E floor(E element) { int index = headIndex(element, true) - 1; return (index == -1) ? null : elements.get(index); }
@Override ImmutableSortedSet<E> headSetImpl(E toElement, boolean inclusive) { return getSubSet(0, headIndex(toElement, inclusive)); }
@Override public E floor(E element) { int index = headIndex(element, true) - 1; return (index == -1) ? null : elements.get(index); }
@Override ImmutableSortedSet<E> headSetImpl(E toElement, boolean inclusive) { return getSubSet(0, headIndex(toElement, inclusive)); }
@Override public ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType) { return getSubMultiset(0, elementSet.headIndex(upperBound, checkNotNull(boundType) == CLOSED)); }
/** * This method returns a {@code ImmutableSortedMap}, consisting of the entries whose keys are less * than (or equal to, if {@code inclusive}) {@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}. * * @since 12.0 */ @Override public ImmutableSortedMap<K, V> headMap(K toKey, boolean inclusive) { return getSubMap(0, keySet.headIndex(checkNotNull(toKey), inclusive)); }
@Override public E floor(E element) { int index = headIndex(element, true) - 1; return (index == -1) ? null : elements.get(index); }
@Override public E lower(E element) { int index = headIndex(element, false) - 1; return (index == -1) ? null : elements.get(index); }
@Override public ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType) { return getSubMultiset(0, elementSet.headIndex(upperBound, checkNotNull(boundType) == CLOSED)); }
@Override ImmutableSortedSet<E> headSetImpl(E toElement, boolean inclusive) { return getSubSet(0, headIndex(toElement, inclusive)); }
/** * This method returns a {@code ImmutableSortedMap}, consisting of the entries whose keys are less * than (or equal to, if {@code inclusive}) {@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}. * * @since 12.0 */ @Override public ImmutableSortedMap<K, V> headMap(K toKey, boolean inclusive) { return getSubMap(0, keySet.headIndex(checkNotNull(toKey), inclusive)); }
return getSubMultiset(0, elementSet.headIndex(upperBound, checkNotNull(boundType) == CLOSED));
/** * A builder for creating immutable sorted map instances, especially {@code public static final} * maps ("constant maps"). Example: * * <pre>{@code * static final ImmutableSortedMap<Integer, String> INT_TO_WORD = * new ImmutableSortedMap.Builder<Integer, String>(Ordering.natural()) * .put(1, "one") * .put(2, "two") * .put(3, "three") * .build(); * }</pre> * * <p>For <i>small</i> immutable sorted maps, the {@code ImmutableSortedMap.of()} methods are even * more convenient. * * <p>Builder instances can be reused - it is safe to call {@link #build} multiple times to build * multiple maps in series. Each map is a superset of the maps created before it. * * @since 2.0 */ public static class Builder<K, V> extends ImmutableMap.Builder<K, V> { private transient Object[] keys; private transient Object[] values; private final Comparator<? super K> comparator; /** * Creates a new builder. The returned builder is equivalent to the builder generated by {@link * ImmutableSortedMap#orderedBy}. */
@Override public E floor(E element) { int index = headIndex(element, true) - 1; return (index == -1) ? null : elements.get(index); }
@Override public E floor(E element) { int index = headIndex(element, true) - 1; return (index == -1) ? null : elements.get(index); }
@Override public E lower(E element) { int index = headIndex(element, false) - 1; return (index == -1) ? null : elements.get(index); }
@Override ImmutableSortedSet<E> headSetImpl(E toElement, boolean inclusive) { return getSubSet(0, headIndex(toElement, inclusive)); }
@Override public ImmutableSortedMultiset<E> headMultiset(E upperBound, BoundType boundType) { return getSubMultiset(0, elementSet.headIndex(upperBound, checkNotNull(boundType) == CLOSED)); }
@Override public ImmutableSortedMap<K, V> headMap(K toKey, boolean inclusive) { return getSubMap(0, keySet.headIndex(checkNotNull(toKey), inclusive)); }