Update of /var/cvs/src/org/mmbase/bridge/util
In directory james.mmbase.org:/tmp/cvs-serv21428
Modified Files:
TreeIterator.java TreeList.java
Log Message:
MMB-1611
See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/bridge/util
See also: http://www.mmbase.org/jira/browse/MMB-1611
Index: TreeIterator.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/bridge/util/TreeIterator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- TreeIterator.java 9 Oct 2004 09:37:34 -0000 1.3
+++ TreeIterator.java 28 Feb 2008 12:23:51 -0000 1.4
@@ -10,13 +10,14 @@
package org.mmbase.bridge.util;
-import org.mmbase.bridge.NodeIterator;
+import org.mmbase.bridge.*;
+
/**
* A specialized iterator for 'TreeLists'
*
* @author Michiel Meeuwissen
- * @version $Id: TreeIterator.java,v 1.3 2004/10/09 09:37:34 nico Exp $
+ * @version $Id: TreeIterator.java,v 1.4 2008/02/28 12:23:51 michiel Exp $
* @since MMBase-1.7
* @see org.mmbase.bridge.util.TreeList
*/
@@ -28,4 +29,19 @@
*/
int currentDepth();
+
+ /**
+ * Returns the 'parent' node of the most recently returned Node. Or
<code>null</code> if there
+ * is no such node.
+ * @since MMBase-1.8.6
+ */
+ Node getParent();
+
+ /**
+ * Returns all nodes with the same parent as the most recently return Node
(include that node
+ * itself).
+ * @since MMBase-1.8.6
+ */
+ NodeList getSiblings();
+
}
Index: TreeList.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/bridge/util/TreeList.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- TreeList.java 3 Feb 2008 17:33:56 -0000 1.29
+++ TreeList.java 28 Feb 2008 12:23:51 -0000 1.30
@@ -23,7 +23,7 @@
*
*
* @author Michiel Meeuwissen
- * @version $Id: TreeList.java,v 1.29 2008/02/03 17:33:56 nklasens Exp $
+ * @version $Id: TreeList.java,v 1.30 2008/02/28 12:23:51 michiel Exp $
* @since MMBase-1.7
*/
@@ -226,6 +226,8 @@
}
return branch.result;
}
+
+
/**
* Executes one query as a 'leaf' query.
* @since MMBase-1.8
@@ -376,7 +378,9 @@
private int currentIterator; // number of current iterator which is
iterated
private int nextIndex; // the next index number, so this is 0 on
the beginning, and <size> just before the last next()
+
private boolean encounteredLeafConstraint = false;
+ private Node current;
TreeItr(int i) {
if (i < 0 || (i > 0 && i > TreeList.this.size())) {
@@ -467,9 +471,48 @@
public Node nextNode() {
nextIndex++;
- return getNextNode();
+ current = getNextNode();
+ return current;
+ }
+
+ public Node getParent() {
+ NodeList nl = TreeList.this.getLeafList(currentDepth() - 1);
+ Query q = TreeList.this.branches.get(currentDepth() -1
).getQuery();
+ List<Step> steps = q.getSteps();
+ if (steps.size() >= 3) {
+ Step thisStep = steps.get(steps.size() - 1);
+ Step parentStep = steps.get(steps.size() - 3);
+ for (Node sibling : nl) {
+ if (current.getNumber() ==
sibling.getIntValue(thisStep.getAlias() +".number")) {
+ return
getCloud().getNode(sibling.getIntValue(parentStep.getAlias() +".number"));
+ }
+ }
+ }
+ return null;
}
+ public NodeList getSiblings() {
+ NodeList nl = TreeList.this.getLeafList(currentDepth() - 1);
+ Query q = TreeList.this.branches.get(currentDepth() -1
).getQuery();
+ List<Step> steps = q.getSteps();
+ NodeList l = getCloud().createNodeList();
+ if (steps.size() >= 3) {
+ int start = 0;
+ int end = 0;
+ int parent = getParent().getNumber();
+ Step thisStep = steps.get(steps.size() - 1);
+ Step parentStep = steps.get(steps.size() - 3);
+ for (Node sibling : nl) {
+ if (sibling.getIntValue(parentStep.getAlias() +".number")
== parent) {
+
l.add(getCloud().getNode(sibling.getIntValue(thisStep.getAlias() +".number")));
+ }
+ }
+ return l;
+ } else {
+ l.add(current);
+ return l;
+ }
+ }
/**
* Depth of the last node fetched with next() or nextNode()
*/
@@ -653,12 +696,14 @@
String startNodes = args[0];
Cloud cloud =
ContextProvider.getDefaultCloudContext().getCloud("mmbase");
- NodeManager object = cloud.getNodeManager("segments");
+ String type = args.length > 1 ? args[1] : "segments";
+ String role = args.length > 2 ? args[2] : "index";
+ NodeManager object = cloud.getNodeManager(type);
NodeQuery q = cloud.createNodeQuery();
Step step = q.addStep(object);
q.setNodeStep(step);
- RelationStep relationStep = q.addRelationStep(object, "index",
"destination");
+ RelationStep relationStep = q.addRelationStep(object, role,
"destination");
q.setNodeStep(relationStep.getNext());
StepField pos = q.createStepField(relationStep, "pos");
q.addSortOrder(pos, SortOrder.ORDER_ASCENDING);
@@ -672,7 +717,7 @@
public static void doTest(java.io.Writer writer, NodeQuery q) {
Cloud cloud = q.getCloud();
- NodeManager object = cloud.getNodeManager("segments");
+ NodeManager object = q.getNodeManager();
try {
//String text = "%potjandosie%";
String text = "%%";
@@ -680,21 +725,27 @@
long startTime = System.currentTimeMillis();
TreeList tree = new TreeList(q);
+ if (object.hasField("body")) {
Constraint con2 = Queries.createConstraint(tree.getLeafQuery(),
"body", Queries.getOperator("LIKE"), text);
//tree.setLeafConstraint(con2);
+ }
+
writer.write("grow1:\n");
writer.flush();
- RelationStep step = tree.grow(object, "index", "destination");
+ RelationStep step = tree.grow(object, "posrel", "destination");
NodeQuery top = tree.getLeafQuery();
+ if (object.hasField("body")) {
Constraint con1 = Queries.createConstraint(top, "body",
Queries.getOperator("LIKE"), text);
//tree.setLeafConstraint(con1);
+ }
+ assert step != null;
StepField pos = top.createStepField(step, "pos");
top.addSortOrder(pos, SortOrder.ORDER_ASCENDING);
writer.write("top " + top.toSql() + " grow2:\n");
writer.flush();
- tree.grow(object, "index", "destination");
+ tree.grow(object, "posrel", "destination");
NodeQuery leaf = tree.getLeafQuery();
Constraint con = Queries.createConstraint(leaf, "body",
Queries.getOperator("LIKE"), text);
//tree.setLeafConstraint(con);
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs