Class IList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.magicwerk.brownies.collections.IList<E>
- Type Parameters:
E
- type of elements stored in the list
- All Implemented Interfaces:
Serializable
,Cloneable
,Iterable<E>
,Collection<E>
,List<E>
,RandomAccess
,SequencedCollection<E>
,ICollection<E>
,IListable<E>
- Direct Known Subclasses:
BigList
,BooleanObjBigList
,BooleanObjGapList
,ByteObjBigList
,ByteObjGapList
,CharObjBigList
,CharObjGapList
,DoubleObjBigList
,DoubleObjGapList
,FloatObjBigList
,FloatObjGapList
,GapList
,IntObjBigList
,IntObjGapList
,KeyListImpl
,LongObjBigList
,LongObjGapList
,ShortObjBigList
,ShortObjGapList
public abstract class IList<E>
extends AbstractList<E>
implements ICollection<E>, IListable<E>, List<E>, RandomAccess, Cloneable, Serializable
Class
IList
is the abstract class which offers all interfaces implemented by ArrayList.
It also offers additional methods which are then available in all implementations of GapList
and BigList
.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Wrapper to treat an array asIListable
.protected static class
Wrapper to treat aCollection
asIListable
.protected static class
protected static class
Wrapper to treat a repeated element asIListable
.(package private) class
Iterator supports forward and reverse iteration.(package private) class
Iterator supports forward and reverse iteration. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
private static final int
private static final int
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts the specified element at the specified position in this list.boolean
boolean
addAll
(int index, Collection<? extends E> coll) Inserts all of the elements in the specified collection into this list, starting at the specified position.boolean
Inserts all of the elements in the specified list into this list, starting at the specified position.boolean
addAll
(Collection<? extends E> coll) Adds all of the elements in the specified collection into this list.boolean
Adds all of the elements in the specified list into this list.boolean
Inserts the specified elements into this list, starting at the specified position.boolean
boolean
Adds all specified elements into this list.boolean
void
boolean
addIfAbsent
(E elem) Add elements to the end if it is not already contained in the list.void
SeeDeque.addLast(E)
boolean
Inserts element multiple time to list, starting at the specified position.boolean
Adds element multiple time to list.asDeque()
asIListable
(Collection<? extends E> coll) Return correct IListable for passed collection.abstract <K> int
binarySearch
(int index, int len, K key, Comparator<? super K> comparator) Searches the specified range for an object using the binary search algorithm.<K> int
binarySearch
(K key, Comparator<? super K> comparator) Searches the specified range for an object using the binary* search algorithm.abstract int
capacity()
Returns capacity of this list.protected void
checkIndex
(int index) Check that specified index is valid for getting/setting elements.protected void
checkIndexAdd
(int index) Check that specified index is valid for adding elements.protected void
checkLength
(int len) Check that specified length is valid (>= 0).protected void
checkLengths
(int len1, int len2) Check that both specified lengths are valid (>= 0) and equal.protected void
checkNonNull
(Object obj) Check that object is not null.protected void
checkRange
(int index, int len) Check that specified range is valid.void
clear()
clone()
Returns a shallow copy of this list.boolean
boolean
containsAll
(Collection<?> coll) boolean
containsAny
(Collection<?> coll) Returns true if any of the elements of the specified collection is contained in the list.boolean
containsIf
(Predicate<? super E> predicate) Determines whether the list contains a matching element.copy()
Returns a shallow copy of this list.void
copy
(int srcIndex, int dstIndex, int len) Copy specified elements.int
Counts how many times the specified element is contained in the list.int
Counts how many elements in the list match the predicate.crop()
Returns a copy this list but without elements.protected abstract boolean
Helper method for adding an element to the list.protected boolean
Helper method for adding multiple elements to the list.protected abstract void
Assign this list the content of the that list.protected void
doClear()
protected abstract void
Initialize this object after the bitwise copy has been made by Object.clone().doCreate
(int capacity) Create list with specified capacity.protected <T> T[]
doCreateArray
(Class<T> clazz, int len) Create array.protected abstract void
doEnsureCapacity
(int minCapacity) Increases the capacity of this list instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.protected abstract E
doGet
(int index) Helper method for getting an element from the list.protected <T> void
doGetAll
(T[] array, int index, int len) Helper method to fill the specified elements in an array.protected int
Returns the index of the first occurrence of the specified element in this list, starting the search at the specified position.protected int
doIndexOfIf
(Predicate<? super E> predicate, int fromIndex) Returns the index of the first element which matches the specified predicate in this list, starting the search at the specified position.protected void
protected int
doLastIndexOf
(Object elem, int fromIndex) Returns the index of the last occurrence of the specified element in this list, starting the search at the specified position.protected int
doLastIndexOfIf
(Predicate<? super E> predicate, int fromIndex) Returns the index of the last occurrence of the specified element in this list, starting the search at the specified position.protected void
doModify()
This method is called internally before elements are allocated or freed.protected void
protected abstract E
doRemove
(int index) Helper method to remove an element.protected void
doRemoveAll
(int index, int len) Remove specified range of elements from list.protected boolean
protected abstract E
Sets an element at specified position.protected void
doRotate
(int index, int len, int distance) Internal method to rotate specified elements in the list.protected abstract E
Helper method for setting an element in the list.(package private) void
doTransfer
(int transferMode, int srcIndex, int srcLen, IList<? super E> dst, int dstIndex, int dstLen) (package private) void
doTransferSwap
(int srcIndex, IList<E> dst, int dstIndex, int len) void
drag
(int srcIndex, int dstIndex, int len) Drag specified elements.element()
SeeDeque.element()
void
ensureCapacity
(int minCapacity) Increases the capacity of this instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.boolean
(package private) static boolean
equalsElem
(Object elem1, Object elem2) Helper function to check two elements stored in the list for equality.extract
(int index, int len) Removes specified range of elements from list and return them.Removes and returns all elements in the list which match the predicate.void
Fill list.Create a new list by applying the specified filter to all elements.<R> IList
<R> Create a new list by applying the specified filter first and then the mapping function to all elements selected.<R,
C extends Collection<R>>
IList<R> Create a new list by applying the specified mapping function to all elements.get
(int index) Return element at specified positiongetAll
(int index, int len) Returns specified range of elements from list.Returns all elements in the list equal to the specified element.protected abstract E
Returns distinct elements in the list.getFirst()
Returns the first element stored in the collection.Returns the first element stored in the collection.Get first element in the list which matches the predicate.getLast()
SeeDeque.getLast()
Returns the last element stored in the list.Returns the only element stored in the collection.Returns the only element stored in the collection or null if the collection is empty.int
hashCode()
(package private) static int
hashCodeElem
(Object elem) Helper method to calculate hash code of a element stored in the list.Returns an immutable copy of this list.int
int
Returns the index of the first occurrence of the specified element in this list, starting the search at the specified position.int
Returns the index of the first element which matches the specified predicate in this list.int
Returns the index of the first element which matches the specified predicate in this list, starting the search at the specified position.void
initAll
(Collection<? extends E> coll) Initializes the list so it will afterwards only contain the elements of the collection.void
Initializes the list so it will afterwards only contain the elements of the collection.void
Initializes the list so it will afterwards only contain the elements of the array.void
Initializes the list so it will afterwards have a size oflen
and contain only the elementelem
.boolean
isEmpty()
abstract boolean
Returns true if this list is either unmodifiable or immutable, false otherwise.iterator()
int
lastIndexOf
(Object elem) int
lastIndexOf
(Object elem, int fromIndex) Returns the index of the last occurrence of the specified element in this list, starting the search at the specified position.int
lastIndexOfIf
(Predicate<? super E> predicate) Returns the index of the last element which matches the specified predicate in this list.int
lastIndexOfIf
(Predicate<? super E> predicate, int fromIndex) Returns the index of the last occurrence of the specified element in this list, starting the search at the specified position.listIterator
(int index) <R> IList
<R> Create a new list by applying the specified mapping function to all elements.<R> IList
<R> Create a new list by applying the specified mapping function to all elements and then filtering it.void
move
(int srcIndex, int dstIndex, int len) Move specified elements.boolean
SeeDeque.offer(E)
boolean
offerFirst
(E elem) boolean
peek()
SeeDeque.peek()
peekLast()
SeeDeque.peekLast()
poll()
SeeDeque.poll()
pollLast()
SeeDeque.pollLast()
pop()
SeeDeque.pop()
void
SeeDeque.push(E)
Sets or adds the element.void
putAll
(int index, Collection<? extends E> coll) Set or add the specified elements.void
Set or add the specified elements.void
Set or add the specified elements.void
Set or add the specified element multiple times.remove()
SeeDeque.remove()
remove
(int index) void
remove
(int index, int len) Remove specified range of elements from list.boolean
Removes all equal elements.boolean
removeAll
(Collection<?> coll) boolean
boolean
removeFirstOccurrence
(Object elem) boolean
Removes all elements in the list which match the predicate.boolean
removeLastOccurrence
(Object elem) protected void
void
replaceAll
(int index, int len, Collection<? extends E> coll) Replaces the specified range with new elements.void
replaceAll
(int index, int len, IList<? extends E> list) Replaces the specified range with new elements.void
replaceArray
(int index, int len, E... elems) Replaces the specified range with new elements.void
replaceMult
(int index, int len, int numElems, E elem) Replaces the specified range with new elements.void
Resizes the list so it will afterwards have a size oflen
.void
retain
(int index, int len) Retain specified range of elements from list, the other elements are removed.boolean
retainAll
(Collection<?> coll) boolean
boolean
Retains all elements in the list which match the predicate.void
reverse()
Reverses the order of all elements in the specified list.void
reverse
(int index, int len) Reverses the order of the specified elements in the list.void
rotate
(int distance) Rotate specified elements in the list.void
rotate
(int index, int len, int distance) Rotate specified elements in the list.void
setAll
(int index, Collection<? extends E> coll) Sets the specified elements.void
Sets the specified elements.void
Sets the specified elements.void
void
Sets the element multiple times.abstract int
size()
Return size of listabstract void
sort
(int index, int len, Comparator<? super E> comparator) Sort specified elements in the list using the specified comparator.void
sort
(Comparator<? super E> comparator) Sort elements in the list using the specified comparator.void
swap
(int index1, int index2, int len) Swap the specified elements in the list.Object[]
toArray()
Object[]
toArray
(int index, int len) Returns an array containing the specified elements in this list.<T> T[]
Returns an array containing the elements in this list.<T> T[]
Returns an array containing the specified elements in this list.(package private) static Object[]
toArray
(Collection<?> coll) Copies the collection values into an array.<T> T[]
toArray
(T[] array) <T> T[]
toArray
(T[] array, int index, int len) Returns an array containing the specified elements in this list.toString()
static <E> void
transferCopy
(IList<E> src, int srcIndex, int srcLen, IList<? super E> dst, int dstIndex, int dstLen) Copies elements from one list to another.static <E> void
transferMove
(IList<E> src, int srcIndex, int srcLen, IList<? super E> dst, int dstIndex, int dstLen) Moves elements from one list to another by setting it to null in the source list.static <E> void
transferRemove
(IList<E> src, int srcIndex, int srcLen, IList<? super E> dst, int dstIndex, int dstLen) Moves elements from one list to another by removing it from the source list.static <E> void
transferSwap
(IList<E> src, int srcIndex, IList<E> dst, int dstIndex, int len) Swaps elements from two lists.void
transform
(UnaryOperator<E> op) Change the list by applying the specified operator to all elements.Create a new list by applying the specified transforming operator to all elements.abstract void
An application can use this operation to minimize the storage of an instance.Returns an unmodifiable view of this list.Methods inherited from class java.util.AbstractList
removeRange, subList
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods inherited from interface java.util.List
replaceAll, reversed, spliterator, subList
-
Field Details
-
TRANSFER_COPY
private static final int TRANSFER_COPY- See Also:
-
TRANSFER_MOVE
private static final int TRANSFER_MOVE- See Also:
-
TRANSFER_REMOVE
private static final int TRANSFER_REMOVE- See Also:
-
-
Constructor Details
-
IList
public IList()
-
-
Method Details
-
asDeque
- Returns:
- list of IList as
Deque
-
toArray
Copies the collection values into an array.- Parameters:
coll
- collection of values- Returns:
- array containing the collection values
-
copy
Returns a shallow copy of this list. The new list will contain the same elements as the source list, i.e. the elements themselves are not copied. The capacity of the list will be set to the number of elements, i.e. size and capacity are equal. This returned list will be modifiable, i.e. a read-only list will be copied and be modifiable again.- Specified by:
copy
in interfaceICollection<E>
- Returns:
- a modifiable copy of this list
-
clone
Returns a shallow copy of this list. The new list will contain the same elements as the source list, i.e. the elements themselves are not copied. The capacity of the list will be set to the number of elements, i.e. size and capacity are equal. If the list is read-only, the same list is returned without change. Usecopy()
to . -
crop
Returns a copy this list but without elements. The new list will have the same type as this list.- Specified by:
crop
in interfaceICollection<E>
- Returns:
- an empty copy of this list
-
isReadOnly
public abstract boolean isReadOnly()Returns true if this list is either unmodifiable or immutable, false otherwise. -
unmodifiableList
Returns an unmodifiable view of this list. This method allows modules to provide users with "read-only" access to internal lists, where changes made to the original list are visible as query operations on the returned list "read through" to the specified list. Attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException. If this list is already unmodifiable, it is returned unchanged. SeeimmutableList()
to get an immutable copy of a list.- Returns:
- an unmodifiable view of the specified list
-
immutableList
Returns an immutable copy of this list. The returned list is independent from the original list, i.e. changes done later are not seen. Attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException. If this list is already immutable, it is returned unchanged. SeeunmodifiableList()
to get unmodifiable view of a list.- Returns:
- an immutable copy of the specified list
-
doClone
Initialize this object after the bitwise copy has been made by Object.clone().- Parameters:
that
- source object
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Overrides:
clear
in classAbstractList<E>
-
doClear
protected void doClear() -
resize
Resizes the list so it will afterwards have a size oflen
. If the list must grow, the specified elementelem
will be used for filling.- Parameters:
len
- new size of listelem
- element which will be used for extending the list- Throws:
IndexOutOfBoundsException
- if the range is invalid
-
size
public abstract int size()Description copied from interface:IListable
Return size of list -
capacity
public abstract int capacity()Returns capacity of this list. Note that two lists are considered equal even if they have a distinct capacity. Also the capacity can be changed by operations like clone() etc.- Returns:
- capacity of this list
-
get
Description copied from interface:IListable
Return element at specified position -
doGet
Helper method for getting an element from the list. This is the only method which really gets an element. Override if you need to validity checks before getting.- Parameters:
index
- index of element to return- Returns:
- the element at the specified position in this list
-
doSet
Helper method for setting an element in the list. This is the only method which really sets an element. Override if you need to validity checks before setting.- Parameters:
index
- index where element will be placedelem
- element to set- Returns:
- old element which was at the position
-
set
-
put
Sets or adds the element. If the index is smaller than the size of the list, the existing element is replaced. If the index equals the size of the list, the element is added.- Parameters:
index
- index where element will be placedelem
- element to put- Returns:
- old element if an element was replaced, null if the element was added
- Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index > size())
-
doReSet
Sets an element at specified position. This method is used internally if existing elements will be moved etc. Override if you need to validity checks.- Parameters:
index
- index where element will be placedelem
- element to set- Returns:
- old element which was at the position
-
getDefaultElem
-
doModify
protected void doModify()This method is called internally before elements are allocated or freed. Override if you need to validity checks. -
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classAbstractList<E>
-
add
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices). -
doAdd
Helper method for adding an element to the list. This is the only method which really adds an element. Override if you need to validity checks before adding.- Parameters:
index
- index where element should be added (-1 means it is up to the implementation to choose the index)elem
- element to add- Returns:
- true if element has been added, false otherwise
-
remove
-
doRemove
Helper method to remove an element. This is the only method which really removes an element. Override if you need to validity checks before removing.- Parameters:
index
- index of element to remove- Returns:
- removed element
-
ensureCapacity
public void ensureCapacity(int minCapacity) Increases the capacity of this instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.- Parameters:
minCapacity
- the desired minimum capacity
-
doEnsureCapacity
protected abstract void doEnsureCapacity(int minCapacity) Increases the capacity of this list instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.- Parameters:
minCapacity
- the desired minimum capacity
-
trimToSize
public abstract void trimToSize()An application can use this operation to minimize the storage of an instance. -
equals
- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceList<E>
- Overrides:
equals
in classAbstractList<E>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceList<E>
- Overrides:
hashCode
in classAbstractList<E>
-
toString
- Overrides:
toString
in classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
equalsElem
Helper function to check two elements stored in the list for equality.- Parameters:
elem1
- first elementelem2
- second element- Returns:
- true if the elements are equal, otherwise false
-
hashCodeElem
Helper method to calculate hash code of a element stored in the list.- Parameters:
elem
- element- Returns:
- hash code for element
-
count
Counts how many times the specified element is contained in the list.- Parameters:
elem
- element to count- Returns:
- count how many times the specified element is contained in the list
-
countIf
Description copied from interface:ICollection
Counts how many elements in the list match the predicate.- Specified by:
countIf
in interfaceICollection<E>
- Parameters:
predicate
- a predicate which returnstrue
for elements to be counted- Returns:
- count how many elements in the list match the predicate
-
getSingle
Description copied from interface:ICollection
Returns the only element stored in the collection. If the collection size is not 1, aNoSuchElementException
is thrown.- Specified by:
getSingle
in interfaceICollection<E>
- Returns:
- only element stored in the collection
-
getSingleOrNull
Description copied from interface:ICollection
Returns the only element stored in the collection or null if the collection is empty. If the collection's size is greater than 1, aNoSuchElementException
is thrown.- Specified by:
getSingleOrNull
in interfaceICollection<E>
- Returns:
- only element stored in the collection or null if empty
-
getAll
Returns all elements in the list equal to the specified element.- Parameters:
elem
- element to look for- Returns:
- all elements in the list equal to the specified element
-
getIf
Get first element in the list which matches the predicate.- Specified by:
getIf
in interfaceICollection<E>
- Parameters:
predicate
- a predicate which returnstrue
for elements to be selected- Returns:
- first element matching the predicate, null otherwise
-
getDistinct
Returns distinct elements in the list.- Returns:
- distinct elements in the list
-
map
Description copied from interface:ICollection
Create a new list by applying the specified mapping function to all elements. The returned list is of typeIList
, typicallyGapList
unless the original type isBigList
.- Specified by:
map
in interfaceICollection<E>
- Parameters:
func
- mapping function- Returns:
- created list
-
flatMap
Description copied from interface:ICollection
Create a new list by applying the specified mapping function to all elements. The returned list is of typeIList
, typicallyGapList
unless the original type isBigList
.- Specified by:
flatMap
in interfaceICollection<E>
- Parameters:
func
- mapping function- Returns:
- created list
-
mapFilter
Description copied from interface:ICollection
Create a new list by applying the specified mapping function to all elements and then filtering it. The returned list is of typeIList
, typicallyGapList
unless the original type isBigList
.- Specified by:
mapFilter
in interfaceICollection<E>
- Parameters:
func
- mapping functionfilter
- filter predicate- Returns:
- created list
-
filterMap
Description copied from interface:ICollection
Create a new list by applying the specified filter first and then the mapping function to all elements selected. The returned list is of typeIList
, typicallyGapList
unless the original type isBigList
.- Specified by:
filterMap
in interfaceICollection<E>
- Parameters:
filter
- filter predicatefunc
- mapping function- Returns:
- created list
-
transformedList
Create a new list by applying the specified transforming operator to all elements.- Parameters:
op
- transforming operator- Returns:
- created list
-
transform
Change the list by applying the specified operator to all elements.- Parameters:
op
- transforming operator
-
filter
Create a new list by applying the specified filter to all elements. Only element which are allowed by the predicate are copied to the new list.- Specified by:
filter
in interfaceICollection<E>
- Parameters:
predicate
- predicate used for filtering- Returns:
- created list
-
retainIf
Retains all elements in the list which match the predicate.- Parameters:
predicate
- a predicate which returnstrue
for elements to be retained- Returns:
true
if the list was changed
-
removeIf
Removes all elements in the list which match the predicate.- Specified by:
removeIf
in interfaceCollection<E>
- Parameters:
predicate
- a predicate which returnstrue
for elements to be removed- Returns:
true
if the list was changed
-
extractIf
Removes and returns all elements in the list which match the predicate.- Parameters:
predicate
- predicate- Returns:
- elements which have been removed from the list
-
indexOf
-
indexOf
Returns the index of the first occurrence of the specified element in this list, starting the search at the specified position. If the element is not found, -1 is returned.- Parameters:
elem
- element to search forfromIndex
- start index for search- Returns:
- the index of the first occurrence of the specified element in this list that is greater than or equal to fromIndex, or -1 if this list does not contain the element
- See Also:
-
doIndexOf
Returns the index of the first occurrence of the specified element in this list, starting the search at the specified position. If the element is not found, -1 is returned. -
indexOfIf
Returns the index of the first element which matches the specified predicate in this list. If no such element is not found, -1 is returned.- Parameters:
predicate
- predicate used to search for the element- Returns:
- the index of the first element which matches the specified predicate, or -1 if not found
- See Also:
-
indexOfIf
Returns the index of the first element which matches the specified predicate in this list, starting the search at the specified position. If no such element is not found, -1 is returned.- Parameters:
predicate
- predicate used to search for the element- Returns:
- the index of the first element which matches the specified predicate, or -1 if not found
- See Also:
-
doIndexOfIf
Returns the index of the first element which matches the specified predicate in this list, starting the search at the specified position. If no such element is not found, -1 is returned. -
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<E>
- Overrides:
lastIndexOf
in classAbstractList<E>
-
lastIndexOf
Returns the index of the last occurrence of the specified element in this list, starting the search at the specified position. If the element is not found, -1 is returned.- Parameters:
elem
- element to search forfromIndex
- start index for search- Returns:
- the index of the last occurrence of the specified element in this list that is less than or equal to fromIndex, or -1 if this list does not contain the element
- See Also:
-
doLastIndexOf
Returns the index of the last occurrence of the specified element in this list, starting the search at the specified position. If the element is not found, -1 is returned. -
lastIndexOfIf
Returns the index of the last element which matches the specified predicate in this list. If no such element is not found, -1 is returned.- Parameters:
predicate
- predicate used to search for the element- Returns:
- the index of the last element which matches the specified predicate, or -1 if not found
- See Also:
-
lastIndexOfIf
Returns the index of the last occurrence of the specified element in this list, starting the search at the specified position. If the element is not found, -1 is returned.- Parameters:
predicate
- predicate used to search for the elementfromIndex
- start index for search- Returns:
- the index of the last occurrence of the specified element in this list that is less than or equal to fromIndex, or -1 if this list does not contain the element
- See Also:
-
doLastIndexOfIf
Returns the index of the last occurrence of the specified element in this list, starting the search at the specified position. If the element is not found, -1 is returned. -
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceList<E>
- Overrides:
contains
in classAbstractCollection<E>
-
containsIf
Determines whether the list contains a matching element.- Specified by:
containsIf
in interfaceICollection<E>
- Parameters:
predicate
- predicate used to search element- Returns:
- true if the list contains a matching element, false otherwise
-
addIfAbsent
Add elements to the end if it is not already contained in the list.- Parameters:
elem
- element to add- Returns:
- true if element has been added, false if not
-
containsAny
Returns true if any of the elements of the specified collection is contained in the list.- Parameters:
coll
- collection with elements to be contained- Returns:
- true if any element is contained, false otherwise
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceList<E>
- Overrides:
containsAll
in classAbstractCollection<E>
-
removeAll
Removes all equal elements.- Parameters:
elem
- element- Returns:
- removed equal elements (never null)
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceList<E>
- Overrides:
removeAll
in classAbstractCollection<E>
-
removeAll
- See Also:
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceList<E>
- Overrides:
retainAll
in classAbstractCollection<E>
-
retainAll
- See Also:
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] array) - Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
Returns an array containing the elements in this list.- Parameters:
clazz
- class for array elements- Returns:
- array containing the specified elements
-
toArray
Returns an array containing the specified elements in this list.- Parameters:
index
- index of first element to copylen
- number of elements to copy- Returns:
- array containing the specified elements
- See Also:
-
toArray
public <T> T[] toArray(T[] array, int index, int len) Returns an array containing the specified elements in this list.- Parameters:
array
- the array into which the elements of this list are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purposeindex
- index of first element to copylen
- number of elements to copy- Returns:
- array containing the specified elements
- See Also:
-
toArray
Returns an array containing the specified elements in this list.- Parameters:
clazz
- class for array elementsindex
- index of first element to copylen
- number of elements to copy- Returns:
- array containing the specified elements
-
doCreateArray
Create array.- Parameters:
clazz
- class for array elementslen
- array length- Returns:
- created array
-
doGetAll
protected <T> void doGetAll(T[] array, int index, int len) Helper method to fill the specified elements in an array.- Type Parameters:
T
- type of elements stored in the list- Parameters:
array
- array to store the list elementsindex
- index of first element to copylen
- number of elements to copy
-
doAddAll
Helper method for adding multiple elements to the list. This default implementation calls doAdd() for adding each element.- Parameters:
index
- index where element should be added (-1 is valid for adding at the end)list
- list with elements to add- Returns:
- true if elements have been added, false otherwise
-
iterator
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classAbstractList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classAbstractList<E>
-
descendingIterator
-
peek
SeeDeque.peek()
-
element
SeeDeque.element()
-
poll
SeeDeque.poll()
-
remove
SeeDeque.remove()
-
offer
SeeDeque.offer(E)
-
getFirst
Description copied from interface:ICollection
Returns the first element stored in the collection. If the collection is empty, aNoSuchElementException
is thrown.- Specified by:
getFirst
in interfaceICollection<E>
- Specified by:
getFirst
in interfaceList<E>
- Specified by:
getFirst
in interfaceSequencedCollection<E>
- Returns:
- first element stored in the collection
-
getFirstOrNull
Description copied from interface:ICollection
Returns the first element stored in the collection. If the collection is empty, null is returned.- Specified by:
getFirstOrNull
in interfaceICollection<E>
- Returns:
- first element stored in the collection or null if empty
-
getLast
SeeDeque.getLast()
-
getLastOrNull
Returns the last element stored in the list. If the list is empty, null is returned.- Returns:
- last element stored in the list or null if empty
-
addFirst
-
addLast
SeeDeque.addLast(E)
-
removeFirst
- Specified by:
removeFirst
in interfaceList<E>
- Specified by:
removeFirst
in interfaceSequencedCollection<E>
-
removeLast
- Specified by:
removeLast
in interfaceList<E>
- Specified by:
removeLast
in interfaceSequencedCollection<E>
-
offerFirst
-
offerLast
-
peekFirst
-
peekLast
SeeDeque.peekLast()
-
pollFirst
-
pollLast
SeeDeque.pollLast()
-
pop
SeeDeque.pop()
-
push
SeeDeque.push(E)
-
removeFirstOccurrence
-
removeLastOccurrence
-
transferCopy
public static <E> void transferCopy(IList<E> src, int srcIndex, int srcLen, IList<? super E> dst, int dstIndex, int dstLen) Copies elements from one list to another. Elements and size of source list do not change. The elements in the specified range in the destination list are removed and the elements specified to be copied are inserted. If source and destination list are identical, the method behaves likecopy(int, int, int)
.- Type Parameters:
E
- type of elements stored in the list- Parameters:
src
- source listsrcIndex
- index of first element in source listsrcLen
- number of elements to copydst
- destination listdstIndex
- index of first element in destination listdstLen
- number of elements to replace in destination list- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
transferMove
public static <E> void transferMove(IList<E> src, int srcIndex, int srcLen, IList<? super E> dst, int dstIndex, int dstLen) Moves elements from one list to another by setting it to null in the source list. Elements in the source range are set to null, but size of source list does not change. The elements in the specified range in the destination list are removed and the elements specified to be moved are inserted. If source and destination list are identical, the method behaves likemove(int, int, int)
.- Type Parameters:
E
- type of elements stored in the list- Parameters:
src
- source listsrcIndex
- index of first element in source listsrcLen
- number of elements to copydst
- destination listdstIndex
- index of first element in destination listdstLen
- number of elements to replace in destination list- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
transferRemove
public static <E> void transferRemove(IList<E> src, int srcIndex, int srcLen, IList<? super E> dst, int dstIndex, int dstLen) Moves elements from one list to another by removing it from the source list. So the size of source list will change. The elements in the specified range in the destination list are removed and the elements specified to be moved are inserted. If source and destination list are identical, the method behaves likedrag(int, int, int)
.- Type Parameters:
E
- type of elements stored in the list- Parameters:
src
- source listsrcIndex
- index of first element in source listsrcLen
- number of elements to copydst
- destination listdstIndex
- index of first element in destination listdstLen
- number of elements to replace in destination list- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
doTransfer
-
transferSwap
public static <E> void transferSwap(IList<E> src, int srcIndex, IList<E> dst, int dstIndex, int len) Swaps elements from two lists. The size of both source and destination list do not change. If source and destination list are identical, the method behaves likeswap(int, int, int)
.- Type Parameters:
E
- type of elements stored in the list- Parameters:
src
- first listsrcIndex
- index of first element in first listdst
- second listdstIndex
- index of first element in second listlen
- number of elements to swap- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
doTransferSwap
-
doCreate
Create list with specified capacity.- Parameters:
capacity
- initial capacity (use -1 for default capacity)- Returns:
- created list
-
doAssign
Assign this list the content of the that list. This is done by bitwise copying so the that list should not be used afterwards.- Parameters:
that
- list to copy content from
-
getAll
Returns specified range of elements from list.- Parameters:
index
- index of first element to retrievelen
- number of elements to retrieve- Returns:
- list containing the specified range of elements
-
extract
Removes specified range of elements from list and return them.- Parameters:
index
- index of first element to retrievelen
- number of elements to retrieve- Returns:
- list containing the specified range of elements
-
retain
public void retain(int index, int len) Retain specified range of elements from list, the other elements are removed.- Parameters:
index
- index of first element to retainlen
- number of elements to retain- Throws:
IndexOutOfBoundsException
- if the range is invalid
-
remove
public void remove(int index, int len) Remove specified range of elements from list.- Parameters:
index
- index of first element to removelen
- number of elements to remove- Throws:
IndexOutOfBoundsException
- if the range is invalid
-
doRemoveAll
protected void doRemoveAll(int index, int len) Remove specified range of elements from list.- Parameters:
index
- index of first element to removelen
- number of elements to remove
-
addAll
Adds all of the elements in the specified list into this list.- Parameters:
list
- collection containing elements to be added to this list- Returns:
- true if this list changed as a result of the call
- Throws:
NullPointerException
- if the specified list is null
-
addAll
Inserts all of the elements in the specified list into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices).- Parameters:
index
- index at which to insert the first element from the specified collectionlist
- list containing elements to be inserted into this list- Returns:
- true if this list changed as a result of the call
- Throws:
IndexOutOfBoundsException
- if the index is invalidNullPointerException
- if the specified collection is null
-
addAll
Adds all of the elements in the specified collection into this list. The new elements will appear in the list in the order that they are returned by the specified collection's iterator.- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractCollection<E>
- Parameters:
coll
- collection containing elements to be added to this list- Returns:
- true if this list changed as a result of the call
- Throws:
NullPointerException
- if the specified collection is null
-
addAll
Inserts all of the elements in the specified collection into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the list in the order that they are returned by the specified collection's iterator.- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractList<E>
- Parameters:
index
- index at which to insert the first element from the specified collectioncoll
- collection containing elements to be inserted into this list- Returns:
- true if this list changed as a result of the call
- Throws:
IndexOutOfBoundsException
- if the index is invalidNullPointerException
- if the specified collection is null
-
addArray
Adds all specified elements into this list.- Parameters:
elems
- elements to be added to this list- Returns:
- true if this list changed as a result of the call
-
addArray
-
addArray
-
addArray
Inserts the specified elements into this list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices).- Parameters:
index
- index at which to insert the first element from the specified collectionelems
- elements to be inserted into this list- Returns:
- true if this list changed as a result of the call
- Throws:
IndexOutOfBoundsException
- if the index is invalid
-
addMult
Adds element multiple time to list.- Parameters:
elem
- element to be added to this list- Returns:
- true if this list changed as a result of the call
-
addMult
Inserts element multiple time to list, starting at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices).- Parameters:
index
- index at which to insert the first element from the specified collectionelem
- element to be inserted into this list- Returns:
- true if this list changed as a result of the call
- Throws:
IndexOutOfBoundsException
- if the index is invalid
-
setAll
Sets the specified elements.- Parameters:
index
- index of first element to setlist
- list with elements to set
-
setAll
Sets the specified elements.- Parameters:
index
- index of first element to setcoll
- collection with elements to set- Throws:
IndexOutOfBoundsException
- if the range is invalid
-
setArray
Sets the specified elements.- Parameters:
index
- index of first element to setelems
- array with elements to set- Throws:
IndexOutOfBoundsException
- if the range is invalid
-
setArray
-
setMult
Sets the element multiple times.- Parameters:
index
- index of first element to setelem
- element to set
-
putAll
Set or add the specified elements.- Parameters:
index
- index of first element to set or addlist
- list with elements to set or add
-
putAll
Set or add the specified elements. If the index is smaller than the size of the list, the existing element is replaced. If the index equals the size of the list, the element is added.- Parameters:
index
- index of first element to set or addcoll
- collection with elements to set or add
-
doPutAll
-
putArray
Set or add the specified elements. If the index is smaller than the size of the list, the existing element is replaced. If the index equals the size of the list, the element is added.- Parameters:
index
- index of first element to set or addelems
- array with elements to set or add
-
putMult
Set or add the specified element multiple times. If the index is smaller than the size of the list, the existing element is replaced. If the index equals the size of the list, the element is added.- Parameters:
index
- index of first element to set or addlen
- element to set or add
-
initAll
Initializes the list so it will afterwards only contain the elements of the collection. The list will grow or shrink as needed.- Parameters:
list
- list with elements- Throws:
IndexOutOfBoundsException
- if the length is invalid
-
doInitAll
-
initAll
Initializes the list so it will afterwards only contain the elements of the collection. The list will grow or shrink as needed.- Parameters:
coll
- collection with elements- Throws:
IndexOutOfBoundsException
- if the length is invalid
-
asIListable
Return correct IListable for passed collection. -
initArray
Initializes the list so it will afterwards only contain the elements of the array. The list will grow or shrink as needed.- Parameters:
elems
- array with elements- Throws:
IndexOutOfBoundsException
- if the length is invalid
-
initMult
Initializes the list so it will afterwards have a size oflen
and contain only the elementelem
. The list will grow or shrink as needed.- Parameters:
len
- length of listelem
- element which the list will contain- Throws:
IndexOutOfBoundsException
- if the length is invalid
-
replaceAll
Replaces the specified range with new elements. This method is very powerful as it offers the functionality of many other methods which are therefore only offered for convenience:
- addAll(index, list): replaceAll(index, 0, list)
- setAll(index, list): replaceAll(index, list.size(), list)
- putAll(index, list): replaceAll(index, -1, list)
- initAll(list) : replaceAll(0, this.size(), list)
- remove(index, list): replaceAll(index, list.size(), null)- Parameters:
index
- index of first element to replace, use -1 for the position after the last element (this.size())len
- number of elements to replace, use -1 for getting behavior of putAll()coll
- collection with elements which replace the old elements, use null if elements should only be removed- Throws:
IndexOutOfBoundsException
- if the range is invalid
-
replaceArray
Replaces the specified range with new elements. This method is very powerful as it offers the functionality of many other methods which are therefore only offered for convenience:
- addAll(index, list): replaceAll(index, 0, list)
- setAll(index, list): replaceAll(index, list.size(), list)
- putAll(index, list): replaceAll(index, -1, list)
- initAll(list) : replaceAll(0, this.size(), list)
- remove(index, list): replaceAll(index, list.size(), null)- Parameters:
index
- index of first element to replace, use -1 for the position after the last element (this.size())len
- number of elements to replace, use -1 for getting behavior of putAll()elems
- array with elements which replace the old elements, use null if elements should only be removed- Throws:
IndexOutOfBoundsException
- if the range is invalid
-
replaceMult
Replaces the specified range with new elements. This method is very powerful as it offers the functionality of many other methods which are therefore only offered for convenience:
- addAll(index, list): replaceAll(index, 0, list)
- setAll(index, list): replaceAll(index, list.size(), list)
- putAll(index, list): replaceAll(index, -1, list)
- initAll(list) : replaceAll(0, this.size(), list)
- remove(index, list): replaceAll(index, list.size(), null)- Parameters:
index
- index of first element to replace, use -1 for the position after the last element (this.size())len
- number of elements to replace, use -1 for getting behavior of putAll()numElems
- number of time element has to be addedelem
- element to add- Throws:
IndexOutOfBoundsException
- if the range is invalid
-
replaceAll
Replaces the specified range with new elements. This method is very powerful as it offers the functionality of many other methods which are therefore only offered for convenience:
- addAll(index, list): replaceAll(index, 0, list)
- setAll(index, list): replaceAll(index, list.size(), list)
- putAll(index, list): replaceAll(index, -1, list)
- initAll(list) : replaceAll(0, this.size(), list)
- remove(index, list): replaceAll(index, list.size(), null)- Parameters:
index
- index of first element to replace, use -1 for the position after the last element (this.size())len
- number of elements to replace, use -1 for getting behavior of putAll()list
- list with elements which replace the old elements, use null if elements should only be removed- Throws:
IndexOutOfBoundsException
- if the range is invalid
-
replace
-
doReplace
-
fill
Fill list.- Parameters:
elem
- element used for filling
-
copy
public void copy(int srcIndex, int dstIndex, int len) Copy specified elements. Source and destination ranges may overlap. The size of the list does not change.- Parameters:
srcIndex
- index of first source element to copydstIndex
- index of first destination element to copylen
- number of elements to copy- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
move
public void move(int srcIndex, int dstIndex, int len) Move specified elements. Source and destination ranges may overlap. The elements which are moved away are set to null, so the size of the list does not change.- Parameters:
srcIndex
- index of first source element to movedstIndex
- index of first destination element to movelen
- number of elements to move- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
drag
public void drag(int srcIndex, int dstIndex, int len) Drag specified elements. Source and destination ranges may overlap. The size of the list does not change and it contains the same elements as before, but in changed order.- Parameters:
srcIndex
- index of first source element to movedstIndex
- index of first destination element to movelen
- number of elements to move- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
swap
public void swap(int index1, int index2, int len) Swap the specified elements in the list.- Parameters:
index1
- index of first element in first range to swapindex2
- index of first element in second range to swaplen
- number of elements to swap- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
reverse
public void reverse()Reverses the order of all elements in the specified list. -
reverse
public void reverse(int index, int len) Reverses the order of the specified elements in the list.- Parameters:
index
- index of first element to reverselen
- number of elements to reverse- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
rotate
public void rotate(int distance) Rotate specified elements in the list. The distance argument can be positive or negative: If it is positive, the elements are moved towards the end, if negative, the elements are moved toward the beginning, if distance is 0, the list is not changed.- Parameters:
distance
- distance to move the elements
-
rotate
public void rotate(int index, int len, int distance) Rotate specified elements in the list. The distance argument can be positive or negative: If it is positive, the elements are moved towards the end, if negative, the elements are moved toward the beginning, if distance is 0, the list is not changed.- Parameters:
index
- index of first element to rotatelen
- number of elements to rotatedistance
- distance to move the elements- Throws:
IndexOutOfBoundsException
- if the ranges are invalid
-
doRotate
protected void doRotate(int index, int len, int distance) Internal method to rotate specified elements in the list. The distance argument can be positive or negative: If it is positive, the elements are moved towards the end, if negative, the elements are moved toward the beginning, if distance is 0, the list is not changed.- Parameters:
index
- index of first element to rotatelen
- number of elements to rotatedistance
- distance to move the elements
-
sort
Sort elements in the list using the specified comparator. -
sort
Sort specified elements in the list using the specified comparator.- Parameters:
index
- index of first element to sortlen
- number of elements to sortcomparator
- comparator to use for sorting (null means the elements natural ordering should be used)- Throws:
IndexOutOfBoundsException
- if the range is invalid- See Also:
-
binarySearch
Searches the specified range for an object using the binary* search algorithm.Note that the method is defined to work with an arbitrary type <K>. This allows to search directly for a key field in the object without the need to construct an object containing the key:
persons.binarySearch("john", new SearchByName()); class SearchByName implements Comparator<Object> { public int compare(Object o1, Object o2) { String s1 = (o1 instanceof String) ? (String) o1 : ((Name) o1).getName(); String s2 = (o2 instanceof String) ? (String) o2 : ((Name) o2).getName(); return s1.compareTo(s2); } }
- Parameters:
key
- the value to be searched forcomparator
- the comparator by which the list is ordered. A null value indicates that the elements' natural ordering should be used.- Returns:
- index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
- See Also:
-
binarySearch
Searches the specified range for an object using the binary search algorithm.Note that the method is defined to work with an arbitrary type <K>. This allows to search directly for a key field in the object without the need to construct an object containing the key:
persons.binarySearch("john", new SearchByName()); class SearchByName implements Comparator<Object> { public int compare(Object o1, Object o2) { String s1 = (o1 instanceof String) ? (String) o1 : ((Name) o1).getName(); String s2 = (o2 instanceof String) ? (String) o2 : ((Name) o2).getName(); return s1.compareTo(s2); } }
/- Parameters:
index
- index of first element to searchlen
- number of elements to searchkey
- the value to be searched forcomparator
- the comparator by which the list is ordered. A null value indicates that the elements' natural ordering should be used.- Returns:
- index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.
- Throws:
IndexOutOfBoundsException
- if the range is invalid- See Also:
-
checkIndex
protected void checkIndex(int index) Check that specified index is valid for getting/setting elements.- Parameters:
index
- index to check- Throws:
IndexOutOfBoundsException
- if index is invalid
-
checkIndexAdd
protected void checkIndexAdd(int index) Check that specified index is valid for adding elements.- Parameters:
index
- index to check- Throws:
IndexOutOfBoundsException
- if index is invalid
-
checkRange
protected void checkRange(int index, int len) Check that specified range is valid.- Parameters:
index
- start index of range to checklen
- number of elements in range to check- Throws:
IndexOutOfBoundsException
- if index is invalid
-
checkLength
protected void checkLength(int len) Check that specified length is valid (>= 0).- Parameters:
len
- length to check- Throws:
IndexOutOfBoundsException
- if length is invalid
-
checkLengths
protected void checkLengths(int len1, int len2) Check that both specified lengths are valid (>= 0) and equal.- Parameters:
len1
- length to checklen2
- length to check- Throws:
IndexOutOfBoundsException
- if lengths are invalid
-
checkNonNull
Check that object is not null.- Parameters:
obj
- object to check- Throws:
NullPointerException
- if object is null
-