Class SingleValue
java.lang.Object
com.northconcepts.datapipeline.core.Node
com.northconcepts.datapipeline.core.ValueNode<Object>
com.northconcepts.datapipeline.core.SingleValue
- All Implemented Interfaces:
Session,Serializable,Cloneable,Comparable<ValueNode<Object>>
SingleValue is an immutable
ValueNode that holds a single scalar value (or null).
The value's type is tracked by a FieldType that is either explicitly specified or inferred
from the value's Java class at construction time.- 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
ConstructorsModifierConstructorDescriptionprotectedSingleValue(FieldType type, Object value) Creates a value of the given type; a null type is inferred from the value's class (FieldType.UNDEFINEDif unknown or null).protectedSingleValue(Object value) Creates a value whose type is inferred from its class (FieldType.UNDEFINEDif unknown or null). -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a deep copy of this single value.intCompares this single value to another by their underlying values using natural ordering.intCompares this single value to another by their underlying values, optionally using the specifiedCollatorfor string comparisons.booleanIndicates whether the given object is aSingleValuewith an equal underlying value.Returns the concreteNode.NodeTypeof this node.longReturns the estimated size of this value node in bytes, including object overhead.getType()Returns theFieldTypeof this value node.getValue()Returns the underlying value held by this node.Returns the value as aBigDecimal.Returns the value as aBigInteger.booleanReturns the value as aboolean.byteReturns the value as abyte.byte[]Returns the value as abyte[].charReturns the value as achar.Returns the value as aDate.Returns the value as aDate(datetime).doubleReturns the value as adouble.floatReturns the value as afloat.Returns the value as anInstant.intReturns the value as anint.Returns the value as aLocalDate.Returns the value as aLocalDateTimeusing the system default time zone.Returns the value as aLocalTime.longReturns the value as along.shortReturns the value as ashort.Returns a string representation of the value held by this node.Returns the value as aTime.Returns the value as aUUID.booleanReturnstrueif this node contains any sub nodes.booleanReturnstrueif this node contains any descendant, record nodes.inthashCode()Returns a hash code based on the underlying value.booleanisArray()Returnstrueif this value node is anArrayValue.booleanisRecord()Returnstrueif this value node is aRecord.booleanReturnstrueif this value node is aSingleValue.protected voidremoveChildNode(Node child) Detaches the given child (matched by identity) from this node; called when the child is moved to another parent.toJson()Serializes this value node to a JSON string.toString()Returns a string representation of this value, truncated toField.MAX_DISPLAY_STRINGcharacters if necessary.toXml()Serializes this value node to an XML string.Methods inherited from class com.northconcepts.datapipeline.core.ValueNode
asArray, asArrayValue, asRecord, asSingleValue, from, from, getParentNode, isNotArray, isNotNull, isNotRecord, isNotSingleValue, isNull, isValueNode, nullValue, nullValue, setParentNodeMethods inherited from class com.northconcepts.datapipeline.core.Node
assertNotAncestorOf, containsSessionProperty, containsSessionProperty, containsSessionProperty, copySessionPropertiesFrom, getNodeDepth, getParentField, getParentRecord, getSessionProperty, getSessionProperty, getSessionProperty, isAncestorOf, isChildNode, keySet, removeSessionProperties, setSessionProperty, setSessionProperty, setSessionProperty
-
Constructor Details
-
SingleValue
Creates a value of the given type; a null type is inferred from the value's class (FieldType.UNDEFINEDif unknown or null). -
SingleValue
Creates a value whose type is inferred from its class (FieldType.UNDEFINEDif unknown or null).
-
-
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. -
getNodeType
Returns the concreteNode.NodeTypeof this node.- Specified by:
getNodeTypein classNode- Returns:
Node.NodeType.SINGLE_VALUE
-
hasChildNodes
public boolean hasChildNodes()Returnstrueif this node contains any sub nodes.Always returns
falsesince a single value has no child nodes.- Specified by:
hasChildNodesin classNode
-
hasChildRecords
public boolean hasChildRecords()Returnstrueif this node contains any descendant, record nodes.Always returns
falsesince a single value cannot contain records.- Specified by:
hasChildRecordsin classNode
-
removeChildNode
Description copied from class:NodeDetaches the given child (matched by identity) from this node; called when the child is moved to another parent.- Specified by:
removeChildNodein classNode
-
isArray
public boolean isArray() -
isRecord
public boolean isRecord() -
isSingleValue
public boolean isSingleValue()- Overrides:
isSingleValuein classValueNode<Object>- Returns:
trueif this is a single value,falseotherwise- See Also:
-
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. -
getValueAsString
Returns a string representation of the value held by this node.- Specified by:
getValueAsStringin classValueNode<Object>- Returns:
- the value formatted as a string using the rules of its
FieldType
-
getValueAsDatetime
Returns the value as aDate(datetime).- Returns:
- the datetime value
- Throws:
ClassCastException- if the value is not aDate
-
getValueAsDate
Returns the value as aDate. If the underlying type isFieldType.DATETIME, the value is converted; otherwise the value is cast directly.- Returns:
- the date value, or
nullif the value is null - Throws:
ClassCastException- if the value cannot be converted to aDate
-
getValueAsTime
Returns the value as aTime. If the underlying type isFieldType.DATETIME, the value is converted; otherwise the value is cast directly.- Returns:
- the time value, or
nullif the value is null - Throws:
ClassCastException- if the value cannot be converted to aTime
-
getValueAsInteger
public int getValueAsInteger()Returns the value as anint.- Returns:
- the integer value
- Throws:
ClassCastException- if the value is not aNumberNullPointerException- if the value isnull
-
getValueAsLong
public long getValueAsLong()Returns the value as along.- Returns:
- the long value
- Throws:
ClassCastException- if the value is not aNumberNullPointerException- if the value isnull
-
getValueAsShort
public short getValueAsShort()Returns the value as ashort.- Returns:
- the short value
- Throws:
ClassCastException- if the value is not aNumberNullPointerException- if the value isnull
-
getValueAsByte
public byte getValueAsByte()Returns the value as abyte.- Returns:
- the byte value
- Throws:
ClassCastException- if the value is not aNumberNullPointerException- if the value isnull
-
getValueAsBoolean
public boolean getValueAsBoolean()Returns the value as aboolean.- Returns:
- the boolean value
- Throws:
ClassCastException- if the value is not aBooleanNullPointerException- if the value isnull
-
getValueAsChar
public char getValueAsChar()Returns the value as achar.- Returns:
- the character value
- Throws:
NullPointerException- if the value isnull
-
getValueAsDouble
public double getValueAsDouble()Returns the value as adouble.- Returns:
- the double value
- Throws:
ClassCastException- if the value is not aNumberNullPointerException- if the value isnull
-
getValueAsFloat
public float getValueAsFloat()Returns the value as afloat.- Returns:
- the float value
- Throws:
ClassCastException- if the value is not aNumberNullPointerException- if the value isnull
-
getValueAsBytes
public byte[] getValueAsBytes()Returns the value as abyte[].- Returns:
- the byte array value
- Throws:
ClassCastException- if the value is not abyte[]
-
getValueAsBigDecimal
Returns the value as aBigDecimal.- Returns:
- the big decimal value
- Throws:
ClassCastException- if the value is not aNumber
-
getValueAsBigInteger
Returns the value as aBigInteger.- Returns:
- the big integer value
- Throws:
ClassCastException- if the value is not aNumber
-
getValueAsInstant
Returns the value as anInstant.- Returns:
- the instant value, or
nullif the value is null
-
getValueAsLocalDateTime
Returns the value as aLocalDateTimeusing the system default time zone.- Returns:
- the local date-time value, or
nullif the value is null
-
getValueAsLocalDate
Returns the value as aLocalDate.- Returns:
- the local date value, or
nullif the value is null
-
getValueAsLocalTime
Returns the value as aLocalTime.- Returns:
- the local time value, or
nullif the value is null
-
getValueAsUuid
Returns the value as aUUID.- Returns:
- the UUID value, or
nullif the value is null - Throws:
ClassCastException- if the value is not aUUID
-
getSizeInBytes
public long getSizeInBytes()Returns the estimated size of this value node in bytes, including object overhead.- Specified by:
getSizeInBytesin classValueNode<Object>- Returns:
- the size in bytes
-
compareTo
Compares this single value to another by their underlying values using natural ordering.- Parameters:
o- the other value node to compare to- Returns:
- a negative integer, zero, or a positive integer as this value is less than, equal to, or greater than the other
-
compareTo
Compares this single value to another by their underlying values, optionally using the specifiedCollatorfor string comparisons.- Parameters:
o- the other value node to compare tocollator- the collator to use for string comparisons, ornullfor natural ordering- Returns:
- a negative integer, zero, or a positive integer as this value is less than, equal to, or greater than the other
-
equals
Indicates whether the given object is aSingleValuewith an equal underlying value. -
hashCode
public int hashCode()Returns a hash code based on the underlying value. -
clone
Returns a deep copy of this single value.- Specified by:
clonein classValueNode<Object>- Returns:
- a new
SingleValuewith the same type and value
-
toJson
Description copied from class:ValueNodeSerializes this value node to a JSON string. -
toXml
Description copied from class:ValueNodeSerializes this value node to an XML string. -
toString
Returns a string representation of this value, truncated toField.MAX_DISPLAY_STRINGcharacters if necessary.
-