Class ValueNode<T>
java.lang.Object
com.northconcepts.datapipeline.core.Node
com.northconcepts.datapipeline.core.ValueNode<T>
- All Implemented Interfaces:
Session,Serializable,Cloneable,Comparable<ValueNode<T>>
- Direct Known Subclasses:
ArrayValue,Record,SingleValue
ValueNode is the base class for all persistent values held in fields and arrays. Values can be:
- Single values (boolean, date, string, etc. --
FieldType) - Records
- Array of single values, records, and arrays
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.northconcepts.datapipeline.core.Node
Node.DuplicateNodeAction, Node.NodeTypeNested classes/interfaces inherited from interface com.northconcepts.datapipeline.core.Session
Session.SessionImpl -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ArrayValueWraps the given value as anArrayValue.Casts this value node to anArrayValue.asRecord()Casts this value node to aRecord.Casts this value node to aSingleValue.clone()Returns a deep copy of this value node.static ValueNode<?> static ValueNode<?> Converts the given object to the appropriateValueNodesubtype.Returns the parent node that this node belongs to, ornullif this is a root node.abstract longReturns the estimated size of this value node in bytes, including object overhead.abstract FieldTypegetType()Returns theFieldTypeof this value node.abstract TgetValue()Returns the underlying value held by this node.abstract StringReturns a string representation of the value held by this node.booleanisArray()Returnstrueif this value node is anArrayValue.booleanReturnstrueif this value node is not anArrayValue.booleanReturnstrueif this node does not contain a null value.booleanReturnstrueif this value node is not aRecord.booleanReturnstrueif this value node is not aSingleValue.booleanisNull()Returnstrueif this node contains a null value.booleanisRecord()Returnstrueif this value node is aRecord.booleanReturnstrueif this value node is aSingleValue.booleanReturnstrueif this node is a ValueNode (Record, ArrayValue, or SingleValue).static SingleValuestatic SingleValueprotected NodesetParentNode(Node parentNode) Sets the parent node of this value node.abstract StringtoJson()Serializes this value node to a JSON string.abstract StringtoXml()Serializes this value node to an XML string.Methods inherited from class com.northconcepts.datapipeline.core.Node
assertNotAncestorOf, containsSessionProperty, containsSessionProperty, containsSessionProperty, copySessionPropertiesFrom, getNodeDepth, getNodeType, getParentField, getParentRecord, getSessionProperty, getSessionProperty, getSessionProperty, hasChildNodes, hasChildRecords, isAncestorOf, isChildNode, keySet, removeChildNode, removeSessionProperties, setSessionProperty, setSessionProperty, setSessionProperty, toStringMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareTo
-
Constructor Details
-
ValueNode
protected ValueNode()
-
-
Method Details
-
getType
Returns theFieldTypeof this value node. ForSingleValue, this is the type of the contained value. ForArrayValue, the type is derived from its elements or its default type. ForRecord, the type is alwaysFieldType.RECORD.- Returns:
- the field type of this value node, never
null
-
getParentNode
Returns the parent node that this node belongs to, ornullif this is a root node.- Specified by:
getParentNodein classNode- Returns:
- the parent
Nodethat this value node belongs to, ornullif this is a root node
-
setParentNode
Sets the parent node of this value node. If a parent was previously assigned and differs from the new parent, this node is first removed from the old parent. Circular references are detected and will cause aDataException.- Parameters:
parentNode- the new parent node, ornullto detach from the current parent- Returns:
- this value node
-
isValueNode
public boolean isValueNode()Returnstrueif this node is a ValueNode (Record, ArrayValue, or SingleValue).Always returns
truefor allValueNodesubclasses (SingleValue,Record, andArrayValue).- Overrides:
isValueNodein classNode- Returns:
true
-
isArray
public boolean isArray()Returnstrueif this value node is anArrayValue.- Returns:
trueif this is an array,falseotherwise- See Also:
-
isNotArray
public boolean isNotArray()Returnstrueif this value node is not anArrayValue.- Returns:
trueif this is not an array,falseotherwise- See Also:
-
isRecord
public boolean isRecord()Returnstrueif this value node is aRecord.- Returns:
trueif this is a record,falseotherwise- See Also:
-
isNotRecord
public boolean isNotRecord()Returnstrueif this value node is not aRecord.- Returns:
trueif this is not a record,falseotherwise- See Also:
-
isSingleValue
public boolean isSingleValue()Returnstrueif this value node is aSingleValue.- Returns:
trueif this is a single value,falseotherwise- See Also:
-
isNotSingleValue
public boolean isNotSingleValue()Returnstrueif this value node is not aSingleValue.- Returns:
trueif this is not a single value,falseotherwise- See Also:
-
clone
Returns a deep copy of this value node. -
getValue
Returns the underlying value held by this node. ForSingleValue, this is the wrapped object. ForArrayValue, this returns the array itself. ForRecord, this returns the record itself.- Returns:
- the value, or
nullif this node holds a null value
-
getValueAsString
Returns a string representation of the value held by this node.- Returns:
- the value as a string, or
"null"if the value isnull
-
isNull
public boolean isNull()Returnstrueif this node contains a null value. In concrete terms, onlyFieldandSingleValuecan contain nulls while not being null themselves. BothRecordandArrayValuewill returnfalseeven if they have no values or null only values.Returns
trueifgetValue()returnsnull. -
isNotNull
public boolean isNotNull()Returnstrueif this node does not contain a null value. In concrete terms, onlyFieldandSingleValuecan contain nulls while not being null themselves. BothRecordandArrayValuewill returntrueeven if they have no values or null only values.Returns
trueifgetValue()does not returnnull. -
getSizeInBytes
public abstract long getSizeInBytes()Returns the estimated size of this value node in bytes, including object overhead.- Returns:
- the size in bytes
-
nullValue
- Returns:
- a new null-valued
SingleValue
-
nullValue
- Parameters:
type- the field type to assign to the null value- Returns:
- a new null-valued
SingleValueof the given type
-
from
Converts the given object to the appropriateValueNodesubtype. The conversion rules are:nullreturns a null-valuedSingleValuewith anFieldType.UNDEFINEDtypeValueNodeinstances are returned as-isIterableinstances are wrapped in anArrayValue- Java arrays (except
byte[]) are wrapped in anArrayValue - All other objects are wrapped in a
SingleValue
- Parameters:
value- the object to convert, may benull- Returns:
- the corresponding
ValueNode, nevernull - See Also:
-
from
Converts the given object to the appropriateValueNodesubtype with an explicitFieldTypehint. The hint can benullto rely on automatic type detection. The conversion rules are:nullreturns a null-valuedSingleValueof the given typeValueNodeinstances are returned as-isIterableinstances are wrapped in anArrayValuewith the given default type- Java arrays (except
byte[]) are wrapped in anArrayValuewith the given default type Moment,InputStream,Reader,LocalDateTime,LocalDate,LocalTime, andInstantvalues are converted before being wrapped in aSingleValue- All other objects are wrapped in a
SingleValue
- Parameters:
type- the explicit field type hint, ornullto infer the typevalue- the object to convert, may benull- Returns:
- the corresponding
ValueNode, nevernull - Throws:
DataException- if the value cannot be converted
-
asArray
Wraps the given value as anArrayValue. If the value is already anArrayValue, it is returned as-is. If it is a differentValueNode, its underlying value is extracted first. Anullvalue produces a single-element array containing a typed null.- Parameters:
type- the default field type for the resulting arrayvalue- the value to wrap, may benull- Returns:
- an
ArrayValuecontaining the given value
-
asSingleValue
Casts this value node to aSingleValue. This is a convenience method that avoids explicit casting in client code.- Returns:
- this value node cast to
SingleValue - Throws:
ClassCastException- if this value node is not aSingleValue- See Also:
-
asRecord
Casts this value node to aRecord. This is a convenience method that avoids explicit casting in client code.- Returns:
- this value node cast to
Record - Throws:
ClassCastException- if this value node is not aRecord- See Also:
-
asArrayValue
Casts this value node to anArrayValue. This is a convenience method that avoids explicit casting in client code.- Returns:
- this value node cast to
ArrayValue - Throws:
ClassCastException- if this value node is not anArrayValue- See Also:
-
toJson
Serializes this value node to a JSON string.- Returns:
- the JSON representation
-
toXml
Serializes this value node to an XML string.- Returns:
- the XML representation
-