org.mmbase.bridge.util
Class TreeList

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.AbstractSequentialList<E>
              extended by org.mmbase.bridge.util.AbstractSequentialBridgeList<Node>
                  extended by org.mmbase.bridge.util.TreeList
All Implemented Interfaces:
Iterable<Node>, Collection<Node>, List<Node>, BridgeList<Node>, NodeList
Direct Known Subclasses:
GrowingTreeList

public class TreeList
extends AbstractSequentialBridgeList<Node>
implements NodeList

Queries a Tree from MMBase. A Tree is presented as a List of MultiLevel results (ClusterNodes), combined with a smart iterator which iterates through the elements of these lists as if it was one list ordered as a Tree.

Since:
MMBase-1.7
Version:
$Id: TreeList.java 41943 2010-04-16 17:18:19Z michiel $
Author:
Michiel Meeuwissen

Nested Class Summary
protected  class TreeList.Branch
          Structure to hold the information for every branch-depth.
protected  class TreeList.TreeItr
          The TreeIterator contains the core-functionality of TreeList.
 
Field Summary
protected  List<TreeList.Branch> branches
           
protected  Cloud cloud
           
protected  boolean foundEnd
           
protected  int leafConstraintOffset
           
protected  int max
           
protected  int numberOfSteps
           
static String REAL_NODES
           
protected  int topQuery
           
 
Fields inherited from class java.util.AbstractList
modCount
 
Fields inherited from interface org.mmbase.bridge.NodeList
NODESTEP_PROPERTY, QUERY_PROPERTY
 
Constructor Summary
TreeList(NodeQuery q)
           
TreeList(TreeList tl)
          Copy-constructor
 
Method Summary
static void doTest(Writer writer, NodeQuery q)
           
 Cloud getCloud()
           
protected  NodeList getLeafList(int queryNumber)
          Executes one query as a 'leaf' query.
 NodeQuery getLeafQuery()
          Returns the top most query, associated with the last call to grow(org.mmbase.bridge.NodeManager, java.lang.String, java.lang.String).
protected  NodeList getList(int queryNumber)
          Executes one query if that did not happen yet, and stores the result in the 'results' List
 int getMax()
           
 Node getNode(int i)
          Returns the Node at the indicated postion in the list
protected static NodeQuery getQuery(String[] args)
          For testing only.
protected  Node getRealNode(int queryIndex, int index)
          Returns node 'index' of query result 'queryIndex' as a 'real' node (so not a cluster node)
 RelationStep grow(NodeManager nodeManager, String role, String searchDir)
          Grows branches of the Tree, which means that one new query will be created which is one relationStep longer than the longest one until now.
 ListIterator<Node> listIterator(int ind)
           
static void main(String[] args)
           
 NodeIterator nodeIterator()
          Returns an type-specific iterator for this list.
 void setLeafConstraint(Constraint constraint)
          Sets a 'leaf constraint' on the last 'growed' step.
 void setMax(int m)
           
 int size()
           
protected  void sizeCheck()
          Checks if the size of the List needs to be (re)determined, and if not, does so.
 NodeList subList(int start, int end)
           
 NodeList subNodeList(int start, int end)
          Returns a sublist of this list.
 String toString()
           
 TreeIterator treeIterator()
           
protected  TreeIterator treeIterator(int ind)
           
 
Methods inherited from class org.mmbase.bridge.util.AbstractSequentialBridgeList
getProperties, getProperty, setProperty, sort, sort
 
Methods inherited from class java.util.AbstractSequentialList
add, addAll, get, iterator, remove, set
 
Methods inherited from class java.util.AbstractList
add, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mmbase.bridge.BridgeList
getProperties, getProperty, setProperty, sort, sort
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, remove, remove, removeAll, retainAll, set, toArray, toArray
 

Field Detail

REAL_NODES

public static final String REAL_NODES
See Also:
Constant Field Values

cloud

protected final Cloud cloud

branches

protected final List<TreeList.Branch> branches

topQuery

protected int topQuery

numberOfSteps

protected int numberOfSteps

foundEnd

protected boolean foundEnd

leafConstraintOffset

protected int leafConstraintOffset

max

protected int max
Since:
MMBase-1.8.1
Constructor Detail

TreeList

public TreeList(NodeQuery q)
Parameters:
q - The 'base' query defining the minimal depth of the tree elements. The trunk of the tree.

TreeList

public TreeList(TreeList tl)
Copy-constructor

Since:
MMBase-1.8
Method Detail

setMax

public void setMax(int m)
Since:
MMBase-1.8.1

getMax

public int getMax()
Since:
MMBase-1.8.1

getCloud

public Cloud getCloud()
Since:
MMBase-1.8

size

public int size()
Specified by:
size in interface Collection<Node>
Specified by:
size in interface List<Node>
Specified by:
size in class AbstractCollection<Node>

sizeCheck

protected void sizeCheck()
Checks if the size of the List needs to be (re)determined, and if not, does so. After growing a List the size needs recalculation.

Since:
MMBase-1.7.1

grow

public RelationStep grow(NodeManager nodeManager,
                         String role,
                         String searchDir)
Grows branches of the Tree, which means that one new query will be created which is one relationStep longer than the longest one until now. This new relationStep is returned, which can be used to create new constraints.

Returns:
null if no relationstep is added because that would not increase the number of results.

getLeafQuery

public NodeQuery getLeafQuery()
Returns the top most query, associated with the last call to grow(org.mmbase.bridge.NodeManager, java.lang.String, java.lang.String).

Since:
MMBase-1.8

setLeafConstraint

public void setLeafConstraint(Constraint constraint)
Sets a 'leaf constraint' on the last 'growed' step. A leaf constraint is a constraint which is only used on leafs, so if the tree is grown further, the leaf constraint will not be passed to the branches.

Since:
MMBase-1.8

getList

protected NodeList getList(int queryNumber)
Executes one query if that did not happen yet, and stores the result in the 'results' List

Returns:
NodeList or null if queryNumber too big
Throws:
IndexOutOfBoundsException - if queryNumber < 0

getLeafList

protected NodeList getLeafList(int queryNumber)
Executes one query as a 'leaf' query.

Since:
MMBase-1.8

listIterator

public ListIterator<Node> listIterator(int ind)
Specified by:
listIterator in interface List<Node>
Specified by:
listIterator in class AbstractSequentialList<Node>

nodeIterator

public NodeIterator nodeIterator()
Description copied from interface: NodeList
Returns an type-specific iterator for this list.

Specified by:
nodeIterator in interface NodeList
Returns:
Node iterator

treeIterator

public TreeIterator treeIterator()

treeIterator

protected TreeIterator treeIterator(int ind)

getNode

public Node getNode(int i)
Description copied from interface: NodeList
Returns the Node at the indicated postion in the list

Specified by:
getNode in interface NodeList
Parameters:
i - the position of the Node to retrieve
Returns:
Node at the indicated postion

getRealNode

protected Node getRealNode(int queryIndex,
                           int index)
Returns node 'index' of query result 'queryIndex' as a 'real' node (so not a cluster node)


subNodeList

public NodeList subNodeList(int start,
                            int end)
Description copied from interface: NodeList
Returns a sublist of this list.

Specified by:
subNodeList in interface NodeList
Parameters:
start - the position in the current list where the sublist starts (inclusive)
end - the position in the current list where the sublist ends (exclusive)
Returns:
sublist of this list

subList

public NodeList subList(int start,
                        int end)
Specified by:
subList in interface List<Node>
Specified by:
subList in interface BridgeList<Node>
Specified by:
subList in class AbstractSequentialBridgeList<Node>

toString

public String toString()
Overrides:
toString in class AbstractCollection<Node>

getQuery

protected static NodeQuery getQuery(String[] args)
For testing only. Based on RMMCI, please use the System property to specify de cloud context -Dmmbase.defaultcloudcontext=rmi://localhost:1111/remotecontext

Parameters:
args - the start node (in one argument)

doTest

public static void doTest(Writer writer,
                          NodeQuery q)

main

public static void main(String[] args)


MMBase 2.0-SNAPSHOT - null