Class RegularImmutableSortedSet<E>

  • All Implemented Interfaces:
    SortedIterable<E>, java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.NavigableSet<E>, java.util.Set<E>, java.util.SortedSet<E>

    final class RegularImmutableSortedSet<E>
    extends ImmutableSortedSet<E>
    An immutable sorted set with one or more elements. TODO(jlevy): Consider separate class for a single-element sorted set.
    • Constructor Detail

      • RegularImmutableSortedSet

        RegularImmutableSortedSet​(ImmutableList<E> elements,
                                  java.util.Comparator<? super E> comparator)
    • Method Detail

      • internalArray

        @CheckForNull
        java.lang.Object[] internalArray()
        Description copied from class: ImmutableCollection
        If this collection is backed by an array of its elements in insertion order, returns it.
        Overrides:
        internalArray in class ImmutableCollection<E>
      • internalArrayStart

        int internalArrayStart()
        Description copied from class: ImmutableCollection
        If this collection is backed by an array of its elements in insertion order, returns the offset where this collection's elements start.
        Overrides:
        internalArrayStart in class ImmutableCollection<E>
      • internalArrayEnd

        int internalArrayEnd()
        Description copied from class: ImmutableCollection
        If this collection is backed by an array of its elements in insertion order, returns the offset where this collection's elements end.
        Overrides:
        internalArrayEnd in class ImmutableCollection<E>
      • iterator

        public UnmodifiableIterator<E> iterator()
        Description copied from class: ImmutableCollection
        Returns an unmodifiable iterator across the elements in this collection.
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in interface java.util.NavigableSet<E>
        Specified by:
        iterator in interface java.util.Set<E>
        Specified by:
        iterator in interface SortedIterable<E>
        Specified by:
        iterator in class ImmutableSortedSet<E>
      • spliterator

        public java.util.Spliterator<E> spliterator()
        Specified by:
        spliterator in interface java.util.Collection<E>
        Specified by:
        spliterator in interface java.lang.Iterable<E>
        Specified by:
        spliterator in interface java.util.Set<E>
        Specified by:
        spliterator in interface java.util.SortedSet<E>
        Overrides:
        spliterator in class ImmutableSortedSet<E>
      • forEach

        public void forEach​(java.util.function.Consumer<? super E> action)
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Set<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • contains

        public boolean contains​(@CheckForNull
                                java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.Set<E>
        Specified by:
        contains in class ImmutableCollection<E>
      • containsAll

        public boolean containsAll​(java.util.Collection<?> targets)
        Specified by:
        containsAll in interface java.util.Collection<E>
        Specified by:
        containsAll in interface java.util.Set<E>
        Overrides:
        containsAll in class java.util.AbstractCollection<E>
      • unsafeBinarySearch

        private int unsafeBinarySearch​(java.lang.Object key)
                                throws java.lang.ClassCastException
        Throws:
        java.lang.ClassCastException
      • isPartialView

        boolean isPartialView()
        Description copied from class: ImmutableCollection
        Returns true if this immutable collection's implementation contains references to user-created objects that aren't accessible via this collection's methods. This is generally used to determine whether copyOf implementations should make an explicit copy to avoid memory leaks.
        Specified by:
        isPartialView in class ImmutableCollection<E>
      • copyIntoArray

        int copyIntoArray​(java.lang.Object[] dst,
                          int offset)
        Description copied from class: ImmutableCollection
        Copies the contents of this immutable collection into the specified array at the specified offset. Returns offset + size().
        Overrides:
        copyIntoArray in class ImmutableCollection<E>
      • equals

        public boolean equals​(@CheckForNull
                              java.lang.Object object)
        Specified by:
        equals in interface java.util.Collection<E>
        Specified by:
        equals in interface java.util.Set<E>
        Overrides:
        equals in class ImmutableSet<E>
      • first

        public E first()
        Specified by:
        first in interface java.util.SortedSet<E>
        Overrides:
        first in class ImmutableSortedSet<E>
      • last

        public E last()
        Specified by:
        last in interface java.util.SortedSet<E>
        Overrides:
        last in class ImmutableSortedSet<E>
      • lower

        @CheckForNull
        public E lower​(E element)
        Specified by:
        lower in interface java.util.NavigableSet<E>
        Overrides:
        lower in class ImmutableSortedSet<E>
      • floor

        @CheckForNull
        public E floor​(E element)
        Specified by:
        floor in interface java.util.NavigableSet<E>
        Overrides:
        floor in class ImmutableSortedSet<E>
      • ceiling

        @CheckForNull
        public E ceiling​(E element)
        Specified by:
        ceiling in interface java.util.NavigableSet<E>
        Overrides:
        ceiling in class ImmutableSortedSet<E>
      • higher

        @CheckForNull
        public E higher​(E element)
        Specified by:
        higher in interface java.util.NavigableSet<E>
        Overrides:
        higher in class ImmutableSortedSet<E>
      • headIndex

        int headIndex​(E toElement,
                      boolean inclusive)
      • tailIndex

        int tailIndex​(E fromElement,
                      boolean inclusive)
      • unsafeComparator

        java.util.Comparator<java.lang.Object> unsafeComparator()
      • indexOf

        int indexOf​(@CheckForNull
                    java.lang.Object target)
        Description copied from class: ImmutableSortedSet
        Returns the position of an element within the set, or -1 if not present.
        Specified by:
        indexOf in class ImmutableSortedSet<E>