Interface UnmodSet<E>

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      default boolean add​(E e)
      Deprecated.
      default boolean addAll​(java.util.Collection<? extends E> c)
      Deprecated.
      default void clear()
      Deprecated.
      boolean contains​(java.lang.Object o)
      Returns true if the set contains the given item.
      default boolean containsAll​(java.util.Collection<?> items)
      The default implementation of this method has O(this.size() + that.size()) or O(n) performance.
      default boolean isEmpty()
      This is a convenience method inherited from Collection that returns true if size() == 0 (if this set contains no elements).
      UnmodIterator<E> iterator()
      Iterates over contents with no guarantees about their ordering.
      default boolean remove​(java.lang.Object o)
      Deprecated.
      default boolean removeAll​(java.util.Collection<?> c)
      Deprecated.
      default boolean removeIf​(java.util.function.Predicate<? super E> filter)
      Deprecated.
      default boolean retainAll​(java.util.Collection<?> c)
      Deprecated.
      default java.lang.Object[] toArray()
      This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations.
      default <T> T[] toArray​(T[] as)
      This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations.
      • 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

        equals, hashCode, size, spliterator
      • Methods inherited from interface org.organicdesign.fp.collections.Sized

        size
    • Method Detail

      • add

        @Deprecated
        default boolean add​(E e)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Set<E>
        Specified by:
        add in interface UnmodCollection<E>
      • addAll

        @Deprecated
        default boolean addAll​(java.util.Collection<? extends E> c)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        addAll in interface java.util.Collection<E>
        Specified by:
        addAll in interface java.util.Set<E>
        Specified by:
        addAll in interface UnmodCollection<E>
      • clear

        @Deprecated
        default void clear()
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.Set<E>
        Specified by:
        clear in interface UnmodCollection<E>
      • contains

        boolean contains​(java.lang.Object o)
        Returns true if the set contains the given item. This is the defining method of a set. Sets have to override this because the default implementation in UnmodCollection is O(n) whereas a sorted set should be O(log n) or O(1).
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.Set<E>
      • containsAll

        default boolean containsAll​(java.util.Collection<?> items)
        The default implementation of this method has O(this.size() + that.size()) or O(n) performance. So even though contains() is impossible to implement efficiently for Lists, containsAll() has a decent implementation (brute force would be O(this.size() * that.size()) or O(n^2) ).
        Specified by:
        containsAll in interface java.util.Collection<E>
        Specified by:
        containsAll in interface java.util.Set<E>
        Specified by:
        containsAll in interface UnmodCollection<E>
      • isEmpty

        default boolean isEmpty()
        This is a convenience method inherited from Collection that returns true if size() == 0 (if this set contains no elements).
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface java.util.Set<E>
        Specified by:
        isEmpty in interface UnmodCollection<E>
      • iterator

        UnmodIterator<E> iterator()
        Iterates over contents with no guarantees about their ordering. An unmodifiable iterator A one-time use, mutable, not-thread-safe way to get each value of the underling collection in turn. I experimented with various thread-safe alternatives, but the JVM is optimized around iterators so this is the lowest common denominator of collection iteration, even though iterators are inherently mutable.
        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 interface UnmodCollection<E>
        Specified by:
        iterator in interface UnmodIterable<E>
      • remove

        @Deprecated
        default boolean remove​(java.lang.Object o)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Set<E>
        Specified by:
        remove in interface UnmodCollection<E>
      • removeAll

        @Deprecated
        default boolean removeAll​(java.util.Collection<?> c)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        removeAll in interface java.util.Collection<E>
        Specified by:
        removeAll in interface java.util.Set<E>
        Specified by:
        removeAll in interface UnmodCollection<E>
      • retainAll

        @Deprecated
        default boolean retainAll​(java.util.Collection<?> c)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface java.util.Set<E>
        Specified by:
        retainAll in interface UnmodCollection<E>
      • toArray

        default java.lang.Object[] toArray()
        This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations. If you really need an array, consider using the somewhat type-safe version of this method instead, but read the caveats first. This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations. If you really need an array, consider using the somewhat type-safe version of this method instead, but read the caveats first.
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.Set<E>
        Specified by:
        toArray in interface UnmodCollection<E>
      • toArray

        default <T> T[] toArray​(T[] as)
        This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations. If you need to create an array (you almost always do) then the best way to use this method is: MyThing[] things = col.toArray(new MyThing[coll.size()]); Calling this method any other way causes unnecessary work to be done - an extra memory allocation and potential garbage collection if the passed array is too small, extra effort to fill the end of the array with nulls if it is too large. This method goes against Josh Bloch's Item 25: "Prefer Lists to Arrays", but is provided for backwards compatibility in some performance-critical situations. If you need to create an array (you almost always do) then the best way to use this method is: MyThing[] things = col.toArray(new MyThing[coll.size()]); Calling this method any other way causes unnecessary work to be done - an extra memory allocation and potential garbage collection if the passed array is too small, extra effort to fill the end of the array with nulls if it is too large.
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.Set<E>
        Specified by:
        toArray in interface UnmodCollection<E>
      • removeIf

        @Deprecated
        default boolean removeIf​(java.util.function.Predicate<? super E> filter)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        removeIf in interface java.util.Collection<E>
        Specified by:
        removeIf in interface UnmodCollection<E>