Package dev.prozilla.pine.common.util
Class DeferredList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<E>
dev.prozilla.pine.common.util.DeferredList<E>
- Type Parameters:
E- The type of elements in this list
- All Implemented Interfaces:
Destructible,Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess,SequencedCollection<E>
Implementation of an array list which defers modifications of elements until the current iteration is complete, to prevent concurrent modification exceptions.
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanbooleanaddAll(int index, Collection<? extends E> collection) booleanaddAll(Collection<? extends E> collection) voidclear()voiddestroy()Removes all elements from this list.voidMarks the end of an ongoing iteration of this list.voidReturns a snapshot of what this list will look like after the current iterations are done and the deferred operations are executed.booleanChecks if this list is being iterated.booleanChecks if the snapshot of this list is empty.iterator()remove(int index) booleanbooleanremoveAll(Collection<?> collection) booleanintReturns the size of the snapshot of this list.voidsort(Comparator<? super E> c) voidMarks the start of a new iteration of this list.Methods inherited from class java.util.ArrayList
addFirst, addLast, clone, contains, ensureCapacity, equals, get, getFirst, getLast, hashCode, indexOf, isEmpty, lastIndexOf, listIterator, listIterator, removeFirst, removeLast, removeRange, replaceAll, retainAll, set, size, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, stream, toArrayMethods inherited from interface java.util.List
containsAll, reversed
-
Constructor Details
-
DeferredList
public DeferredList()
-
-
Method Details
-
add
-
addAll
-
addAll
public boolean addAll(int index, Collection<? extends E> collection) throws ConcurrentModificationException -
add
-
remove
-
removeAll
-
removeIf
- Specified by:
removeIfin interfaceCollection<E>- Overrides:
removeIfin classArrayList<E>- Throws:
ConcurrentModificationException
-
remove
-
clear
public void clear() -
snapshotSize
public int snapshotSize()Returns the size of the snapshot of this list.- Returns:
- The size of the snapshot.
-
isSnapshotEmpty
public boolean isSnapshotEmpty()Checks if the snapshot of this list is empty.- Returns:
trueif the snapshot is empty.
-
getSnapshot
Returns a snapshot of what this list will look like after the current iterations are done and the deferred operations are executed.If there are no current iterations, this will simply return
this.- Returns:
- A snapshot of this list after executing the deferred operations.
-
iterator
-
forEach
-
sort
-
startIteration
public void startIteration()Marks the start of a new iteration of this list. -
endIteration
public void endIteration()Marks the end of an ongoing iteration of this list. -
isIterating
public boolean isIterating()Checks if this list is being iterated.- Returns:
trueif this list is being iterated.
-
destroy
public void destroy()Removes all elements from this list.- Specified by:
destroyin interfaceDestructible
-