I added two methods to Node.java and I’m thinking they might be good to have to everyone.
The first is to detach all children fitting a certain name. There is already one where you can delete a named child, but it would only remove the first occurrence. I wanted the ability to remove all children of a given name.
The second searches for a node with a given name attached inside the node and return it.
Here’s the diff.
[java]
This patch file was generated by NetBeans IDE
It uses platform neutral UTF-8 encoding and n newlines.
— Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -339,7 +339,7 @@
throw new NullPointerException();
for (int x = 0, max = children.size(); x < max; x++) {
-
Spatial child = children.get(x);<br />
-
Spatial child = children.get(x);<br />
if (childName.equals(child.getName())) {
detachChildAt( x );
return x;
@@ -349,7 +349,26 @@
}
/**
-
* <code>detachChildrenNamed</code> removes all named children from the node's list.<br />
-
* These children will no longer be maintained.<br />
*
-
* @param childrenName<br />
-
* the children's name to remove.<br />
-
*/<br />
- public void detachChildrenNamed(String childName) {
-
if (childName == null)<br />
-
throw new NullPointerException();<br />
+
-
for ( int i = children.size() - 1; i >= 0; i-- ) {<br />
-
Spatial child = children.get(i);<br />
-
if (childName.equals(child.getName())) {<br />
-
detachChildAt( i );<br />
-
}<br />
-
}<br />
- }
+
- /**
-
*<br />
- <code>detachChildAt</code> removes a child at a given index. That child
- is returned for saving purposes.
*
@@ -445,6 +464,27 @@
}
/**
-
* <code>getChildNode</code> returns the first child node found with exactly the<br />
-
* given name (case sensitive.)<br />
-
*<br />
-
* @param name<br />
-
* the name of the child node to retrieve. If null, we'll return null.<br />
-
* @return the child node if found, or null.<br />
-
*/<br />
- public Node getChildNode(String name) {
-
if (name == null)<br />
-
return null;<br />
+
-
for (int x = 0, cSize = getQuantity(); x < cSize; x++) {<br />
-
Spatial child = children.get(x);<br />
-
if (child instanceof Node)<br />
-
if (name.equals(child.getName()))<br />
-
return (Node) child;<br />
-
}<br />
-
return null;<br />
- }
+
- /**
- determines if the provided Spatial is contained in the children list of
- this node.
- [/java]