Package de.danielbechler.diff.node
Class DiffNode
java.lang.Object
de.danielbechler.diff.node.DiffNode
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe state of aDiffNoderepresenting the difference between two objects.static interfaceVisitor to traverse a node graph. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCategories(Collection<String> additionalCategories) voidAdds a child to this node and sets this node as its parent node.canonicalGet(Object target) voidcanonicalSet(Object target, Object value) voidcanonicalUnset(Object target) intbooleanRetrieve a child that matches the given absolute path, starting from the current node.getChild(ElementSelector elementSelector) Retrieve a child that matches the given path element relative to this node.Retrieve a child with the given property name relative to this node.getChild(List<ElementSelector> selectors) Retrieve a child that matches the given path element relative to this node.<T extends Annotation>
TgetFieldAnnotation(Class<T> annotationClass) If this node represents a bean property this method returns all annotations of its field.getPath()<T extends Annotation>
TgetPropertyAnnotation(Class<T> annotationClass) If this node represents a bean property this method returns all annotations of its getter.If this node represents a bean property, this method will simply return its name.getState()Class<?>booleanbooleaninthashCode()final booleanisAdded()Convenience method forgetState()==DiffNode.State.ADDEDfinal booleanConvenience method forgetState()==DiffNode.State.CHANGEDbooleanConvenience method forgetState()==DiffNode.State.CIRCULARbooleanDeprecated.This method was a shortcut to extract the "exclude" flag from the ObjectDiffProperty annotation.final booleanConvenience method forgetState()==DiffNode.State.IGNOREDfinal booleanReturnstruewhen this node represents a bean property and can therefore be queried for property specific information like annotations or property types.final booleanConvenience method forgetState()==DiffNode.State.REMOVEDfinal booleanfinal booleanConvenience method forgetState()==DiffNode.State.UNTOUCHEDbooleanstatic DiffNodestatic DiffNodenewRootNodeWithType(Class<?> valueType) voidvoidsetChildIdentityStrategy(IdentityStrategy identityStrategy) voidsetCircleStartNode(DiffNode circleStartNode) voidsetCircleStartPath(NodePath circularStartPath) protected final voidsetParentNode(DiffNode parentNode) Sets the parent node.voidsetState(DiffNode.State state) final voidAllows to explicity set the type of this node.voidsetValueTypeInfo(TypeInfo typeInfo) toString()voidfinal voidvisit(DiffNode.Visitor visitor) Visit this and all child nodes.protected final voidvisit(DiffNode.Visitor visitor, Visit visit) final voidvisitChildren(DiffNode.Visitor visitor) Visit all child nodes but not this one.final voidvisitParents(DiffNode.Visitor visitor)
-
Field Details
-
ROOT
-
-
Constructor Details
-
DiffNode
-
DiffNode
-
-
Method Details
-
setChildIdentityStrategy
-
newRootNode
-
newRootNodeWithType
-
getState
- Returns:
- The state of this node.
-
setState
- Parameters:
state- The state of this node.
-
matches
-
hasChanges
public boolean hasChanges() -
isAdded
public final boolean isAdded()Convenience method forgetState()==DiffNode.State.ADDED -
isChanged
public final boolean isChanged()Convenience method forgetState()==DiffNode.State.CHANGED -
isRemoved
public final boolean isRemoved()Convenience method forgetState()==DiffNode.State.REMOVED -
isUntouched
public final boolean isUntouched()Convenience method forgetState()==DiffNode.State.UNTOUCHED -
isCircular
public boolean isCircular()Convenience method forgetState()==DiffNode.State.CIRCULAR -
getPath
- Returns:
- The absolute property path from the object root up to this node.
-
getElementSelector
-
getValueType
- Returns:
- Returns the type of the property represented by this node, or null if unavailable.
-
setType
Allows to explicity set the type of this node. This will overshadow the type returned by getValueTypeInfo() as well as the one returned by the accessor.- Parameters:
aClass- The type of the value represented by this node.
-
getValueTypeInfo
-
setValueTypeInfo
-
hasChildren
public boolean hasChildren()- Returns:
trueif this node has children.
-
childCount
public int childCount() -
getChild
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
Retrieve a child that matches the given path element relative to this node.- Parameters:
elementSelector- The path element of the child node to get.- Returns:
- The requested child node or
null.
-
getChild
Retrieve a child that matches the given absolute path, starting from the current node.- Parameters:
nodePath- The path from the object root to the requested child node.- Returns:
- The requested child node or
null.
-
getChild
Retrieve a child that matches the given path element relative to this node.- Parameters:
selectors- The path element of the child node to get.- Returns:
- The requested child node or
null.
-
addChild
Adds a child to this node and sets this node as its parent node.- Parameters:
node- The node to add.
-
visit
Visit this and all child nodes.- Parameters:
visitor- The visitor to use.
-
visit
-
visitChildren
Visit all child nodes but not this one.- Parameters:
visitor- The visitor to use.
-
visitParents
-
getFieldAnnotations
If this node represents a bean property this method returns all annotations of its field. Only works for fields having a name that matches the name derived from the getter.- Returns:
- The annotations of the field, or an empty set if there is no field with the name derived from the getter.
-
getFieldAnnotation
- Type Parameters:
T-- Parameters:
annotationClass- the annotation we are looking for- Returns:
- The given annotation of the field, or null if not annotated or if there is no field with the name derived from the getter.
-
getPropertyAnnotations
If this node represents a bean property this method returns all annotations of its getter.- Returns:
- A set of annotations of this nodes property getter or an empty set.
-
getPropertyAnnotation
-
getPropertyName
If this node represents a bean property, this method will simply return its name. Otherwise it will return the property name of its closest bean property representing ancestor. This way intermediate nodes like those representing collection, map or array items will be semantically tied to their container objects. That is especially useful for inclusion and exclusion rules. For example, when a List is explicitly included by property name, it would be weird if the inclusion didn't also apply to its items. -
isPropertyAware
public final boolean isPropertyAware()Returnstruewhen this node represents a bean property and can therefore be queried for property specific information like annotations or property types. But there will also be nodes that represent collection items, map entries, etc. In those cases this method will returnfalse. -
isRootNode
public final boolean isRootNode() -
isIgnored
public final boolean isIgnored()Convenience method forgetState()==DiffNode.State.IGNORED -
isExcluded
Deprecated.This method was a shortcut to extract the "exclude" flag from the ObjectDiffProperty annotation. Since we found a better way to do that, it is not needed anymore and will be removed in future versions. The name is also misleading. It implies that here lies the truth about the exclusion, but only the InclusionService can tell for sure. This flag is just only little piece of the puzzle.- See Also:
-
TypePropertyAnnotationInclusionResolver
-
getCategories
-
getParentNode
- Returns:
- The parent node, if any.
-
setParentNode
Sets the parent node.- Parameters:
parentNode- The parent of this node. May be null, if this is a root node.
-
get
-
set
-
unset
-
canonicalGet
-
canonicalSet
-
canonicalUnset
-
hashCode
public int hashCode() -
equals
-
toString
-
addCategories
-
getCircleStartPath
- Returns:
- Returns the path to the first node in the hierarchy that represents the same object instance as
this one. (Only if
isCircular()returnstrue.
-
setCircleStartPath
-
getCircleStartNode
-
setCircleStartNode
-