/** * Returns all (possibly multiple) the DataObject elements/sub-elements with the specified name. * Could include itself or any recursively selected child. * * @param name Name of the element to return * @return DataObject with the specified name or null, if not found */ public List<DataObject> getDataObjects(String name) { List<DataObject> result = new ArrayList<DataObject>(); // object's name matches, so add it if (this.name.equals(name)) { result.add(this); } // so recursively search among children for (DataObject child : children) { // iterate through each child to add more // note that child may add an empty list result.addAll(child.getDataObjects(name)); } return result; }