Package qilin.util
Interface Chain<E>
- Type Parameters:
E
- element type
- All Superinterfaces:
Collection<E>
,Iterable<E>
,Serializable
Augmented data type guaranteeing O(1) insertion and removal from a set of ordered, unique
elements.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given object at the beginning of the Chain.void
Adds the given object at the end of the Chain.boolean
Returns true if objectsomeObject
follows objectsomeReferenceObject
in the Chain, i.e.Gets all elements in the chain.getFirst()
Returns the first object in this Chain.getLast()
Returns the last object in this Chain.long
Returns the number of times this chain has been modified.Returns the object immediately precedingpoint
.Returns the object immediately followingpoint
.void
insertAfter
(E toInsert, E point) InsertstoInsert
in the Chain afterpoint
.void
insertAfter
(Collection<? extends E> toInsert, E point) InsertstoInsert
in the Chain afterpoint
.void
insertAfter
(List<E> toInsert, E point) InsertstoInsert
in the Chain afterpoint
.void
insertAfter
(Chain<E> toInsert, E point) InsertstoInsert
in the Chain afterpoint
.void
insertBefore
(E toInsert, E point) InsertstoInsert
in the Chain beforepoint
.void
insertBefore
(Collection<? extends E> toInsert, E point) InsertstoInsert
in the Chain beforepoint
.void
insertBefore
(List<E> toInsert, E point) InsertstoInsert
in the Chain beforepoint
.void
insertBefore
(Chain<E> toInsert, E point) InsertstoInsert
in the Chain beforepoint
.iterator()
Returns an iterator over this Chain.Returns an iterator over this Chain, starting at the given object.Returns an iterator over this Chain, starting at head and reaching tail (inclusive).boolean
Removes the given object from this Chain.void
Removes the first object contained in this Chain.void
Removes the last object contained in this Chain.int
size()
Returns the size of this Chain.Returns an iterator over a copy of this chain.void
Replacesout
in the Chain byin
.Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArray
-
Method Details
-
insertBefore
InsertstoInsert
in the Chain beforepoint
. -
insertAfter
InsertstoInsert
in the Chain afterpoint
. -
insertBefore
InsertstoInsert
in the Chain beforepoint
. -
insertAfter
InsertstoInsert
in the Chain afterpoint
. -
insertBefore
InsertstoInsert
in the Chain beforepoint
. -
insertAfter
InsertstoInsert
in the Chain afterpoint
. -
insertBefore
InsertstoInsert
in the Chain beforepoint
. -
insertAfter
InsertstoInsert
in the Chain afterpoint
. -
swapWith
Replacesout
in the Chain byin
. -
remove
Removes the given object from this Chain. Parameter has to be of typeObject
to be compatible with theCollection
interface.- Specified by:
remove
in interfaceCollection<E>
-
addFirst
Adds the given object at the beginning of the Chain. -
addLast
Adds the given object at the end of the Chain. -
removeFirst
void removeFirst()Removes the first object contained in this Chain. -
removeLast
void removeLast()Removes the last object contained in this Chain. -
follows
Returns true if objectsomeObject
follows objectsomeReferenceObject
in the Chain, i.e. someReferenceObject comes first and then someObject. -
getFirst
E getFirst()Returns the first object in this Chain. -
getLast
E getLast()Returns the last object in this Chain. -
getSuccOf
Returns the object immediately followingpoint
. -
getPredOf
Returns the object immediately precedingpoint
. -
snapshotIterator
Returns an iterator over a copy of this chain. This avoids ConcurrentModificationExceptions from being thrown if the underlying Chain is modified during iteration. Do not use this to remove elements which have not yet been iterated over! -
iterator
Returns an iterator over this Chain. -
iterator
Returns an iterator over this Chain, starting at the given object. -
iterator
Returns an iterator over this Chain, starting at head and reaching tail (inclusive). -
size
int size()Returns the size of this Chain.- Specified by:
size
in interfaceCollection<E>
-
getModificationCount
long getModificationCount()Returns the number of times this chain has been modified. -
getElementsUnsorted
Collection<E> getElementsUnsorted()Gets all elements in the chain. There is no guarantee on sorting. On the other hand, the collection returned by this method is thread-safe. You can iterate over it even in the case of concurrent modifications to the underlying chain.- Returns:
- All elements in the chain in an unsorted collection
-