Package org.organicdesign.fp.collections
Interface UnmodList<E>
-
- All Superinterfaces:
java.util.Collection<E>,java.lang.Iterable<E>,java.util.List<E>,Sized,Transformable<E>,UnmodCollection<E>,UnmodIterable<E>,UnmodSortedCollection<E>,UnmodSortedIterable<E>
- All Known Subinterfaces:
BaseList<E>,ImList<E>,MutableList<E>
- All Known Implementing Classes:
PersistentVector,PersistentVector.MutableVector,RangeOfInt,RrbTree,RrbTree.ImRrbt,RrbTree.MutableRrbt,UnmodList.AbstractUnmodList
public interface UnmodList<E> extends java.util.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.
-
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, java.util.Collection<? extends E> c)Deprecated.default booleanaddAll(java.util.Collection<? extends E> c)Deprecated.default voidclear()Deprecated.default booleancontains(java.lang.Object o)Deprecated.default booleancontainsAll(java.util.Collection<?> c)The default implementation of this method has O(this.size() + that.size()) or O(n) performance.default intindexOf(java.lang.Object o)The default implementation of this method has O(this.size()) performance.default booleanisEmpty()A convenience method to check if size is 0default UnmodSortedIterator<E>iterator()A convenience method to get a listIterator.default intlastIndexOf(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> voidpermutations(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 Eremove(int index)Deprecated.default booleanremove(java.lang.Object o)Deprecated.default booleanremoveAll(java.util.Collection<?> c)Deprecated.default booleanremoveIf(java.util.function.Predicate<? super E> filter)Deprecated.default voidreplaceAll(java.util.function.UnaryOperator<E> operator)Deprecated.default booleanretainAll(java.util.Collection<?> c)Deprecated.default Eset(int index, E element)Deprecated.default voidsort(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 org.organicdesign.fp.xform.Transformable
toImList, toImMap, toImRrbt, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableRrbt, toMutableSet, toMutableSortedMap, toMutableSortedSet
-
-
-
-
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:
addin interfacejava.util.Collection<E>- Specified by:
addin interfacejava.util.List<E>- Specified by:
addin interfaceUnmodCollection<E>
-
add
@Deprecated default void add(int index, E element)Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
addin interfacejava.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:
addAllin interfacejava.util.Collection<E>- Specified by:
addAllin interfacejava.util.List<E>- Specified by:
addAllin interfaceUnmodCollection<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:
addAllin interfacejava.util.List<E>
-
clear
@Deprecated default void clear()
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
clearin interfacejava.util.Collection<E>- Specified by:
clearin interfacejava.util.List<E>- Specified by:
clearin interfaceUnmodCollection<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!
-
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:
containsAllin interfacejava.util.Collection<E>- Specified by:
containsAllin interfacejava.util.List<E>- Specified by:
containsAllin interfaceUnmodCollection<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:
indexOfin interfacejava.util.List<E>
-
isEmpty
default boolean isEmpty()
A convenience method to check if size is 0- Specified by:
isEmptyin interfacejava.util.Collection<E>- Specified by:
isEmptyin interfacejava.util.List<E>- Specified by:
isEmptyin interfaceUnmodCollection<E>
-
iterator
default UnmodSortedIterator<E> iterator()
A convenience method to get a listIterator.- Specified by:
iteratorin interfacejava.util.Collection<E>- Specified by:
iteratorin interfacejava.lang.Iterable<E>- Specified by:
iteratorin interfacejava.util.List<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(java.lang.Object o)
The default implementation of this method has O(this.size()) performance.- Specified by:
lastIndexOfin interfacejava.util.List<E>
-
listIterator
default UnmodListIterator<E> listIterator()
- Specified by:
listIteratorin interfacejava.util.List<E>
-
listIterator
default UnmodListIterator<E> listIterator(int index)
Subclasses should override this when they can do so more efficiently.- Specified by:
listIteratorin interfacejava.util.List<E>
-
remove
@Deprecated default E remove(int index)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removein interfacejava.util.List<E>
-
remove
@Deprecated default boolean remove(java.lang.Object o)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removein interfacejava.util.Collection<E>- Specified by:
removein interfacejava.util.List<E>- Specified by:
removein interfaceUnmodCollection<E>
-
removeAll
@Deprecated default boolean removeAll(java.util.Collection<?> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removeAllin interfacejava.util.Collection<E>- Specified by:
removeAllin interfacejava.util.List<E>- Specified by:
removeAllin interfaceUnmodCollection<E>
-
replaceAll
@Deprecated default void replaceAll(java.util.function.UnaryOperator<E> operator)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
replaceAllin interfacejava.util.List<E>
-
retainAll
@Deprecated default boolean retainAll(java.util.Collection<?> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
retainAllin interfacejava.util.Collection<E>- Specified by:
retainAllin interfacejava.util.List<E>- Specified by:
retainAllin interfaceUnmodCollection<E>
-
set
@Deprecated default E set(int index, E element)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
setin interfacejava.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:
sortin interfacejava.util.List<E>
-
subList
default UnmodList<E> subList(int fromIndex, int toIndex)
- Specified by:
subListin interfacejava.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:
toArrayin interfacejava.util.Collection<E>- Specified by:
toArrayin interfacejava.util.List<E>- Specified by:
toArrayin interfaceUnmodCollection<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:
toArrayin interfacejava.util.Collection<E>- Specified by:
toArrayin interfacejava.util.List<E>- Specified by:
toArrayin interfaceUnmodCollection<E>
-
removeIf
@Deprecated default boolean removeIf(java.util.function.Predicate<? super E> filter)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removeIfin interfacejava.util.Collection<E>- Specified by:
removeIfin interfaceUnmodCollection<E>
-
-