* Returns the sub-attributes of the quark passed in parameter
*
* @param attributeQuark
+ * @param recursive
* @return
* @throws AttributeNotFoundException
*/
- List<Integer> getSubAttributes(int attributeQuark)
+ List<Integer> getSubAttributes(int attributeQuark, boolean recursive)
throws AttributeNotFoundException {
List<Integer> listOfChildren = new ArrayList<Integer>();
Attribute startingAttribute;
-
+
/* Check if the quark is valid */
- if ( attributeQuark < 0 || attributeQuark >= attributeList.size()) {
+ if (attributeQuark < 0 || attributeQuark >= attributeList.size()) {
throw new AttributeNotFoundException();
}
-
+
/* Set up the node from which we'll start the search */
- if ( attributeQuark == -1 ) {
+ if (attributeQuark == -1) {
startingAttribute = attributeTreeRoot;
} else {
startingAttribute = attributeList.get(attributeQuark);
}
-
+
/* Iterate through the sub-attributes and add them to the list */
- for (Attribute childNode : startingAttribute.getSubAttributesList()) {
- listOfChildren.add(childNode.getQuark());
- }
+ addSubAttributes(listOfChildren, startingAttribute, recursive);
return listOfChildren;
}
+ private void addSubAttributes(List<Integer> list, Attribute curAttribute,
+ boolean recursive) {
+ for (Attribute childNode : curAttribute.getSubAttributesList()) {
+ list.add(childNode.getQuark());
+ if (recursive) {
+ addSubAttributes(list, childNode, true);
+ }
+ }
+ }
+
String getFullAttributeName(int quark) {
if (quark >= attributeList.size() || quark < 0) {
return null;
* @param quark
* The attribute of which you want to sub-attributes. You can use
* "-1" here to specify the root node.
+ * @param recursive
+ * True if you want all recursive sub-attributes, false if you
+ * only want the first level.
* @return A List of integers, matching the quarks of the sub-attributes.
* @throws AttributeNotFoundException
* If the quark was not existing or invalid.
*/
- public List<Integer> getSubAttributes(int quark)
+ public List<Integer> getSubAttributes(int quark, boolean recursive)
throws AttributeNotFoundException {
- return attributeTree.getSubAttributes(quark);
+ return attributeTree.getSubAttributes(quark, recursive);
}
/**
public void removeAttribute(long t, int attributeQuark)
throws TimeRangeException, AttributeNotFoundException {
assert (attributeQuark >= 0);
- /* "Nullify our children first, recursively */
- List<Integer> childAttributes = attributeTree.getSubAttributes(attributeQuark);
+ List<Integer> childAttributes;
+
+ /*
+ * "Nullify our children first, recursively. We pass 'false' because we
+ * handle the recursion ourselves.
+ */
+ childAttributes = attributeTree.getSubAttributes(attributeQuark, false);
for (Integer childNodeQuark : childAttributes) {
assert (attributeQuark != childNodeQuark);
removeAttribute(t, childNodeQuark);