com.marsching.flexiparse.objecttree
Class DefaultMutableObjectTreeElement

java.lang.Object
  extended by com.marsching.flexiparse.objecttree.DefaultMutableObjectTreeElement
All Implemented Interfaces:
MutableObjectTreeElement, ObjectTreeElement

public class DefaultMutableObjectTreeElement
extends Object
implements MutableObjectTreeElement

Default implementation of the MutableObjectTreeElement interface. Uses LinkedHashSets to store children nodes and attached objects.

Author:
Sebastian Marsching

Constructor Summary
DefaultMutableObjectTreeElement(MutableObjectTreeElement parent)
          Creates a new instance setting the parent property using the supplied argument.
 
Method Summary
 void addChild(MutableObjectTreeElement child)
          Registers another node as a child node of this node.
 void addObject(Object object)
          Attaches the given object to this node.
 Collection<? extends MutableObjectTreeElement> getChildren()
          Returns all children of this node.
 Collection<Object> getObjects()
          Returns objects attached directly to this node.
<T> Collection<T>
getObjectsOfType(Class<? extends T> type)
          Returns objects of specified type attached directly to this node.
<T> Collection<T>
getObjectsOfTypeFromSubTree(Class<? extends T> type)
          Returns objects attached to this node and all child nodes (recursively).
<T> Collection<T>
getObjectsOfTypeFromTopTree(Class<? extends T> type)
          Returns objects attached to this node and all parent nodes up to the root node of the tree.
 MutableObjectTreeElement getParent()
          Returns the parent of this node.
 ObjectTreeElement getRoot()
          Returns the root node of the tree this node belongs to.
 boolean removeChild(MutableObjectTreeElement child)
          Removes the specified child from this node.
 boolean removeObject(Object object)
          Removes a object from this node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultMutableObjectTreeElement

public DefaultMutableObjectTreeElement(MutableObjectTreeElement parent)
Creates a new instance setting the parent property using the supplied argument. The node will not automatically be registered as a child on the parent object. This action has to be performed by the code using this implementation.

Parameters:
parent - object representing the parent node of this node or null to create a root node
Method Detail

addChild

public void addChild(MutableObjectTreeElement child)
Description copied from interface: MutableObjectTreeElement
Registers another node as a child node of this node. For each child node, this method should only be called once. This node should be registered as the parent node of the node being supplied by the calling code.

Specified by:
addChild in interface MutableObjectTreeElement
Parameters:
child - node to be attached as a child.

removeChild

public boolean removeChild(MutableObjectTreeElement child)
Description copied from interface: MutableObjectTreeElement
Removes the specified child from this node.

Specified by:
removeChild in interface MutableObjectTreeElement
Parameters:
child - node to remove
Returns:
true if child was attached to this node, false otherwise

addObject

public void addObject(Object object)
Description copied from interface: ObjectTreeElement
Attaches the given object to this node.

Specified by:
addObject in interface ObjectTreeElement
Parameters:
object - object to attach

getChildren

public Collection<? extends MutableObjectTreeElement> getChildren()
Description copied from interface: MutableObjectTreeElement
Returns all children of this node.

Specified by:
getChildren in interface MutableObjectTreeElement
Specified by:
getChildren in interface ObjectTreeElement
Returns:
a list containing all child nodes of this node

getObjects

public Collection<Object> getObjects()
Description copied from interface: ObjectTreeElement
Returns objects attached directly to this node.

Specified by:
getObjects in interface ObjectTreeElement
Returns:
Objects attached to this node

getObjectsOfType

public <T> Collection<T> getObjectsOfType(Class<? extends T> type)
Description copied from interface: ObjectTreeElement
Returns objects of specified type attached directly to this node.

Specified by:
getObjectsOfType in interface ObjectTreeElement
Type Parameters:
T - type of wanted objects
Parameters:
type - object type that is returned
Returns:
objects of specified type attached to this node

getObjectsOfTypeFromTopTree

public <T> Collection<T> getObjectsOfTypeFromTopTree(Class<? extends T> type)
Description copied from interface: ObjectTreeElement
Returns objects attached to this node and all parent nodes up to the root node of the tree.

Specified by:
getObjectsOfTypeFromTopTree in interface ObjectTreeElement
Type Parameters:
T - type of wanted objects
Parameters:
type - object type that is returned
Returns:
objects of specified type attached to this node or one of its parents nodes

getParent

public MutableObjectTreeElement getParent()
Description copied from interface: MutableObjectTreeElement
Returns the parent of this node.

Specified by:
getParent in interface MutableObjectTreeElement
Specified by:
getParent in interface ObjectTreeElement
Returns:
parent of this node or null if this is the root node

removeObject

public boolean removeObject(Object object)
Description copied from interface: ObjectTreeElement
Removes a object from this node.

Specified by:
removeObject in interface ObjectTreeElement
Parameters:
object - object to remove
Returns:
true if the specified object was removed from this node, false otherwise

getObjectsOfTypeFromSubTree

public <T> Collection<T> getObjectsOfTypeFromSubTree(Class<? extends T> type)
Description copied from interface: ObjectTreeElement
Returns objects attached to this node and all child nodes (recursively). Includes objects attached to sub trees (see SubObjectTree).

Specified by:
getObjectsOfTypeFromSubTree in interface ObjectTreeElement
Type Parameters:
T - type of wanted objects
Parameters:
type - object type that is returned
Returns:
objects of specified type attached to this node or one of its child nodes

getRoot

public ObjectTreeElement getRoot()
Description copied from interface: MutableObjectTreeElement
Returns the root node of the tree this node belongs to.

Specified by:
getRoot in interface MutableObjectTreeElement
Specified by:
getRoot in interface ObjectTreeElement
Returns:
root node of the tree


Copyright © 2008-2009. All Rights Reserved.