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 class
UnmodList.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 void
add(int index, E element)
Deprecated.default boolean
add(E e)
Deprecated.default boolean
addAll(int index, @NotNull Collection<? extends E> c)
Deprecated.default boolean
addAll(@NotNull Collection<? extends E> c)
Deprecated.default void
clear()
Deprecated.default boolean
contains(Object o)
Deprecated.default boolean
containsAll(@NotNull Collection<?> c)
The default implementation of this method has O(this.size() + that.size()) or O(n) performance.default int
indexOf(Object o)
The default implementation of this method has O(this.size()) performance.default boolean
isEmpty()
A convenience method to check if size is 0default @NotNull UnmodSortedIterator<E>
iterator()
A convenience method to get a listIterator.default int
lastIndexOf(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> void
permutations(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(Object o)
Deprecated.default boolean
removeAll(@NotNull Collection<?> c)
Deprecated.default boolean
removeIf(Predicate<? super E> filter)
Deprecated.default void
replaceAll(UnaryOperator<E> operator)
Deprecated.default boolean
retainAll(@NotNull Collection<?> c)
Deprecated.default E
set(int index, E element)
Deprecated.default void
sort(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(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 interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Specified by:
add
in 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:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Specified by:
addAll
in 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:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Specified by:
clear
in 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 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:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
- Specified by:
containsAll
in 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:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Specified by:
isEmpty
in interfaceUnmodCollection<E>
-
iterator
@NotNull default @NotNull UnmodSortedIterator<E> iterator()
A convenience method to get a listIterator.- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in interfaceList<E>
- Specified by:
iterator
in interfaceUnmodCollection<E>
- Specified by:
iterator
in interfaceUnmodIterable<E>
- Specified by:
iterator
in interfaceUnmodSortedCollection<E>
- Specified by:
iterator
in interfaceUnmodSortedIterable<E>
-
lastIndexOf
default int lastIndexOf(Object o)
The default implementation of this method has O(this.size()) performance.- Specified by:
lastIndexOf
in interfaceList<E>
-
listIterator
@NotNull default @NotNull UnmodListIterator<E> listIterator()
- Specified by:
listIterator
in interfaceList<E>
-
listIterator
@NotNull default @NotNull UnmodListIterator<E> listIterator(int index)
Subclasses should override this when they can do so more efficiently.- Specified by:
listIterator
in 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:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Specified by:
remove
in interfaceUnmodCollection<E>
-
removeAll
@Deprecated default boolean removeAll(@NotNull @NotNull Collection<?> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceList<E>
- Specified by:
removeAll
in interfaceUnmodCollection<E>
-
replaceAll
@Deprecated default void replaceAll(UnaryOperator<E> operator)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
replaceAll
in interfaceList<E>
-
retainAll
@Deprecated default boolean retainAll(@NotNull @NotNull Collection<?> c)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceList<E>
- Specified by:
retainAll
in 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:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Specified by:
toArray
in 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 (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 interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Specified by:
toArray
in interfaceUnmodCollection<E>
-
removeIf
@Deprecated default boolean removeIf(Predicate<? super E> filter)
Deprecated.Not allowed - this is supposed to be unmodifiable- Specified by:
removeIf
in interfaceCollection<E>
- Specified by:
removeIf
in interfaceUnmodCollection<E>
-
-