Interface ImmutableList<E>
- Type Parameters:
E- the element type
- All Superinterfaces:
ImmutableCollection<E>,ImmutableSequencedCollection<E>,Iterable<E>,ReadOnlyCollection<E>,ReadOnlyList<E>,ReadOnlySequencedCollection<E>
- All Known Implementing Classes:
VectorList
An interface to an immutable list provides methods for creating a new immutable list with added or removed elements, without changing the original immutable list.
-
Method Summary
Modifier and TypeMethodDescriptionReturns a copy of this list that contains all elements of this list and the specified element appended to the end of the list.Returns a copy of this list that contains all elements of this list and the specified element appended to the end of the list.Returns a copy of this list that contains all elements of this list and all elements of the specified collection appended.Returns a copy of this list that contains all elements of this list and all elements of the specified collection appended.Returns a copy of this collection that contains all elements of this collection and also the specified element as the first element in the iteration order.Returns a copy of this collection that contains all elements of this collection and also the specified element as the last element in the iteration order.<T> ImmutableList<T> empty()Returns a copy of this list that is empty.readOnlySubList(int fromIndex, int toIndex) Returns a copy of this list that contains only the elements in the given index range.Returns a copy of this list that contains all elements of this list except the specified element.Returns a copy of this list that contains all elements of this list except the elements of the specified collection.removeAt(int index) Returns a copy of this list that contains all elements of this list except the element at the specified indexdefault ImmutableList<E> Returns a copy of this set that contains all elements of this set except the first.default ImmutableList<E> Returns a copy of this set that contains all elements of this set except the last.removeRange(int fromIndex, int toIndex) Returns a copy of this list that contains all elements of this list except the elements in the specified range.Returns a copy of this list that contains only elements that are in this list and in the specified collection.reverse()Returns a reversed copy of this list.Returns a copy of this list that contains all elements of this list and the specified element replaced.Returns a mutable copy of this list.Methods inherited from interface org.jhotdraw8.icollection.immutable.ImmutableCollection
filter, maxSizeMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyCollection
characteristics, contains, containsAll, isEmpty, size, stream, toArray, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyList
asList, equals, get, getFirst, getLast, getLast, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, peekFirst, peekLast, spliteratorMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection
asCollection, readOnlyReversed
-
Method Details
-
empty
Returns a copy of this list that is empty.- Specified by:
emptyin interfaceImmutableCollection<E>- Specified by:
emptyin interfaceImmutableSequencedCollection<E>- Type Parameters:
T- the element type of the returned collection- Returns:
- this list instance if it is already empty, or a different list instance that is empty.
-
addFirst
Description copied from interface:ImmutableSequencedCollectionReturns a copy of this collection that contains all elements of this collection and also the specified element as the first element in the iteration order.A collection may prevent that the same element can be added more than once.
If the iteration order is based on an ordering relation of the elements, then the element is only the first in a sequence of elements with the same ordering relation; which is not necessarily the first in the total iteration order.
- Specified by:
addFirstin interfaceImmutableSequencedCollection<E>- Parameters:
element- an element- Returns:
- this collection instance if it already contains the element as the first in the iteration order, or a different collection instance with the element added as the first in the iteration order
-
addLast
Description copied from interface:ImmutableSequencedCollectionReturns a copy of this collection that contains all elements of this collection and also the specified element as the last element in the iteration order.A collection may prevent that the same element can be added more than once.
If the iteration order is based on an ordering relation of the elements, then the element is only the last in a sequence of elements with the same ordering relation; which is not necessarily the last in the total iteration order.
- Specified by:
addLastin interfaceImmutableSequencedCollection<E>- Parameters:
element- an element- Returns:
- this collection instance if it already contains the element as the last in the iteration order, or a different collection instance with the element added as the last in the iteration order
-
removeFirst
Description copied from interface:ImmutableSequencedCollectionReturns a copy of this set that contains all elements of this set except the first.- Specified by:
removeFirstin interfaceImmutableSequencedCollection<E>- Returns:
- a new set instance with the first element removed
-
removeLast
Description copied from interface:ImmutableSequencedCollectionReturns a copy of this set that contains all elements of this set except the last.- Specified by:
removeLastin interfaceImmutableSequencedCollection<E>- Returns:
- a new set instance with the last element removed
-
add
Returns a copy of this list that contains all elements of this list and the specified element appended to the end of the list.- Specified by:
addin interfaceImmutableCollection<E>- Specified by:
addin interfaceImmutableSequencedCollection<E>- Parameters:
element- an element- Returns:
- a different list instance with the element added
-
add
Returns a copy of this list that contains all elements of this list and the specified element appended to the end of the list.- Parameters:
index- the insertion indexelement- an element- Returns:
- a different list instance with the element added
-
addAll
Returns a copy of this list that contains all elements of this list and all elements of the specified collection appended.- Specified by:
addAllin interfaceImmutableCollection<E>- Specified by:
addAllin interfaceImmutableSequencedCollection<E>- Parameters:
c- a collection to be added to this list- Returns:
- a different list instance with the elements added
-
addAll
Returns a copy of this list that contains all elements of this list and all elements of the specified collection appended.- Parameters:
index- the insertion indexc- a collection to be added to this list- Returns:
- a different list instance with the elements added
-
remove
Returns a copy of this list that contains all elements of this list except the specified element.- Specified by:
removein interfaceImmutableCollection<E>- Specified by:
removein interfaceImmutableSequencedCollection<E>- Parameters:
element- an element- Returns:
- this list instance if it already does not contain the element, or a different list instance with the element removed
-
removeAt
Returns a copy of this list that contains all elements of this list except the element at the specified index- Parameters:
index- an index- Returns:
- a different list instance with the element removed
-
removeRange
Returns a copy of this list that contains all elements of this list except the elements in the specified range.- Parameters:
fromIndex- from index (inclusive) of the sub-listtoIndex- to index (exclusive) of the sub-list- Returns:
- a different list instance with the element removed
-
removeAll
Returns a copy of this list that contains all elements of this list except the elements of the specified collection.- Specified by:
removeAllin interfaceImmutableCollection<E>- Specified by:
removeAllin interfaceImmutableSequencedCollection<E>- Parameters:
c- a collection with elements to be removed from this set- Returns:
- this list instance if it already does not contain the elements, or a different list instance with the elements removed
-
retainAll
Returns a copy of this list that contains only elements that are in this list and in the specified collection.- Specified by:
retainAllin interfaceImmutableCollection<E>- Specified by:
retainAllin interfaceImmutableSequencedCollection<E>- Parameters:
c- a collection with elements to be retained in this set- Returns:
- this list instance if it has not changed, or a different list instance with elements removed
-
reverse
ImmutableList<E> reverse()Returns a reversed copy of this list.This operation may be implemented in O(N).
Use
ReadOnlySequencedCollection.readOnlyReversed()if you only need to iterate in the reversed sequence over this list.- Returns:
- a reversed copy of this list.
-
set
Returns a copy of this list that contains all elements of this list and the specified element replaced.- Parameters:
element- an element- Returns:
- this list instance if it has not changed, or a different list instance with the element changed
-
readOnlySubList
Returns a copy of this list that contains only the elements in the given index range.- Specified by:
readOnlySubListin interfaceReadOnlyList<E>- Parameters:
fromIndex- from index (inclusive) of the sub-listtoIndex- to index (exclusive) of the sub-list- Returns:
- this list instance if it has not changed, or a different list instance with the element changed
-
toMutable
Returns a mutable copy of this list.- Specified by:
toMutablein interfaceImmutableCollection<E>- Returns:
- a mutable copy.
-