Package org.drools.core.util
Class LinkedList<T extends DoubleLinkedEntry<T>>
java.lang.Object
org.drools.core.util.LinkedList<T>
- All Implemented Interfaces:
Externalizable,Serializable
- Direct Known Subclasses:
EqualityKey,SegmentMemory,TupleList
This is a simple linked implementation. Each node must implement LinkedListNode
so that it references
the node before and after it. This way a node can be removed without having to scan the list to find it. This class
does not provide an Iterator implementation as its designed for efficiency and not genericity. There are a number of
ways to iterate the list.
Simple iterator:
for ( LinkedListNode node = list.getFirst(); node != null; node = node.remove() ) {
}
Iterator that pops the first entry:
for ( LinkedListNode node = list.removeFirst(); node != null; node = list.removeFirst() ) {
}
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classLinkedList.JavaUtilIterator<T extends DoubleLinkedEntry<T>>static classstatic classLinkedList.LinkedListIterator<T extends DoubleLinkedEntry<T>>Returns a list iteratorstatic class -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an emptyLinkedListLinkedList(T node) LinkedList(T firstNode, T lastNode, int size) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd aLinkedListNodeto the list.<I> voidaddAllToCollection(Collection<I> c) voidvoidAdd aLinkedListNodeto the end of the list.voidclear()Iterates the list removing all the nodes until there are no more nodes to remove.booleanprotected voidcopyStateInto(LinkedList<T> other) booleanget(int i) final TgetFirst()Return the first node in the listfinal TgetLast()Return the last node in the listinthashCode()voidinsertAfter(T existingNode, T newNode) final booleanisEmpty()voidvoidRemoves aLinkedListNodefrom the list.voidRemove the first node from the list.Remove the last node from the list.final intsize()void
-
Field Details
-
fastIterator
-
-
Constructor Details
-
LinkedList
public LinkedList()Construct an emptyLinkedList -
LinkedList
-
LinkedList
-
-
Method Details
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
add
Add aLinkedListNodeto the list. If theLinkedListis empty then the first and last nodes are set to the added node.- Parameters:
node- TheLinkedListNodeto be added
-
addLast
Add aLinkedListNodeto the end of the list. If theLinkedListis empty then the first and last nodes are set to the added node.- Parameters:
node- TheLinkedListNodeto be added
-
addFirst
-
remove
Removes aLinkedListNodefrom the list. This works by attach the previous reference to the child reference. When the node to be removed is the first node it callsremoveFirst(). When the node to be removed is the last node it callsremoveLast().- Parameters:
node- TheLinkedListNodeto be removed.
-
removeFirst
Remove the first node from the list. The next node then becomes the first node. If this is the last node then both first and last node references are set to null.- Returns:
- The first
LinkedListNode.
-
removeLast
Remove the last node from the list. The previous node then becomes the last node. If this is the last node then both first and last node references are set to null.- Returns:
- The first
LinkedListNode.
-
insertAfter
-
removeAdd
-
contains
-
getFirst
Return the first node in the list- Returns:
- The first
LinkedListNode.
-
getLast
Return the last node in the list- Returns:
- The last
LinkedListNode.
-
get
-
get
-
isEmpty
public final boolean isEmpty()- Returns:
- boolean value indicating the empty status of the list
-
clear
public void clear()Iterates the list removing all the nodes until there are no more nodes to remove. -
size
public final int size()- Returns:
- return size of the list as an int
-
hashCode
public int hashCode() -
equals
-
fastIterator
-
javaUtilIterator
-
copyStateInto
-
addAllToCollection
-