Class Field
java.lang.Object
com.northconcepts.datapipeline.core.Node
com.northconcepts.datapipeline.core.Field
- All Implemented Interfaces:
Session,ValueNodeContainer,Serializable,Comparable<Field>
public final class Field
extends Node
implements ValueNodeContainer, Comparable<Field>, Serializable
Field holds persistent key-value data as part of a record. Values in a field can be:
- Single values (boolean, date, string, etc. -- see )
- 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
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a typednullvalue to this container.Adds a value to this field, converting the value to the appropriate type if necessary.Adds a value to this container, inferring theFieldTypefrom the value's class.intCompares this field to another by their values using natural ordering.intCompares this field to another by their values, optionally using the specifiedCollatorfor string comparisons.Copies all properties (name, value, and session properties) from the specified field into this one.Copies properties from the specified field into this one.booleanIndicates whether the given object is aFieldwith an equal value.booleanConverts this field's value to an array if it's not already one, otherwise no change is made.intgetIndex()Returns the position of this field within its record.getName()Returns this field's name.getName(boolean nullToDefaultName) Returns this field's name.Returns the concreteNode.NodeTypeof this node.Returns the parent node that this node belongs to, ornullif this is a root node.Returns the closest parent record that this node is the child of, otherwise null if one does not exist.Returns the record this field belongs to.longReturns the estimated size of this field in bytes, including object overhead and value size.longReturns the estimated size of this field's name in bytes, including object overhead.getType()Returns theFieldTypeof this field's value.getValue()Returns the raw value held by this field, ornullif the field has no value or is null.Retrieve the field's value as anArrayValue.getValueAsArray(boolean force) Retrieve the field's value as anArrayValue.Returns this field's value as aBigDecimal.Returns this field's value as aBigInteger.booleanReturns this field's value as aboolean.byteReturns this field's value as abyte.byte[]Returns this field's value as abyte[].charReturns this field's value as achar.Returns this field's value as aDate.Returns this field's value as aDate(datetime).doubleReturns this field's value as adouble.floatReturns this field's value as afloat.Returns this field's value as anInstant.intReturns this field's value as anint.<T> List<T> getValueAsList(boolean force, Class<T> elementType) Retrieve the field's value as aList.Returns this field's value as aLocalDate.Returns this field's value as aLocalDateTime.Returns this field's value as aLocalTime.longReturns this field's value as along.Returns this field's value cast to aRecord.shortReturns this field's value as ashort.Returns this field's value cast to aSingleValue.Returns this field's value as aString.Returns this field's value as aTime.Returns this field's value as aUUID.ValueNode<?> Returns theValueNodebacking this field's value, ornullif no value has been set.booleanReturnstrueif this node contains any sub nodes.booleanReturnstrueif this node contains any descendant, record nodes.inthashCode()Returns a hash code based on this field's value.booleanhasValue()Returnstrueif this field has been set to a value, includingnull.booleanisArray()Returnstrueif this field's value is anArrayValue.booleanReturnstrueif this field's value is not anArrayValue.booleanReturnstrueif this node does not contain a null value.booleanReturnstrueif this field's value is not aRecord.booleanReturnstrueif this field's value is not aSingleValue.booleanisNull()Returnstrueif this node contains a null value.booleanisRecord()Returnstrueif this field's value is aRecord.booleanReturnstrueif this field's value is aSingleValue.booleanReturnstrueif this field has never had a value assigned.booleanReturnstrueif this field has had a value assigned (including anullvalue).booleanremove()Removes this field from its parent record.protected voidremoveChildNode(Node child) Detaches the given child (matched by identity) from this node; called when the child is moved to another parent.Sets the name of this field.Sets this field's value to null with the given type; a nulltypekeeps the type of the value it replaces.setValue(boolean value) Sets this field's value to the specified boolean.setValue(byte value) Sets this field's value to the specified byte.setValue(byte[] value) Sets this field's value to the specified byte array (blob).setValue(char value) Sets this field's value to the specified character.setValue(double value) Sets this field's value to the specified double.setValue(float value) Sets this field's value to the specified float.setValue(int value) Sets this field's value to the specified integer.setValue(long value) Sets this field's value to the specified long.setValue(short value) Sets this field's value to the specified short.Sets this field's value to the specifiedRecord.Sets this field's value, inferring theFieldTypefrom the value's class.Sets this field's value to the specified string.setValue(BigDecimal value) Sets this field's value to the specifiedBigDecimal.setValue(BigInteger value) Sets this field's value to the specifiedBigInteger.Sets this field's value to the specified date.Sets this field's value to the specified time.setValue(LocalDateTime value) Sets this field's value to the specifiedLocalDateTime, converting it to aDateusing the system default time zone.Sets this field's value to the specified datetime.Sets this field's value to the specifiedUUID.toString()Returns a human-readable string representation of this field, including its name, type, and value.Methods inherited from class com.northconcepts.datapipeline.core.Node
assertNotAncestorOf, containsSessionProperty, containsSessionProperty, containsSessionProperty, copySessionPropertiesFrom, getNodeDepth, getParentField, getSessionProperty, getSessionProperty, getSessionProperty, isAncestorOf, isChildNode, isValueNode, keySet, removeSessionProperties, setSessionProperty, setSessionProperty, setSessionProperty
-
Field Details
-
MAX_DISPLAY_STRING
public static final int MAX_DISPLAY_STRING- See Also:
-
JAVA_OBJECT_SIZE
public static final int JAVA_OBJECT_SIZE- See Also:
-
JAVA_ARRAY_SIZE
public static final int JAVA_ARRAY_SIZE- See Also:
-
-
Constructor Details
-
Field
-
-
Method Details
-
getNodeType
Returns the concreteNode.NodeTypeof this node.- Specified by:
getNodeTypein classNode- Returns:
Node.NodeType.FIELD
-
hasChildNodes
public boolean hasChildNodes()Returnstrueif this node contains any sub nodes.Returns
trueif this field has a non-null value that itself contains child nodes.- Specified by:
hasChildNodesin classNode
-
hasChildRecords
public boolean hasChildRecords()Returnstrueif this node contains any descendant, record nodes.Returns
trueif this field's value is aRecordor contains descendant 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
-
copyFrom
Copies all properties (name, value, and session properties) from the specified field into this one.- Parameters:
field- the source field to copy from- Returns:
- this field for method chaining
-
copyFrom
Copies properties from the specified field into this one. IfcopyNameistrue, the name is also copied; otherwise only the value and session properties are copied.- Parameters:
field- the source field to copy fromcopyName-trueto copy the field name as well- Returns:
- this field for method chaining
-
toString
Returns a human-readable string representation of this field, including its name, type, and value. -
remove
public boolean remove()Removes this field from its parent record.- Returns:
trueif the record contained this field (i.e. the field hadn't already been removed).
-
getIndex
public int getIndex()Returns the position of this field within its record. -
getName
Returns this field's name. If the name has not been explicitly set, a default name is generated based on the field's position within its record.- Returns:
- the field name, never
null
-
getName
Returns this field's name. IfnullToDefaultNameistrueand the name has not been explicitly set, a default name is generated based on the field's position. Iffalse,nullmay be returned when no name has been set.- Parameters:
nullToDefaultName- whether to generate a default name when none has been set- Returns:
- the field name, or
nullif no name is set andnullToDefaultNameisfalse
-
setName
Sets the name of this field.- Parameters:
name- the new field name- Returns:
- this field for method chaining
-
getType
Returns theFieldTypeof this field's value. If no value has been set, returnsFieldType.STRINGas the default.- Returns:
- the field type
-
isArray
public boolean isArray()Returnstrueif this field's value is anArrayValue.- Returns:
trueif the value is an array
-
isNotArray
public boolean isNotArray()Returnstrueif this field's value is not anArrayValue.- Returns:
trueif the value is not an array
-
isRecord
public boolean isRecord()Returnstrueif this field's value is aRecord.- Returns:
trueif the value is a record
-
isSingleValue
public boolean isSingleValue()Returnstrueif this field's value is aSingleValue.- Returns:
trueif the value is a single value
-
isNotSingleValue
public boolean isNotSingleValue()Returnstrueif this field's value is not aSingleValue.- Returns:
trueif the value is not a single value
-
isNotRecord
public boolean isNotRecord()Returnstrueif this field's value is not aRecord.- Returns:
trueif the value is not a record
-
forceValueAsArray
Converts this field's value to an array if it's not already one, otherwise no change is made. -
isValueSet
public boolean isValueSet()Returnstrueif this field has had a value assigned (including anullvalue). A field that has never been assigned returnsfalse.- Returns:
trueif a value has been set
-
isValueNotSet
public boolean isValueNotSet()Returnstrueif this field has never had a value assigned.- Returns:
trueif no value has been set
-
hasValue
public boolean hasValue()Returnstrueif this field has been set to a value, includingnull. Otherwise, it returnsfalse. This method is an alias forisValueSet().- Specified by:
hasValuein interfaceValueNodeContainer
-
isNull
public boolean isNull()Description copied from class:NodeReturnstrueif 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. -
isNotNull
public boolean isNotNull()Description copied from class:NodeReturnstrueif 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. -
addValue
Adds a value to this field, converting the value to the appropriate type if necessary.- Specified by:
addValuein interfaceValueNodeContainer- Parameters:
type- the expected type of the valuevalue- the value to add- Returns:
- this field for method chaining
-
setValue
Sets this field's value, inferring theFieldTypefrom the value's class.- Parameters:
value- the value to set, may benull- Returns:
- this field for method chaining
-
addValue
Adds a value to this container, inferring theFieldTypefrom the value's class.- Specified by:
addValuein interfaceValueNodeContainer- Parameters:
value- the value to add, may benull- Returns:
- this container for method chaining
-
setNull
Sets this field's value to null with the given type; a nulltypekeeps the type of the value it replaces. -
addNull
Description copied from interface:ValueNodeContainerAdds a typednullvalue to this container.- Specified by:
addNullin interfaceValueNodeContainer- Parameters:
type- the field type of the null value to add- Returns:
- this container for method chaining
-
compareTo
Compares this field to another by their values using natural ordering.- Specified by:
compareToin interfaceComparable<Field>- Parameters:
field- the other field to compare to- Returns:
- a negative integer, zero, or a positive integer as this field's value is less than, equal to, or greater than the other's
-
compareTo
Compares this field to another by their values, optionally using the specifiedCollatorfor string comparisons.- Parameters:
field- the other field to compare tocollator- the collator for string comparisons, ornullfor natural ordering- Returns:
- a negative integer, zero, or a positive integer as this field's value is less than, equal to, or greater than the other's
-
equals
Indicates whether the given object is aFieldwith an equal value. -
equals
Indicates whether the given object is aFieldwith an equal value, using the specifiedCollatorfor string comparisons.- Parameters:
o- the object to compare withcollator- the collator for string comparisons, ornullfor natural ordering- Returns:
trueif the objects are equal
-
hashCode
public int hashCode()Returns a hash code based on this field's value. -
getSizeOfNameInBytes
public long getSizeOfNameInBytes()Returns the estimated size of this field's name in bytes, including object overhead.- Returns:
- the name size in bytes
-
getSizeInBytes
public long getSizeInBytes()Returns the estimated size of this field in bytes, including object overhead and value size.- Returns:
- the size in bytes
-
getRecord
Returns the record this field belongs to. -
getParentRecord
Description copied from class:NodeReturns the closest parent record that this node is the child of, otherwise null if one does not exist.- Overrides:
getParentRecordin classNode- See Also:
-
getParentNode
Description copied from class:NodeReturns the parent node that this node belongs to, ornullif this is a root node.- Specified by:
getParentNodein classNode- Returns:
- the parent node, or
null
-
getValue
Returns the raw value held by this field, ornullif the field has no value or is null.- Returns:
- the field's value, or
null
-
getValueNode
Returns theValueNodebacking this field's value, ornullif no value has been set.- Returns:
- the value node, or
null
-
getValueAsArray
Retrieve the field's value as anArrayValue. -
getValueAsArray
Retrieve the field's value as anArrayValue. An exception will be thrown when typecasting if the value is not anArrayValue. -
getValueAsList
Retrieve the field's value as aList.- Type Parameters:
T- The list's parameterized element type- Parameters:
force- indicates if a field containing a single value should be forced to become anArrayValueof one element, otherwise, an exception will be thrown when the typecast to ArrayValue fails.elementType- the target Class of the list's elements. This is used internally to coerce the actual value into this desired type.
-
getValueAsRecord
Returns this field's value cast to aRecord.- Returns:
- the record value
- Throws:
ClassCastException- if the value is not aRecord
-
getValueAsSingleValue
Returns this field's value cast to aSingleValue.- Returns:
- the single value
- Throws:
ClassCastException- if the value is not aSingleValue
-
getValueAsString
Returns this field's value as aString.- Returns:
- the string representation of the value, or
nullif the value is null
-
getValueAsDatetime
Returns this field's value as aDate(datetime).- Returns:
- the datetime value, or
nullif the value is null
-
getValueAsDate
Returns this field's value as aDate.- Returns:
- the date value, or
nullif the value is null
-
getValueAsTime
Returns this field's value as aTime.- Returns:
- the time value, or
nullif the value is null
-
getValueAsInteger
public int getValueAsInteger()Returns this field's value as anint.- Returns:
- the integer value
- Throws:
NullPointerException- if the value is null
-
getValueAsLong
public long getValueAsLong()Returns this field's value as along.- Returns:
- the long value
- Throws:
NullPointerException- if the value is null
-
getValueAsShort
public short getValueAsShort()Returns this field's value as ashort.- Returns:
- the short value
- Throws:
NullPointerException- if the value is null
-
getValueAsByte
public byte getValueAsByte()Returns this field's value as abyte.- Returns:
- the byte value
- Throws:
NullPointerException- if the value is null
-
getValueAsBoolean
public boolean getValueAsBoolean()Returns this field's value as aboolean.- Returns:
- the boolean value
- Throws:
NullPointerException- if the value is null
-
getValueAsChar
public char getValueAsChar()Returns this field's value as achar.- Returns:
- the character value
- Throws:
NullPointerException- if the value is null
-
getValueAsDouble
public double getValueAsDouble()Returns this field's value as adouble.- Returns:
- the double value
- Throws:
NullPointerException- if the value is null
-
getValueAsFloat
public float getValueAsFloat()Returns this field's value as afloat.- Returns:
- the float value
- Throws:
NullPointerException- if the value is null
-
getValueAsBytes
public byte[] getValueAsBytes()Returns this field's value as abyte[].- Returns:
- the byte array value, or
nullif the value is null
-
getValueAsBigDecimal
Returns this field's value as aBigDecimal.- Returns:
- the big decimal value, or
nullif the value is null
-
getValueAsBigInteger
Returns this field's value as aBigInteger.- Returns:
- the big integer value, or
nullif the value is null
-
getValueAsInstant
Returns this field's value as anInstant.- Returns:
- the instant value, or
nullif the value is null
-
getValueAsLocalDateTime
Returns this field's value as aLocalDateTime.- Returns:
- the local date-time value, or
nullif the value is null
-
getValueAsLocalDate
Returns this field's value as aLocalDate.- Returns:
- the local date value, or
nullif the value is null
-
getValueAsLocalTime
Returns this field's value as aLocalTime.- Returns:
- the local time value, or
nullif the value is null
-
getValueAsUuid
Returns this field's value as aUUID.- Returns:
- the UUID value, or
nullif the value is null
-
setValue
Sets this field's value to the specified string.- Parameters:
value- the string value, may benull- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified datetime.- Parameters:
value- the datetime value, may benull- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified date.- Parameters:
value- the date value, may benull- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified time.- Parameters:
value- the time value, may benull- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified integer.- Parameters:
value- the integer value- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified long.- Parameters:
value- the long value- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified short.- Parameters:
value- the short value- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified byte.- Parameters:
value- the byte value- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified boolean.- Parameters:
value- the boolean value- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified character.- Parameters:
value- the character value- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified double.- Parameters:
value- the double value- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified float.- Parameters:
value- the float value- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specified byte array (blob).- Parameters:
value- the byte array value, may benull- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specifiedBigDecimal.- Parameters:
value- the big decimal value, may benull- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specifiedBigInteger.- Parameters:
value- the big integer value, may benull- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specifiedRecord.- Parameters:
value- the record value, may benull- Returns:
- this field for method chaining
-
setValue
- Parameters:
value- the instant value, may benull- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specifiedLocalDateTime, converting it to aDateusing the system default time zone.- Parameters:
value- the local date-time value, may benull- Returns:
- this field for method chaining
-
setValue
- Parameters:
value- the local date value, may benull- Returns:
- this field for method chaining
-
setValue
- Parameters:
value- the local time value, may benull- Returns:
- this field for method chaining
-
setValue
Sets this field's value to the specifiedUUID.- Parameters:
value- the UUID value, may benull- Returns:
- this field for method chaining
-