Class Sets.SetView<E>

  • All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.Set<E>
    Enclosing class:
    Sets

    public abstract static class Sets.SetView<E>
    extends java.util.AbstractSet<E>
    An unmodifiable view of a set which may be backed by other sets; this view will change as the backing sets do. Contains methods to copy the data into a new set which will then remain stable. There is usually no reason to retain a reference of type SetView; typically, you either use it as a plain Set, or immediately invoke immutableCopy() or copyInto(S) and forget the SetView itself.
    Since:
    2.0
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean add​(E e)
      Deprecated.
      Unsupported operation.
      boolean addAll​(java.util.Collection<? extends E> newElements)
      Deprecated.
      Unsupported operation.
      void clear()
      Deprecated.
      Unsupported operation.
      <S extends java.util.Set<E>>
      S
      copyInto​(S set)
      Copies the current contents of this set view into an existing set.
      ImmutableSet<E> immutableCopy()
      Returns an immutable copy of the current contents of this set view.
      abstract UnmodifiableIterator<E> iterator()
      Scope the return type to UnmodifiableIterator to ensure this is an unmodifiable view.
      boolean remove​(java.lang.Object object)
      Deprecated.
      Unsupported operation.
      boolean removeAll​(java.util.Collection<?> oldElements)
      Deprecated.
      Unsupported operation.
      boolean removeIf​(java.util.function.Predicate<? super E> filter)
      Deprecated.
      Unsupported operation.
      boolean retainAll​(java.util.Collection<?> elementsToKeep)
      Deprecated.
      Unsupported operation.
      • Methods inherited from class java.util.AbstractSet

        equals, hashCode
      • Methods inherited from class java.util.AbstractCollection

        contains, containsAll, isEmpty, size, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.Set

        contains, containsAll, isEmpty, size, spliterator, toArray, toArray
    • Method Detail

      • immutableCopy

        public ImmutableSet<E> immutableCopy()
        Returns an immutable copy of the current contents of this set view. Does not support null elements.

        Warning: this may have unexpected results if a backing set of this view uses a nonstandard notion of equivalence, for example if it is a TreeSet using a comparator that is inconsistent with Object.equals(Object).

      • copyInto

        @CanIgnoreReturnValue
        public <S extends java.util.Set<E>> S copyInto​(S set)
        Copies the current contents of this set view into an existing set. This method has equivalent behavior to set.addAll(this), assuming that all the sets involved are based on the same notion of equivalence.
        Returns:
        a reference to set, for convenience
      • add

        @CanIgnoreReturnValue
        @Deprecated
        public final boolean add​(E e)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Set<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • remove

        @CanIgnoreReturnValue
        @Deprecated
        public final boolean remove​(java.lang.Object object)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Set<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • addAll

        @CanIgnoreReturnValue
        @Deprecated
        public final boolean addAll​(java.util.Collection<? extends E> newElements)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface java.util.Set<E>
        Overrides:
        addAll in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • removeAll

        @CanIgnoreReturnValue
        @Deprecated
        public final boolean removeAll​(java.util.Collection<?> oldElements)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        removeAll in interface java.util.Collection<E>
        Specified by:
        removeAll in interface java.util.Set<E>
        Overrides:
        removeAll in class java.util.AbstractSet<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • removeIf

        @CanIgnoreReturnValue
        @Deprecated
        public final boolean removeIf​(java.util.function.Predicate<? super E> filter)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Throws:
        java.lang.UnsupportedOperationException - always
      • retainAll

        @CanIgnoreReturnValue
        @Deprecated
        public final boolean retainAll​(java.util.Collection<?> elementsToKeep)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface java.util.Set<E>
        Overrides:
        retainAll in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • clear

        @Deprecated
        public final void clear()
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.Set<E>
        Overrides:
        clear in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • iterator

        public abstract UnmodifiableIterator<E> iterator()
        Scope the return type to UnmodifiableIterator to ensure this is an unmodifiable view.
        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.Set<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
        Since:
        20.0 (present with return type Iterator since 2.0)