java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.jhotdraw8.icollection.MutableVectorList<E>
- Type Parameters:
E- the element type
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,SequencedCollection<E>,ReadOnlyCollection<E>,ReadOnlyList<E>,ReadOnlySequencedCollection<E>
public class MutableVectorList<E>
extends AbstractList<E>
implements Serializable, ReadOnlyList<E>, List<E>, Cloneable
Implements the
List interface using a bit-mapped trie (Vector).
Features:
- supports up to 231 - 1 elements
- allows null elements
- is immutable
- is thread-safe
- iterates in the order of the list
Performance characteristics:
- addLast: O(log N)
- set: O(log N)
- removeAt: O(N)
- removeFirst,removeLast: O(log N)
- contains: O(N)
- toImmutable: O(1)
- clone: O(1)
- iterator.next(): O(1)
References:
This class has been derived from Vavr Vector.java.
- Vector.java. Copyright 2023 (c) vavr. MIT License.
- github.com
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new empty list.MutableVectorList(@NonNull Iterable<? extends E> c) Constructs a list containing the elements in the specified iterable. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanbooleanaddAll(int index, @NonNull Collection<? extends E> c) voidvoidclone()get(int index) Returns the element at the specified position in this list.getFirst()Gets the first element of the list.getLast()Gets the last element of the list.Returns a reversed-order view of this collection.readOnlySubList(int fromIndex, int toIndex) Returns a view of the portion of this list between the specified *fromIndex, inclusive, andtoIndex, exclusive.remove(int index) booleanremoveAll(@NonNull Collection<?> c) protected voidremoveRange(int fromIndex, int toIndex) booleanretainAll(@NonNull Collection<?> c) reversed()intsize()Returns the size of the collection.Returns a spliterator over elements of typeE.stream()Returns a stream.Methods inherited from class java.util.AbstractList
clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, toArray, toArray, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, toArrayMethods inherited from interface java.util.List
addAll, clear, contains, containsAll, equals, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, removeFirst, removeLast, replaceAll, sort, subList, toArray, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyCollection
characteristics, contains, containsAll, isEmpty, toArray, toArrayMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlyList
asList, equals, getLast, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, peekFirst, peekLastMethods inherited from interface org.jhotdraw8.icollection.readonly.ReadOnlySequencedCollection
asCollection
-
Constructor Details
-
MutableVectorList
public MutableVectorList()Constructs a new empty list. -
MutableVectorList
Constructs a list containing the elements in the specified iterable.- Parameters:
c- an iterable
-
-
Method Details
-
addFirst
-
addLast
-
readOnlyReversed
Description copied from interface:ReadOnlySequencedCollectionReturns a reversed-order view of this collection. Changes to the underlying collection are visible in the reversed view.- Specified by:
readOnlyReversedin interfaceReadOnlySequencedCollection<E>- Returns:
- a reversed-order view of this collection
-
reversed
-
size
public int size()Description copied from interface:ReadOnlyCollectionReturns the size of the collection.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein interfaceReadOnlyCollection<E>- Specified by:
sizein classAbstractCollection<E>- Returns:
- the size
-
get
Description copied from interface:ReadOnlyListReturns the element at the specified position in this list.- Specified by:
getin interfaceList<E>- Specified by:
getin interfaceReadOnlyList<E>- Specified by:
getin classAbstractList<E>- Parameters:
index- the index of the element- Returns:
- the element
-
getFirst
Description copied from interface:ReadOnlyListGets the first element of the list.- Specified by:
getFirstin interfaceList<E>- Specified by:
getFirstin interfaceReadOnlyList<E>- Specified by:
getFirstin interfaceReadOnlySequencedCollection<E>- Specified by:
getFirstin interfaceSequencedCollection<E>- Returns:
- the first element
-
getLast
Description copied from interface:ReadOnlyListGets the last element of the list.- Specified by:
getLastin interfaceList<E>- Specified by:
getLastin interfaceReadOnlyList<E>- Specified by:
getLastin interfaceReadOnlySequencedCollection<E>- Specified by:
getLastin interfaceSequencedCollection<E>- Returns:
- the last element
-
readOnlySubList
Description copied from interface:ReadOnlyListReturns a view of the portion of this list between the specified *fromIndex, inclusive, andtoIndex, exclusive.- Specified by:
readOnlySubListin interfaceReadOnlyList<E>- Parameters:
fromIndex- the from indextoIndex- the to index (exclusive)- Returns:
- the sub list
-
addAll
-
addAll
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>- Overrides:
removeAllin classAbstractCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceList<E>- Overrides:
retainAllin classAbstractCollection<E>
-
toImmutable
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>
-
set
-
add
-
remove
-
spliterator
Description copied from interface:ReadOnlyListReturns a spliterator over elements of typeE.- Specified by:
spliteratorin interfaceCollection<E>- Specified by:
spliteratorin interfaceIterable<E>- Specified by:
spliteratorin interfaceList<E>- Specified by:
spliteratorin interfaceReadOnlyList<E>- Returns:
- an iterator.
-
stream
Description copied from interface:ReadOnlyCollectionReturns a stream.- Specified by:
streamin interfaceCollection<E>- Specified by:
streamin interfaceReadOnlyCollection<E>- Returns:
- a stream
-
removeRange
protected void removeRange(int fromIndex, int toIndex) - Overrides:
removeRangein classAbstractList<E>
-
clone
-