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 TypeMethodDescriptionvoidAdds the given object at the beginning of the Chain.voidAdds the given object at the end of the Chain.booleanReturns true if objectsomeObjectfollows objectsomeReferenceObjectin the Chain, i.e. someReferenceObject comes first and then someObject.Gets all elements in the chain.getFirst()Returns the first object in this Chain.getLast()Returns the last object in this Chain.longReturns the number of times this chain has been modified.Returns the object immediately precedingpoint.Returns the object immediately followingpoint.voidinsertAfter(E toInsert, E point) InsertstoInsertin the Chain afterpoint.voidinsertAfter(Collection<? extends E> toInsert, E point) InsertstoInsertin the Chain afterpoint.voidinsertAfter(List<E> toInsert, E point) InsertstoInsertin the Chain afterpoint.voidinsertAfter(Chain<E> toInsert, E point) InsertstoInsertin the Chain afterpoint.voidinsertBefore(E toInsert, E point) InsertstoInsertin the Chain beforepoint.voidinsertBefore(Collection<? extends E> toInsert, E point) InsertstoInsertin the Chain beforepoint.voidinsertBefore(List<E> toInsert, E point) InsertstoInsertin the Chain beforepoint.voidinsertBefore(Chain<E> toInsert, E point) InsertstoInsertin 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).booleanRemoves the given object from this Chain.voidRemoves the first object contained in this Chain.voidRemoves the last object contained in this Chain.intsize()Returns the size of this Chain.Returns an iterator over a copy of this chain.voidReplacesoutin 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
InsertstoInsertin the Chain beforepoint. -
insertAfter
InsertstoInsertin the Chain afterpoint. -
insertBefore
InsertstoInsertin the Chain beforepoint. -
insertAfter
InsertstoInsertin the Chain afterpoint. -
insertBefore
InsertstoInsertin the Chain beforepoint. -
insertAfter
InsertstoInsertin the Chain afterpoint. -
insertBefore
InsertstoInsertin the Chain beforepoint. -
insertAfter
InsertstoInsertin the Chain afterpoint. -
swapWith
Replacesoutin the Chain byin. -
remove
Removes the given object from this Chain. Parameter has to be of typeObjectto be compatible with theCollectioninterface.- Specified by:
removein 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 objectsomeObjectfollows objectsomeReferenceObjectin 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:
sizein 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
-