pnever 2003/09/16 12:04:22
Modified: src/share/org/apache/slide/structure ObjectNode.java
Log:
Added childrenCache and fixed bug in computeChildren
Revision Changes Path
1.15 +24 -16
jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java
Index: ObjectNode.java
===================================================================
RCS file:
/home/cvs/jakarta-slide/src/share/org/apache/slide/structure/ObjectNode.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ObjectNode.java 16 Sep 2003 15:43:40 -0000 1.14
+++ ObjectNode.java 16 Sep 2003 19:04:22 -0000 1.15
@@ -122,6 +122,7 @@
*/
private boolean bindingsShared;
+ private Vector childrenCache = null;
/**
* Default constructor.
@@ -160,7 +161,6 @@
this.bindings = new BindingList(bindings);
this.parentBindings = new ParentBindingList(parentBindings);
this.links = links;
- computeChildren();
}
/**
@@ -179,7 +179,6 @@
*/
public void setUri(String uri) {
this.uri = uri;
- computeChildren();
}
/**
@@ -215,7 +214,10 @@
* @return Enumeration Children's uris
*/
public Vector getChildren() {
- return computeChildren();
+ if (childrenCache == null) {
+ computeChildren();
+ }
+ return childrenCache;
}
/**
@@ -224,7 +226,7 @@
* @return Enumeration Children's uris
*/
public Enumeration enumerateChildren() {
- return computeChildren().elements();
+ return getChildren().elements();
}
/**
@@ -268,7 +270,7 @@
* false otherwise
*/
public boolean hasChild(String uri) {
- return computeChildren().contains(uri);
+ return getChildren().contains(uri);
}
/**
@@ -281,7 +283,7 @@
public boolean hasChild(ObjectNode child) {
boolean result = false;
if (child != null) {
- result = computeChildren().contains(child.getUri());
+ result = getChildren().contains(child.getUri());
}
return result;
}
@@ -350,7 +352,7 @@
* @return boolean true if this object has children, false otherwise
*/
public boolean hasChildren() {
- return !(computeChildren().isEmpty());
+ return !(getChildren().isEmpty());
}
/**
@@ -474,6 +476,7 @@
bindingsShared=false;
}
bindings.put(bindingName, source);
+ childrenCache = null;
source.addParentBinding(bindingName, this);
}
else {
@@ -499,6 +502,7 @@
}
String bindingName = lastUriSegment( child.getUri() );
bindings.remove(bindingName);
+ childrenCache = null;
child.removeParentBinding(bindingName, this);
}
@@ -517,15 +521,19 @@
String lastUriSegment( String uri ) {
return new UriPath(uri).lastSegment();
}
-
- private Vector computeChildren() {
- Vector children = new Vector();
+
+ private void computeChildren() {
+ childrenCache = new Vector();
Enumeration e = bindings.elements();
while (e.hasMoreElements()) {
Binding b = (Binding)e.nextElement();
- children.add( uri+"/"+b.getName() );
+ StringBuffer buf = new StringBuffer(uri);
+ if (!uri.endsWith("/")) {
+ buf.append("/");
+ }
+ buf.append(b.getName());
+ childrenCache.add( buf.toString() );
}
- return children;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]