Class ImmutableAbstractSet<E>

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ImmutableAbstractSet​(Set<E> set, Immutable copyOrWrap)
      Construct an abstract immutable set.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean contains​(Object o)
      Returns true if this immutable collection contains the specified element.
      boolean containsAll​(Collection<?> c)
      Returns true if this immutable collection contains all of the elements in the specified collection.
      boolean containsAll​(ImmutableCollection<?> c)
      Returns true if this immutable collection contains all of the elements in the specified immutable collection.
      boolean equals​(Object obj)
      Force to redefine equals for the implementations of immutable collection classes.
      void forEach​(Consumer<? super E> action)
      protected Set<E> getUnderlyingCollection()
      Returns the underlying collection of this immutable collection.
      int hashCode()
      Force to redefine hashCode for the implementations of immutable collection classes.
      boolean isEmpty()
      Returns true if this immutable collection contains no elements.
      boolean isWrap()
      Return whether the internal storage is a wrapped pointer to the original collection.
      ImmutableIterator<E> iterator()
      Returns an immutable iterator over the elements in this immutable collection.
      Stream<E> parallelStream()
      Returns a possibly parallel Stream with this collection as its source.
      int size()
      Returns the number of elements in this immutable collection.
      Spliterator<E> spliterator()
      Creates a Spliterator over the elements in this collection.
      Stream<E> stream()
      Returns a sequential Stream with this collection as its source.
      Object[] toArray()
      Returns an array containing all of the elements in this immutable collection.
      <T> T[] toArray​(T[] a)
      Returns an array containing all of the elements in this immutable collection; the runtime type of the returned array is that of the specified array.
      Collection<E> toCollection()
      Returns a modifiable copy of this immutable collection.
    • Constructor Detail

      • ImmutableAbstractSet

        protected ImmutableAbstractSet​(Set<E> set,
                                       Immutable copyOrWrap)
        Construct an abstract immutable set. Make sure that the argument is a safe copy of the set of the right type! Copying does not take place in the Abstract class!
        Parameters:
        set - Set<E>; a safe copy of the set to use for the immutable set
        copyOrWrap - Immutable; indicate whether the immutable is a copy or a wrap
    • Method Detail

      • toCollection

        public final Collection<E> toCollection()
        Returns a modifiable copy of this immutable collection.
        Specified by:
        toCollection in interface ImmutableCollection<E>
        Returns:
        a modifiable copy of this immutable collection.
      • getUnderlyingCollection

        protected Set<E> getUnderlyingCollection()
        Returns the underlying collection of this immutable collection. In case of Immutable.WRAP, this will be the original collection. In case of IMMUTABLE.COPY, this will be the internally stored (mutable) copy of the collection.
        Specified by:
        getUnderlyingCollection in class ImmutableAbstractCollection<E>
        Returns:
        the underlying collection of this immutable collection.
      • size

        public final int size()
        Returns the number of elements in this immutable collection. If this immutable collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
        Specified by:
        size in interface ImmutableCollection<E>
        Returns:
        the number of elements in this immutable collection
      • isEmpty

        public final boolean isEmpty()
        Returns true if this immutable collection contains no elements.
        Specified by:
        isEmpty in interface ImmutableCollection<E>
        Returns:
        true if this immutable collection contains no elements
      • contains

        public final boolean contains​(Object o)
        Returns true if this immutable collection contains the specified element. More formally, returns true if and only if this immutable collection contains at least one element e such that (o==null ? e==null : o.equals(e)).
        Specified by:
        contains in interface ImmutableCollection<E>
        Parameters:
        o - Object; element whose presence in this immutable collection is to be tested
        Returns:
        true if this immutable collection contains the specified element
      • toArray

        public final Object[] toArray()
        Returns an array containing all of the elements in this immutable collection. If this immutable collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

        See java.util.Collection.toArray() for more details.

        Specified by:
        toArray in interface ImmutableCollection<E>
        Returns:
        an array containing all of the elements in this immutable collection
      • toArray

        public final <T> T[] toArray​(T[] a)
        Returns an array containing all of the elements in this immutable collection; the runtime type of the returned array is that of the specified array. If the immutable collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this immutable collection.

        See java.util.Collection.toArray(T[]) for more details.

        Specified by:
        toArray in interface ImmutableCollection<E>
        Type Parameters:
        T - the runtime type of the array to contain the immutable collection
        Parameters:
        a - the array into which the elements of this immutable collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
        Returns:
        an array containing all of the elements in this immutable collection
      • iterator

        public final ImmutableIterator<E> iterator()
        Returns an immutable iterator over the elements in this immutable collection. There are no guarantees concerning the order in which the elements are returned (unless this immutable collection is an instance of some class that provides a guarantee). The ImmutableIterator is an Iterator where the remove() operation will throw an exception.
        Specified by:
        iterator in interface ImmutableCollection<E>
        Specified by:
        iterator in interface Iterable<E>
        Returns:
        an ImmutableIterator over the elements in this immutable collection
      • spliterator

        public final Spliterator<E> spliterator()
        Creates a Spliterator over the elements in this collection. Implementations should document characteristic values reported by the spliterator. See java.util.Collection for more information.
        Specified by:
        spliterator in interface ImmutableCollection<E>
        Specified by:
        spliterator in interface Iterable<E>
        Returns:
        a Spliterator over the elements in this collection
      • containsAll

        public final boolean containsAll​(Collection<?> c)
        Returns true if this immutable collection contains all of the elements in the specified collection.
        Specified by:
        containsAll in interface ImmutableCollection<E>
        Parameters:
        c - Collection<?>; collection to be checked for containment in this immutable collection
        Returns:
        true if this immutable collection contains all of the elements in the specified collection
        See Also:
        ImmutableCollection.contains(Object)
      • containsAll

        public final boolean containsAll​(ImmutableCollection<?> c)
        Returns true if this immutable collection contains all of the elements in the specified immutable collection.
        Specified by:
        containsAll in interface ImmutableCollection<E>
        Parameters:
        c - ImmutableCollection<?>; immutable collection to be checked for containment in this immutable collection
        Returns:
        true if this immutable collection contains all of the elements in the specified immutable collection
        See Also:
        ImmutableCollection.contains(Object)
      • parallelStream

        public final Stream<E> parallelStream()
        Returns a possibly parallel Stream with this collection as its source. It is allowable for this method to return a sequential stream.

        This method should be overridden when the ImmutableCollection.spliterator() method cannot return a spliterator that is IMMUTABLE, CONCURRENT, or late-binding. (See ImmutableCollection.spliterator() for details.)

        Specified by:
        parallelStream in interface ImmutableCollection<E>
        Returns:
        a possibly parallel Stream over the elements in this collection
      • isWrap

        public final boolean isWrap()
        Return whether the internal storage is a wrapped pointer to the original collection. If true, this means that anyone holding a pointer to this data structure can still change it. The users of the ImmutableCollection itself can, however, not make any changes.
        Specified by:
        isWrap in interface ImmutableCollection<E>
        Returns:
        boolean; whether the internal storage is a wrapped pointer to the original collection
      • equals

        public boolean equals​(Object obj)
        Force to redefine equals for the implementations of immutable collection classes.
        Specified by:
        equals in interface ImmutableCollection<E>
        Specified by:
        equals in interface ImmutableSet<E>
        Overrides:
        equals in class Object
        Parameters:
        obj - Object; the object to compare this collection with
        Returns:
        whether the objects are equal