Class ElementAwareArrayList<T>
java.lang.Object
ai.timefold.solver.core.impl.util.ElementAwareArrayList<T>
- Type Parameters:
T-
ArrayList-backed list which allows for a cheap removal of an element,
while still providing fast iteration and random access.
The order of iteration is guaranteed to be the insertion order.
It uses internal state of the entry to track insertion position of the element.
When an element is removed, the underlying collection isn't actually touched;
therefore, the insertion position of later elements isn't changed.
This position is called a gap.
Gaps are removed (the list is compacted) when forEach(Consumer) or asList() is called.
This keeps the overhead low while giving us all benefits of ArrayList,
such as memory efficiency, random access, and fast iteration.
This class is very thread-unsafe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppends the specified element to the end of this collection.asList()Returns a standardListview of this collection.voidPerforms the given action for each element of the collection until all elements have been processed.get(int index) booleanisEmpty()iterator()voidremove(ElementAwareArrayList.Entry<T> entry) Removes the first occurrence of the specified element from this collection, if present.intsize()
-
Constructor Details
-
ElementAwareArrayList
public ElementAwareArrayList()
-
-
Method Details
-
add
Appends the specified element to the end of this collection.- Parameters:
element- element to be appended to this collection
-
get
-
remove
Removes the first occurrence of the specified element from this collection, if present.- Parameters:
entry- entry to be removed from this collection- Throws:
IllegalStateException- if the element wasn't found in this collection
-
isEmpty
public boolean isEmpty() -
size
public int size() -
forEach
Performs the given action for each element of the collection until all elements have been processed.- Parameters:
elementConsumer- the action to be performed for each element; mustn't modify the collection and mustn't throw exceptions, as that'd leave the collection in an inconsistent state
-
iterator
-
asList
Returns a standardListview of this collection. Users mustn't modify the returned list, as that'd also change the underlying data structure.- Returns:
- a standard list view of this element-aware list
-