de.danielbechler.diff.node
Interface Node

All Superinterfaces:
Accessor, CanonicalAccessor, PropertyDescriptor
All Known Implementing Classes:
CollectionNode, DefaultNode, MapNode

public interface Node
extends CanonicalAccessor

Represents a part of an object. It could be the object itself, one of its properties, an item in a collection or a map entry. A node may have one parent node and any number of children. It also provides methods to read and write the property represented by this node on any object of the same type as the original object. Last but not least, a node knows how the associated property has changed compared to the base object.

Author:
Daniel Bechler

Nested Class Summary
static class Node.State
          The state of a Node representing the difference between two objects.
static interface Node.Visitor
          Visitor to traverse a node graph.
 
Field Summary
static Node ROOT
           
 
Method Summary
 boolean addChild(Node node)
          Adds a child to this node and sets this node as its parent node.
 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()
           
 PropertyPath getPropertyPath()
           
 Node.State getState()
           
 Class<?> getType()
           
 boolean hasChanges()
           
 boolean hasChildren()
           
 boolean isAdded()
          Convenience method for getState() == Node.State.ADDED
 boolean isChanged()
          Convenience method for getState() == Node.State.CHANGED
 boolean isCircular()
          Convenience method for getState() == Node.State.CIRCULAR
 boolean isCollectionNode()
           
 boolean isIgnored()
          Convenience method for getState() == Node.State.IGNORED
 boolean isMapNode()
           
 boolean isRemoved()
          Convenience method for getState() == Node.State.REMOVED
 boolean isRootNode()
           
 boolean isUntouched()
          Convenience method for getState() == Node.State.UNTOUCHED
 boolean matches(PropertyPath path)
           
 void setParentNode(Node parent)
          Sets the parent node.
 void setState(Node.State state)
           
 void setType(Class<?> aClass)
          Allows for explicit type definition.
 CollectionNode toCollectionNode()
           
 MapNode toMapNode()
           
 void visit(Node.Visitor visitor)
          Visit this and all child nodes.
 void visitChildren(Node.Visitor visitor)
          Visit all child nodes but not this one.
 
Methods inherited from interface de.danielbechler.diff.accessor.CanonicalAccessor
canonicalGet, canonicalSet, canonicalUnset
 
Methods inherited from interface de.danielbechler.diff.accessor.Accessor
get, set, unset
 
Methods inherited from interface de.danielbechler.diff.accessor.PropertyDescriptor
getCategories, getPathElement, isEqualsOnly
 

Field Detail

ROOT

static final Node ROOT
Method Detail

getParentNode

Node getParentNode()
Returns:
The parent node, if any.

setParentNode

void setParentNode(Node parent)
Sets the parent node.

Parameters:
parent - The parent of this node. May be null, if this is a root node.

getState

Node.State getState()
Returns:
The state of this node.

setState

void setState(Node.State state)
Parameters:
state - The state of this node.

matches

boolean matches(PropertyPath path)

isRootNode

boolean isRootNode()

hasChanges

boolean hasChanges()

isAdded

boolean isAdded()
Convenience method for getState() == Node.State.ADDED


isChanged

boolean isChanged()
Convenience method for getState() == Node.State.CHANGED


isRemoved

boolean isRemoved()
Convenience method for getState() == Node.State.REMOVED


isUntouched

boolean isUntouched()
Convenience method for getState() == Node.State.UNTOUCHED


isIgnored

boolean isIgnored()
Convenience method for getState() == Node.State.IGNORED

Specified by:
isIgnored in interface PropertyDescriptor

isCircular

boolean isCircular()
Convenience method for getState() == Node.State.CIRCULAR


isCollectionNode

boolean isCollectionNode()

toCollectionNode

CollectionNode toCollectionNode()

isMapNode

boolean isMapNode()

toMapNode

MapNode toMapNode()

getType

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

setType

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

Parameters:
aClass - The type of the value represented by this node.

getPropertyPath

PropertyPath getPropertyPath()
Returns:
The absolute property path from the object root up to this node.

hasChildren

boolean hasChildren()
Returns:
true if this node has children.

getChildren

Collection<Node> getChildren()
Returns:
The child nodes of this node.

getChild

Node getChild(String propertyName)
Retrieve a child with the given property name relative to this node.

Parameters:
propertyName - The name of the property represented by the child node.
Returns:
The requested child node or null.

getChild

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

Parameters:
path - The path from the object root to the requested child node.
Returns:
The requested child node or null.

getChild

Node getChild(Element pathElement)
Retrieve a child that matches the given path element relative to this node.

Parameters:
pathElement - The path element of the childe node to get.
Returns:
The requested child node or null.

addChild

boolean addChild(Node node)
Adds a child to this node and sets this node as its parent node.

Parameters:
node - The node to add.

visit

void visit(Node.Visitor visitor)
Visit this and all child nodes.

Parameters:
visitor - The visitor to use.

visitChildren

void visitChildren(Node.Visitor visitor)
Visit all child nodes but not this one.

Parameters:
visitor - The visitor to use.


Copyright © 2012. All Rights Reserved.