Package org.drools.core.util
Class LinkedList<T extends LinkedListNode<T>>
- java.lang.Object
-
- org.drools.core.util.LinkedList<T>
-
- All Implemented Interfaces:
Externalizable,Serializable
- Direct Known Subclasses:
EqualityKey,SegmentMemory
public class LinkedList<T extends LinkedListNode<T>> extends Object implements Externalizable
This is a simple linked linked implementation. Each node must implement LinkedListNodeso 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLinkedList.JavaUtilIterator<T extends LinkedListNode<T>>static classLinkedList.LinkedListFastIteratorstatic classLinkedList.LinkedListIterator<T extends LinkedListNode<T>>Returns a list iterator
-
Field Summary
Fields Modifier and Type Field Description static FastIteratorfastIterator
-
Constructor Summary
Constructors Constructor Description LinkedList()Construct an emptyLinkedListLinkedList(T node)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T node)Add aLinkedListNodeto the list.voidaddFirst(T node)voidaddLast(T node)Add aLinkedListNodeto the end of the list.voidclear()Iterates the list removing all the nodes until there are no more nodes to remove.booleancontains(T node)booleanequals(Object object)FastIteratorfastIterator()Tget(int i)TgetFirst()Return the first node in the listTgetLast()Return the last node in the listinthashCode()voidinsertAfter(T existingNode, T newNode)booleanisEmpty()FastIteratoriterator()Iterator<T>javaUtilIterator()voidreadExternal(ObjectInput in)voidremove(T node)Removes aLinkedListNodefrom the list.TremoveFirst()Remove the first node from the list.TremoveLast()Remove the last node from the list.intsize()voidwriteExternal(ObjectOutput out)
-
-
-
Field Detail
-
fastIterator
public static final FastIterator fastIterator
-
-
Constructor Detail
-
LinkedList
public LinkedList()
Construct an emptyLinkedList
-
LinkedList
public LinkedList(T node)
-
-
Method Detail
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
add
public void add(T node)
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
public void addLast(T node)
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
public void addFirst(T node)
-
remove
public void remove(T node)
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.
-
contains
public boolean contains(T node)
-
getFirst
public final T getFirst()
Return the first node in the list- Returns:
- The first
LinkedListNode.
-
getLast
public final T getLast()
Return the last node in the list- Returns:
- The last
LinkedListNode.
-
removeFirst
public T 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
public T 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.
-
get
public T get(int i)
-
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
-
iterator
public FastIterator iterator()
-
fastIterator
public FastIterator fastIterator()
-
-