Drools :: Core 6.0.0.Beta5

org.drools.core.util
Class LinkedList<T extends LinkedListNode<T>>

java.lang.Object
  extended by org.drools.core.util.LinkedList<T>
All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
EqualityKey, JTMSBeliefSet, SegmentMemory, SimpleBeliefSet

public class LinkedList<T extends LinkedListNode<T>>
extends Object
implements Externalizable

This is a simple linked 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:
Serialized Form

Nested Class Summary
static class LinkedList.JavaUtilIterator<T extends LinkedListNode<T>>
           
static class LinkedList.LinkedListFastIterator
           
static class LinkedList.LinkedListIterator<T extends LinkedListNode<T>>
          Returns a list iterator
 
Field Summary
static FastIterator fastIterator
           
 
Constructor Summary
LinkedList()
          Construct an empty LinkedList
LinkedList(T node)
           
 
Method Summary
 void add(T node)
          Add a LinkedListNode to the list.
 void addLast(T node)
          Add a LinkedListNode to the end of the list.
 void clear()
          Iterates the list removing all the nodes until there are no more nodes to remove.
 boolean equals(Object object)
           
 FastIterator fastIterator()
           
 T get(int i)
           
 T getFirst()
          Return the first node in the list
 T getLast()
          Return the last node in the list
 int hashCode()
           
 void insertAfter(T existingNode, T newNode)
           
 boolean isEmpty()
           
 FastIterator iterator()
           
 Iterator<T> javaUtilIterator()
           
 void readExternal(ObjectInput in)
           
 void remove(T node)
          Removes a LinkedListNode from the list.
 T removeFirst()
          Remove the first node from the list.
 T removeLast()
          Remove the last node from the list.
 int size()
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fastIterator

public static FastIterator fastIterator
Constructor Detail

LinkedList

public LinkedList()
Construct an empty LinkedList


LinkedList

public LinkedList(T node)
Method Detail

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Specified by:
readExternal in interface Externalizable
Throws:
IOException
ClassNotFoundException

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

add

public void add(T node)
Add a LinkedListNode to the list. If the LinkedList is empty then the first and last nodes are set to the added node.

Parameters:
node - The LinkedListNode to be added

addLast

public void addLast(T node)
Add a LinkedListNode to the end of the list. If the LinkedList is empty then the first and last nodes are set to the added node.

Parameters:
node - The LinkedListNode to be added

remove

public void remove(T node)
Removes a LinkedListNode from the list. This works by attach the previous reference to the child reference. When the node to be removed is the first node it calls removeFirst(). When the node to be removed is the last node it calls removeLast().

Parameters:
node - The LinkedListNode to be removed.

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.

insertAfter

public void insertAfter(T existingNode,
                        T newNode)

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object object)
Overrides:
equals in class Object

iterator

public FastIterator iterator()

fastIterator

public FastIterator fastIterator()

javaUtilIterator

public Iterator<T> javaUtilIterator()

Drools :: Core 6.0.0.Beta5

Copyright © 2001-2013 JBoss by Red Hat. All Rights Reserved.