Update of /var/cvs/src/org/mmbase/bridge/util
In directory james.mmbase.org:/tmp/cvs-serv21388
Modified Files:
Tag: MMBase-1_8
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.3.2.1
diff -u -b -r1.3 -r1.3.2.1
--- TreeIterator.java 9 Oct 2004 09:37:34 -0000 1.3
+++ TreeIterator.java 28 Feb 2008 12:23:27 -0000 1.3.2.1
@@ -10,13 +10,13 @@
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.3.2.1 2008/02/28 12:23:27 michiel Exp $
* @since MMBase-1.7
* @see org.mmbase.bridge.util.TreeList
*/
@@ -28,4 +28,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.21.2.2
retrieving revision 1.21.2.3
diff -u -b -r1.21.2.2 -r1.21.2.3
--- TreeList.java 2 Aug 2007 10:10:16 -0000 1.21.2.2
+++ TreeList.java 28 Feb 2008 12:23:27 -0000 1.21.2.3
@@ -23,7 +23,7 @@
*
*
* @author Michiel Meeuwissen
- * @version $Id: TreeList.java,v 1.21.2.2 2007/08/02 10:10:16 michiel Exp $
+ * @version $Id: TreeList.java,v 1.21.2.3 2008/02/28 12:23:27 michiel Exp $
* @since MMBase-1.7
*/
@@ -273,6 +273,12 @@
return (Node)get(i);
}
+ public NodeList getSiblings(Node node, int depth) {
+ NodeList nl = getList(depth);
+
+ return nl;
+ }
+
/**
* Returns node 'index' of query result 'queryIndex' as a 'real' node (so
not a cluster node)
*/
@@ -372,6 +378,7 @@
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())) {
@@ -462,9 +469,50 @@
public Node nextNode() {
nextIndex++;
- return getNextNode();
+ current = getNextNode();
+ return current;
}
+
+
+ public Node getParent() {
+ NodeList nl = TreeList.this.getLeafList(currentDepth() - 1);
+ Query q = ((Branch) TreeList.this.branches.get(currentDepth() -1
)).getQuery();
+ List steps = q.getSteps();
+ if (steps.size() >= 3) {
+ Step thisStep = (Step) steps.get(steps.size() - 1);
+ Step parentStep = (Step) steps.get(steps.size() - 3);
+ for (NodeIterator ni = nl.nodeIterator(); ni.hasNext(); ) {
+ Node sibling = ni.nextNode();
+ 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 = ((Branch) TreeList.this.branches.get(currentDepth() -1
)).getQuery();
+ List steps = q.getSteps();
+ NodeList l = getCloud().createNodeList();
+ if (steps.size() >= 3) {
+ int parent = getParent().getNumber();
+ Step thisStep = (Step) steps.get(steps.size() - 1);
+ Step parentStep = (Step) steps.get(steps.size() - 3);
+ for (NodeIterator ni = nl.nodeIterator(); ni.hasNext(); ) {
+ Node sibling = ni.nextNode();
+ 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()
*/
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs