Package org.organicdesign.fp.collections
Interface UnmodList<E>
-
- All Superinterfaces:
Collection<E>,Iterable<E>,List<E>,Sized,Transformable<E>,UnmodCollection<E>,UnmodIterable<E>,UnmodSortedCollection<E>,UnmodSortedIterable<E>
- All Known Implementing Classes:
PersistentVector,PersistentVector.MutVector,RangeOfInt,RrbTree,RrbTree.ImRrbt,RrbTree.MutRrbt,UnmodList.AbstractUnmodList
public interface UnmodList<E> extends List<E>, UnmodSortedCollection<E>
Formalizes the return type ofCollections.unmodifiableList(List), deprecating mutator methods and implementing them to throw exceptions. You could think of this as "clearing the slate" to a point where immutable, functional, fluent interfaces can be built again.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classUnmodList.AbstractUnmodList<E>Implements equals and hashCode() methods compatible with java.util.List (which ignores order) to make defining unmod lists easier.-
Nested classes/interfaces inherited from interface org.organicdesign.fp.collections.UnmodIterable
UnmodIterable.UnIterable
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Deprecated Methods Modifier and Type Method Description default voidadd(int index, E element)Deprecated.default booleanadd(E e)Deprecated.default booleanaddAll(int index, @NotNull Collection<? extends E> c)Deprecated.default booleanaddAll(@NotNull Collection<? extends E> c)Deprecated.default voidclear()Deprecated.default booleancontains(Object o)Deprecated.default booleancontainsAll(@NotNull Collection<?> c)The default implementation of this method has O(this.size() + that.size()) or O(n) performance.default intindexOf(Object o)The default implementation of this method has O(this.size()) performance.default booleanisEmpty()A convenience method to check if size is 0default @NotNull UnmodSortedIterator<E>iterator()A convenience method to get a listIterator.default intlastIndexOf(Object o)The default implementation of this method has O(this.size()) performance.default @NotNull UnmodListIterator<E>listIterator()default @NotNull UnmodListIterator<E>listIterator(int index)Subclasses should override this when they can do so more efficiently.static <T> voidpermutations(@NotNull List<T> items, @NotNull Fn2<? super T,? super T,?> f)Apply the given function against all unique pairings of items in the list.default Eremove(int index)Deprecated.default booleanremove(Object o)Deprecated.default booleanremoveAll(@NotNull Collection<?> c)Deprecated.default booleanremoveIf(Predicate<? super E> filter)Deprecated.default voidreplaceAll(UnaryOperator<E> operator)Deprecated.default booleanretainAll(@NotNull Collection<?> c)Deprecated.default Eset(int index, E element)Deprecated.default voidsort(Comparator<? super E> c)Deprecated.default @NotNull UnmodList<E>subList(int fromIndex, int toIndex)default Object @NotNull []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 @NotNull []toArray(T @NotNull [] 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 org.organicdesign.fp.xform.Transformable
any, toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutList, toMutMap, toMutRrbt, toMutSet, toMutSortedMap, toMutSortedSet
-
-
-
-
Method Detail
-
permutations
static <T> void permutations(@NotNull @NotNull List<T> items, @NotNull @NotNull 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:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Specified by:
addin interfaceUnmodCollection<E>
-
add
@Deprecated default void add(int index, E element)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
addAll
@Deprecated default boolean addAll(@NotNull @NotNull Collection<? extends E> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Specified by:
addAllin interfaceUnmodCollection<E>
-
addAll
@Deprecated default boolean addAll(int index, @NotNull @NotNull Collection<? extends E> c)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
clear
@Deprecated default void clear()
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Specified by:
clearin interfaceUnmodCollection<E>
-
contains
@Deprecated default boolean contains(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 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!
-
containsAll
default boolean containsAll(@NotNull @NotNull 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:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceList<E>- Specified by:
containsAllin interfaceUnmodCollection<E>
-
indexOf
default int indexOf(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.
-
isEmpty
default boolean isEmpty()
A convenience method to check if size is 0- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Specified by:
isEmptyin interfaceUnmodCollection<E>
-
iterator
@NotNull default @NotNull UnmodSortedIterator<E> iterator()
A convenience method to get a listIterator.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceList<E>- Specified by:
iteratorin interfaceUnmodCollection<E>- Specified by:
iteratorin interfaceUnmodIterable<E>- Specified by:
iteratorin interfaceUnmodSortedCollection<E>- Specified by:
iteratorin interfaceUnmodSortedIterable<E>
-
lastIndexOf
default int lastIndexOf(Object o)
The default implementation of this method has O(this.size()) performance.- Specified by:
lastIndexOfin interfaceList<E>
-
listIterator
@NotNull default @NotNull UnmodListIterator<E> listIterator()
- Specified by:
listIteratorin interfaceList<E>
-
listIterator
@NotNull default @NotNull UnmodListIterator<E> listIterator(int index)
Subclasses should override this when they can do so more efficiently.- Specified by:
listIteratorin interfaceList<E>
-
remove
@Deprecated default E remove(int index)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
remove
@Deprecated default boolean remove(Object o)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceList<E>- Specified by:
removein interfaceUnmodCollection<E>
-
removeAll
@Deprecated default boolean removeAll(@NotNull @NotNull Collection<?> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>- Specified by:
removeAllin interfaceUnmodCollection<E>
-
replaceAll
@Deprecated default void replaceAll(UnaryOperator<E> operator)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
replaceAllin interfaceList<E>
-
retainAll
@Deprecated default boolean retainAll(@NotNull @NotNull Collection<?> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceList<E>- Specified by:
retainAllin interfaceUnmodCollection<E>
-
set
@Deprecated default E set(int index, E element)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
sort
@Deprecated default void sort(Comparator<? super E> c)
Deprecated.Not allowed - this is supposed to be unmodifiable
-
toArray
default Object @NotNull [] 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:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Specified by:
toArrayin interfaceUnmodCollection<E>
-
toArray
default <T> T @NotNull [] toArray(T @NotNull [] 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, 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 - memory allocation and potential garbage collection if the passed array is too small, the work of filling 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:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Specified by:
toArrayin interfaceUnmodCollection<E>
-
removeIf
@Deprecated default boolean removeIf(Predicate<? super E> filter)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removeIfin interfaceCollection<E>- Specified by:
removeIfin interfaceUnmodCollection<E>
-
-