Interface UnmodList<E>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  UnmodList.AbstractUnmodList<E>
      Implements equals and hashCode() methods compatible with java.util.List (which ignores order) to make defining unmod lists easier.
    • Method Summary

      All Methods Static Methods Instance Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      default void add​(int index, E element)
      Deprecated.
      default boolean add​(E e)
      Deprecated.
      default boolean addAll​(int index, java.util.Collection<? extends E> c)
      Deprecated.
      default boolean addAll​(java.util.Collection<? extends E> c)
      Deprecated.
      default void clear()
      Deprecated.
      default boolean contains​(java.lang.Object o)
      Deprecated.
      default boolean containsAll​(java.util.Collection<?> c)
      The default implementation of this method has O(this.size() + that.size()) or O(n) performance.
      default int indexOf​(java.lang.Object o)
      The default implementation of this method has O(this.size()) performance.
      default boolean isEmpty()
      A convenience method to check if size is 0
      default UnmodSortedIterator<E> iterator()
      A convenience method to get a listIterator.
      default int lastIndexOf​(java.lang.Object o)
      The default implementation of this method has O(this.size()) performance.
      default UnmodListIterator<E> listIterator()
      default UnmodListIterator<E> listIterator​(int index)
      Subclasses should override this when they can do so more efficiently.
      static <T> void permutations​(java.util.List<T> items, Fn2<? super T,​? super T,​?> f)
      Apply the given function against all unique pairings of items in the list.
      default E remove​(int index)
      Deprecated.
      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 void replaceAll​(java.util.function.UnaryOperator<E> operator)
      Deprecated.
      default boolean retainAll​(java.util.Collection<?> c)
      Deprecated.
      default E set​(int index, E element)
      Deprecated.
      default void sort​(java.util.Comparator<? super E> c)
      Deprecated.
      default UnmodList<E> subList​(int fromIndex, int toIndex)
      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.List

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

        size
    • Method Detail

      • permutations

        static <T> void permutations​(java.util.List<T> items,
                                     Fn2<? super T,​? super T,​?> f)
        Apply the given function against all unique pairings of items in the list. Does this belong on Fn2 instead of List?
      • 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.List<E>
        Specified by:
        add in interface UnmodCollection<E>
      • add

        @Deprecated
        default void add​(int index,
                         E element)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        add in interface java.util.List<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.List<E>
        Specified by:
        addAll in interface UnmodCollection<E>
      • addAll

        @Deprecated
        default boolean addAll​(int index,
                               java.util.Collection<? extends E> c)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        addAll in interface java.util.List<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.List<E>
        Specified by:
        clear in interface UnmodCollection<E>
      • contains

        @Deprecated
        default boolean contains​(java.lang.Object o)
        Deprecated.
        This method is deprecated because implementing it on a List has O(n) performance. It will never go away because it's declared on java.util.Collection which List extends. It still shouldn't be used. If you need repeated or fast contains() tests, use a Set instead instead of a List. SortedSet.contains() has O(log2 n) performance. HashSet.contains() has O(1) performance! If you truly need a one-shot contains test, iterate the list manually, or override the deprecation warning, but include a description of why you need to use a List instead of some kind of Set or Map!
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.List<E>
      • containsAll

        default boolean containsAll​(java.util.Collection<?> c)
        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.List<E>
        Specified by:
        containsAll in interface UnmodCollection<E>
      • indexOf

        default int indexOf​(java.lang.Object o)
        The default implementation of this method has O(this.size()) performance. If you call this much, you probably want to use a Map<Integer,T> instead for O(1) performance.
        Specified by:
        indexOf in interface java.util.List<E>
      • isEmpty

        default boolean isEmpty()
        A convenience method to check if size is 0
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface java.util.List<E>
        Specified by:
        isEmpty in interface UnmodCollection<E>
      • lastIndexOf

        default int lastIndexOf​(java.lang.Object o)
        The default implementation of this method has O(this.size()) performance.
        Specified by:
        lastIndexOf in interface java.util.List<E>
      • listIterator

        default UnmodListIterator<E> listIterator()
        Specified by:
        listIterator in interface java.util.List<E>
      • listIterator

        default UnmodListIterator<E> listIterator​(int index)
        Subclasses should override this when they can do so more efficiently.
        Specified by:
        listIterator in interface java.util.List<E>
      • remove

        @Deprecated
        default E remove​(int index)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        remove in interface java.util.List<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.List<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.List<E>
        Specified by:
        removeAll in interface UnmodCollection<E>
      • replaceAll

        @Deprecated
        default void replaceAll​(java.util.function.UnaryOperator<E> operator)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        replaceAll in interface java.util.List<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.List<E>
        Specified by:
        retainAll in interface UnmodCollection<E>
      • set

        @Deprecated
        default E set​(int index,
                      E element)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        set in interface java.util.List<E>
      • sort

        @Deprecated
        default void sort​(java.util.Comparator<? super E> c)
        Deprecated.
        Not allowed - this is supposed to be unmodifiable
        Specified by:
        sort in interface java.util.List<E>
      • subList

        default UnmodList<E> subList​(int fromIndex,
                                     int toIndex)
        Specified by:
        subList in interface java.util.List<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.List<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.List<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>