Class LinkedList
-
- All Implemented Interfaces:
-
kotlin.Cloneable,kotlin.collections.Collection,kotlin.collections.Iterable,kotlin.collections.List,kotlin.collections.MutableCollection,kotlin.collections.MutableIterable,kotlin.collections.MutableList
public final class LinkedList<T extends Object> implements List<T>, Cloneable
Implementation of the MutableList interface for PolyUI.
This is a doubly-linked list, with special "fast" methods:
these methods are all designed to avoid the allocation of an Iterator object, as otherwise PolyUI would create a lot of garbage.
this collection, unlike most of the collections in the Java Collections Framework, does not make any effort to check against concurrent modification. this allows you to do some "quirky" things, such as iterating over the list and removing elements at the same time.
Being a linked list, the random get and put operations are not the best. However, this operation is rare in PolyUI, so it's okay to use this.
- Since:
1.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classLinkedList.Nodepublic final classLinkedList.LLIteratoriterator for LinkedList.
-
Field Summary
Fields Modifier and Type Field Description private final LinkedList.Node<T>startprivate final LinkedList.Node<T>endprivate final Integersize
-
Constructor Summary
Constructors Constructor Description LinkedList(Collection<T> elements)LinkedList(T elements)LinkedList()
-
Method Summary
Modifier and Type Method Description final LinkedList.Node<T>getStart()final LinkedList.Node<T>getEnd()IntegergetSize()BooleanaddAll(Integer index, Collection<T> elements)BooleanaddAll(Collection<T> elements)final UnitaddAll(Array<out T> elements)Unitclear()final Unitclear(Boolean unlink)Unitadd(Integer index, T element)Booleanadd(T element)BooleanisEmpty()ListIterator<T>iterator()ListIterator<T>listIterator()ListIterator<T>listIterator(Integer index)TremoveAt(Integer index)List<T>subList(Integer fromIndex, Integer toIndex)IntegerlastIndexOf(T element)BooleanretainAll(Collection<T> elements)BooleanremoveAll(Collection<T> elements)Booleanremove(T element)BooleancontainsAll(Collection<T> elements)Tget(Integer index)IntegerindexOf(T element)Tset(Integer index, T element)Booleancontains(T element)final UnitfastEach(Function1<T, Unit> action)final UnitfastEachIndexed(Function2<Integer, T, Unit> action)final UnitfastEachReversed(Function1<T, Unit> action)final BooleanfastRemoveIf(Function1<T, Boolean> predicate)final BooleanfastRemoveIfIndexed(Function2<Integer, T, Boolean> predicate)final BooleanfastRemoveIfReversed(Function1<T, Boolean> predicate)final Booleanclearing(Function1<T, Unit> function)final TaddOrReplace(T element)Adds or replaces an element in the list. final Unitcut(Integer from, Integer to)Sublist this list in the range of from to to, discarding any elements outside of that range. final Unit_remove(LinkedList.Node<T> node)Remove a node from a LinkedList. final BooleanallAre(Function1<T, Boolean> predicate)Returns trueif all elements match the given predicate.final Tfirst()final Tfirst(Function1<T, Boolean> predicate)final TfirstOrNull()final Tlast()final TlastOrNull()Booleanequals(Object other)IntegerhashCode()final LinkedList<T>copy()LinkedList<T>clone()StringtoString()-
Methods inherited from class kotlin.collections.Iterable
forEach -
Methods inherited from class kotlin.collections.Collection
parallelStream, stream, toArray -
Methods inherited from class kotlin.collections.MutableCollection
removeIf -
Methods inherited from class kotlin.collections.MutableList
replaceAll, sort -
Methods inherited from class kotlin.collections.List
spliterator -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
LinkedList
LinkedList(Collection<T> elements)
-
LinkedList
LinkedList(T elements)
-
LinkedList
LinkedList()
-
-
Method Detail
-
getStart
final LinkedList.Node<T> getStart()
-
getEnd
final LinkedList.Node<T> getEnd()
-
addAll
Boolean addAll(Integer index, Collection<T> elements)
-
addAll
Boolean addAll(Collection<T> elements)
-
iterator
@Deprecated(message = "This list is designed around not using this method.", replaceWith = @ReplaceWith(imports = {}, expression = "fastEach")) ListIterator<T> iterator()
-
listIterator
@Deprecated(message = "This list is designed around not using this method.", replaceWith = @ReplaceWith(imports = {}, expression = "fastEach")) ListIterator<T> listIterator()
-
listIterator
@Deprecated(message = "This list is designed around not using this method.", replaceWith = @ReplaceWith(imports = {}, expression = "fastEach")) ListIterator<T> listIterator(Integer index)
-
lastIndexOf
Integer lastIndexOf(T element)
-
retainAll
Boolean retainAll(Collection<T> elements)
-
removeAll
Boolean removeAll(Collection<T> elements)
-
containsAll
Boolean containsAll(Collection<T> elements)
-
fastEachIndexed
final Unit fastEachIndexed(Function2<Integer, T, Unit> action)
-
fastEachReversed
final Unit fastEachReversed(Function1<T, Unit> action)
-
fastRemoveIf
final Boolean fastRemoveIf(Function1<T, Boolean> predicate)
-
fastRemoveIfIndexed
final Boolean fastRemoveIfIndexed(Function2<Integer, T, Boolean> predicate)
-
fastRemoveIfReversed
final Boolean fastRemoveIfReversed(Function1<T, Boolean> predicate)
-
addOrReplace
final T addOrReplace(T element)
Adds or replaces an element in the list. If the element is already in the list (using equals), it will be replaced, otherwise it will be added.
If it is replaced, the old element will be returned, otherwise
nullwill be returned.- Parameters:
element- the element to add or replace.
-
_remove
@ApiStatus.Internal() final Unit _remove(LinkedList.Node<T> node)
Remove a node from a LinkedList. Note that if the node does not belong in this list, the behaviour is undefined.
-
allAre
final Boolean allAre(Function1<T, Boolean> predicate)
Returns
trueif all elements match the given predicate.Note this function will return
trueif the list is empty, according to the principle of Vacuous truth, and the fact that there are no elements that don't match the given predicate.
-
firstOrNull
final T firstOrNull()
-
lastOrNull
final T lastOrNull()
-
copy
final LinkedList<T> copy()
-
clone
LinkedList<T> clone()
-
-
-
-