de.danielbechler.diff.node
Class DefaultNode

java.lang.Object
  extended by de.danielbechler.diff.node.DefaultNode
All Implemented Interfaces:
Accessor, CanonicalAccessor, PropertyDescriptor, Node
Direct Known Subclasses:
CollectionNode, MapNode

public class DefaultNode
extends Object
implements Node

Author:
Daniel Bechler

Nested Class Summary
 
Nested classes/interfaces inherited from interface de.danielbechler.diff.node.Node
Node.State, Node.Visitor
 
Field Summary
 
Fields inherited from interface de.danielbechler.diff.node.Node
ROOT
 
Constructor Summary
DefaultNode(Accessor accessor, Class<?> valueType)
           
DefaultNode(Class<?> valueType)
           
DefaultNode(Node parentNode, Accessor accessor, Class<?> valueType)
           
 
Method Summary
 boolean addChild(Node node)
          Adds a child to this node and sets this node as its parent node.
 Object canonicalGet(Object target)
           
 void canonicalSet(Object target, Object value)
           
 void canonicalUnset(Object target)
           
 Object get(Object target)
           
 Set<String> getCategories()
           
 Node getChild(Element pathElement)
          Retrieve a child that matches the given path element relative to this node.
 Node getChild(PropertyPath path)
          Retrieve a child that matches the given absolute path, starting from the current node.
 Node getChild(String propertyName)
          Retrieve a child with the given property name relative to this node.
 Collection<Node> getChildren()
           
 Node getParentNode()
           
 Element getPathElement()
           
 PropertyPath getPropertyPath()
           
 Node.State getState()
           
 Class<?> getType()
           
 boolean hasChanges()
           
 boolean hasChildren()
           
 boolean isAdded()
          Convenience method for Node.getState() == Node.State.ADDED
 boolean isChanged()
          Convenience method for Node.getState() == Node.State.CHANGED
 boolean isCircular()
          Convenience method for Node.getState() == Node.State.CIRCULAR
 boolean isCollectionNode()
           
 boolean isEqualsOnly()
           
 boolean isIgnored()
          Convenience method for Node.getState() == Node.State.IGNORED
 boolean isMapNode()
           
 boolean isRemoved()
          Convenience method for Node.getState() == Node.State.REMOVED
 boolean isRootNode()
           
 boolean isUntouched()
          Convenience method for Node.getState() == Node.State.UNTOUCHED
 boolean matches(PropertyPath path)
           
 void set(Object target, Object value)
           
 void setParentNode(Node parentNode)
          Sets the parent node.
 void setState(Node.State state)
           
 void setType(Class<?> aClass)
          Allows for explicit type definition.
 CollectionNode toCollectionNode()
           
 MapNode toMapNode()
           
 String toString()
           
 void unset(Object target)
           
 void visit(Node.Visitor visitor)
          Visit this and all child nodes.
protected  void visit(Node.Visitor visitor, Visit visit)
           
 void visitChildren(Node.Visitor visitor)
          Visit all child nodes but not this one.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultNode

public DefaultNode(Node parentNode,
                   Accessor accessor,
                   Class<?> valueType)

DefaultNode

public DefaultNode(Accessor accessor,
                   Class<?> valueType)

DefaultNode

public DefaultNode(Class<?> valueType)
Method Detail

getState

public Node.State getState()
Specified by:
getState in interface Node
Returns:
The state of this node.

matches

public boolean matches(PropertyPath path)
Specified by:
matches in interface Node

hasChanges

public boolean hasChanges()
Specified by:
hasChanges in interface Node

isAdded

public final boolean isAdded()
Description copied from interface: Node
Convenience method for Node.getState() == Node.State.ADDED

Specified by:
isAdded in interface Node

isChanged

public final boolean isChanged()
Description copied from interface: Node
Convenience method for Node.getState() == Node.State.CHANGED

Specified by:
isChanged in interface Node

isRemoved

public final boolean isRemoved()
Description copied from interface: Node
Convenience method for Node.getState() == Node.State.REMOVED

Specified by:
isRemoved in interface Node

isUntouched

public final boolean isUntouched()
Description copied from interface: Node
Convenience method for Node.getState() == Node.State.UNTOUCHED

Specified by:
isUntouched in interface Node

isCircular

public boolean isCircular()
Description copied from interface: Node
Convenience method for Node.getState() == Node.State.CIRCULAR

Specified by:
isCircular in interface Node

getPropertyPath

public final PropertyPath getPropertyPath()
Specified by:
getPropertyPath in interface Node
Returns:
The absolute property path from the object root up to this node.

getPathElement

public Element getPathElement()
Specified by:
getPathElement in interface PropertyDescriptor

isCollectionNode

public boolean isCollectionNode()
Specified by:
isCollectionNode in interface Node

toCollectionNode

public CollectionNode toCollectionNode()
Specified by:
toCollectionNode in interface Node

isMapNode

public boolean isMapNode()
Specified by:
isMapNode in interface Node

toMapNode

public MapNode toMapNode()
Specified by:
toMapNode in interface Node

getType

public Class<?> getType()
Specified by:
getType in interface Node
Returns:
Returns the type of the property represented by this node, or null if unavailable.

setType

public void setType(Class<?> aClass)
Description copied from interface: Node
Allows for explicit type definition. However, if the accessor is TypeAware, Node.getType() will always return the type returned by the accessor.

Specified by:
setType in interface Node
Parameters:
aClass - The type of the value represented by this node.

hasChildren

public boolean hasChildren()
Specified by:
hasChildren in interface Node
Returns:
true if this node has children.

getChildren

public Collection<Node> getChildren()
Specified by:
getChildren in interface Node
Returns:
The child nodes of this node.

getChild

public Node getChild(String propertyName)
Description copied from interface: Node
Retrieve a child with the given property name relative to this node.

Specified by:
getChild in interface Node
Parameters:
propertyName - The name of the property represented by the child node.
Returns:
The requested child node or null.

getChild

public Node getChild(PropertyPath path)
Description copied from interface: Node
Retrieve a child that matches the given absolute path, starting from the current node.

Specified by:
getChild in interface Node
Parameters:
path - The path from the object root to the requested child node.
Returns:
The requested child node or null.

getChild

public Node getChild(Element pathElement)
Description copied from interface: Node
Retrieve a child that matches the given path element relative to this node.

Specified by:
getChild in interface Node
Parameters:
pathElement - The path element of the childe node to get.
Returns:
The requested child node or null.

addChild

public boolean addChild(Node node)
Description copied from interface: Node
Adds a child to this node and sets this node as its parent node.

Specified by:
addChild in interface Node
Parameters:
node - The node to add.

visit

public final void visit(Node.Visitor visitor)
Description copied from interface: Node
Visit this and all child nodes.

Specified by:
visit in interface Node
Parameters:
visitor - The visitor to use.

visit

protected final void visit(Node.Visitor visitor,
                           Visit visit)

visitChildren

public final void visitChildren(Node.Visitor visitor)
Description copied from interface: Node
Visit all child nodes but not this one.

Specified by:
visitChildren in interface Node
Parameters:
visitor - The visitor to use.

isRootNode

public final boolean isRootNode()
Specified by:
isRootNode in interface Node

isEqualsOnly

public final boolean isEqualsOnly()
Specified by:
isEqualsOnly in interface PropertyDescriptor

isIgnored

public final boolean isIgnored()
Description copied from interface: Node
Convenience method for Node.getState() == Node.State.IGNORED

Specified by:
isIgnored in interface PropertyDescriptor
Specified by:
isIgnored in interface Node

getCategories

public final Set<String> getCategories()
Specified by:
getCategories in interface PropertyDescriptor

setState

public final void setState(Node.State state)
Specified by:
setState in interface Node
Parameters:
state - The state of this node.

getParentNode

public Node getParentNode()
Specified by:
getParentNode in interface Node
Returns:
The parent node, if any.

setParentNode

public final void setParentNode(Node parentNode)
Description copied from interface: Node
Sets the parent node.

Specified by:
setParentNode in interface Node
Parameters:
parentNode - The parent of this node. May be null, if this is a root node.

get

public Object get(Object target)
Specified by:
get in interface Accessor

set

public void set(Object target,
                Object value)
Specified by:
set in interface Accessor

unset

public void unset(Object target)
Specified by:
unset in interface Accessor

canonicalGet

public Object canonicalGet(Object target)
Specified by:
canonicalGet in interface CanonicalAccessor

canonicalSet

public void canonicalSet(Object target,
                         Object value)
Specified by:
canonicalSet in interface CanonicalAccessor

canonicalUnset

public void canonicalUnset(Object target)
Specified by:
canonicalUnset in interface CanonicalAccessor

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.