Class Record
- All Implemented Interfaces:
RecordContainer,Session,Serializable,Cloneable,Comparable<ValueNode<Record>>,Iterable<Field>
public final class Record
extends ValueNode<Record>
implements RecordContainer, Cloneable, Serializable, Iterable<Field>
Record holds persistent data in key-value fields as it flows through the pipeline. Values in a field can be:
- Single values (boolean, date, string, etc. -- see
FieldType) - Records
- Array of single values, records, and arrays
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumLists the lifecycle states of a record as it flows through the pipeline.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
ConstructorsConstructorDescriptionRecord()Creates a new empty record with no fields.Creates a new record with the specified field names.Creates a new record by copying the fields from another.Creates a new record with the specified field names. -
Method Summary
Modifier and TypeMethodDescriptionaddField()Adds a new, unnamed field to this record and returns it for further configuration.Adds a new field with the specified value to this record.Adds a new field with the specified value to this record.clone()Returns a deep copy of this value node.intCompares this record to another using the defaultRecordComparator.intcompareTo(Record o, RecordComparator comparator) Compares this record to another using the specifiedRecordComparator, or the default ifnull.intCompares this record to another value node by delegating tocompareTo(Record).booleanDeprecated.booleancontainsField(FieldList fieldNamePath) Returns true if all fields and sub fields in a nested path exists.booleancontainsField(FieldPath path) Indicates if this record contains a matching field for the specified path.booleancontainsField(String fieldName) Returnstrueif this record contains a field with the given name.booleancontainsNonNull(FieldPath path) Deprecated.booleanIndicates if this record contains a field at the specified path that is not null.booleancontainsNonNullField(String fieldPathExpression) Indicates if this record contains a field at the specified path with a non-null value.booleanIndicates if this record contains a field or value at the specified path where the value is not null.booleancontainsValue(FieldPath path) Indicates if this record contains a matching field or value for the specified path.Copy all the fields and child fields from the specified record into this one, creating new unique fields when target fields with the same name already exists (Node.DuplicateNodeAction.APPEND).Copy all the fields and child fields from the specified record into this one.copyFrom(Record sourceRecord, Node.DuplicateNodeAction fieldExistsAction) Copy all the fields and child fields from the specified record into this one.voiddelete()Marks this record asRecord.State.DELETED.voidensureFields(String... fieldNames) Ensures that all specified field names exist in this record, creating any missing ones.voidensureFields(Collection<String> fieldNames) Ensures that all specified field names exist in this record, creating any missing ones.booleanequals(Record o, RecordComparator comparator) Indicates whether this record is equal to another using the specifiedRecordComparator.booleanIndicates whether the given object is aRecordwith equal fields.<T> TEvaluates the given expression string against this record and returns the result.excludeFields(FieldList fields) Removes all fields whose names appear in the given list.excludeFields(Iterable<FieldPath> fieldPaths) Removes all fields matching the givenFieldPathiterable that exist in this record.excludeFields(Set<String> fields) Removes all fields whose names appear in the given set.voidPerforms the given action for each field in this list.static <T extends ValueNode<?>>
TfromBinary(byte[] bytes) Deserializes a record or array from a binary byte array.static <T extends ValueNode<?>>
TfromBinary(DataInput input) Deserializes a record or array from a binary data input.static <T extends ValueNode<?>>
TfromBinary(InputStream inputStream) Deserializes a record or array from a binary input stream.static <T extends ValueNode<?>>
TDeserializes a record or array from a JSON reader.static <T extends ValueNode<?>>
TDeserializes a record or array from a JSON string.static <T extends ValueNode<?>>
TDeserializes a record or array from an XML reader.static <T extends ValueNode<?>>
TDeserializes a record or array from an XML string.longReturns the time in milliseconds when this record was created.getField(int index) Returns the field at the specified index (for zero or positive indexes) or from the end of the list (for negative indexes by adding index to the size of the list).getField(int index, boolean createField) Returns the field at the specified index, creating new fields as needed ifcreateFieldistrue.Retrieves a nested child field.Returns the field at the specifiedFieldPath.Returns the field at the specifiedFieldPath, optionally creating intermediate fields.Returns the field at the specifiedFieldPath, optionally creating intermediate fields.Returns the first field with the given name or throws an exception if none are found.Returns the first field with the given name.intReturns the number of fields in this record.Returns aFieldListcontaining the names of all fields in this record.Returns a list of the field names in this record in order.getFieldOrNull(String fieldName) Returns the first field with the given name or null if none are found.Returns a new collection of the fields in this record.Returns the field types for all fields in this record.getFieldTypes(FieldList fieldList) Returns the field types for the fields matching the givenFieldList, or all fields if the list isnullor empty.<T> TgetFieldValue(FieldPath fieldPath, T defaultValue) Gets the value at the specified field path, returning a default value if the field is null or not found.<T> TgetFieldValue(String fieldPath, T defaultValue) Returns the unconverted value at the givenFieldPathexpression or the default value if it is missing or null.getFieldValueAsArray(String fieldPath, ArrayValue defaultValue) Returns the field's value as array if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsBigDecimal(String fieldPath, BigDecimal defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsBigInteger(String fieldPath, BigInteger defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsBoolean(String fieldPath, Boolean defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsByte(String fieldPath, Byte defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.byte[]getFieldValueAsBytes(String fieldPath, byte[] defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsChar(String fieldPath, Character defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsDate(String fieldPath, Date defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsDatetime(String fieldPath, Date defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsDouble(String fieldPath, Double defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsFloat(String fieldPath, Float defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsInstant(String fieldPath, Instant defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsInteger(String fieldPath, Integer defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.<T> List<T> getFieldValueAsList(String fieldPath, List<T> defaultValue, Class<T> elementType) Returns the field's value as aListif the field exists and its value is not null, otherwise, it returns the default value (even if the list contains no values).getFieldValueAsLocalDate(String fieldPath, LocalDate defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsLocalDatetime(String fieldPath, LocalDateTime defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsLocalTime(String fieldPath, LocalTime defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsLong(String fieldPath, Long defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsRecord(String fieldPath, Record defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsShort(String fieldPath, Short defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsString(String fieldPath, String defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsTime(String fieldPath, Time defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.getFieldValueAsUUID(String fieldPath, UUID defaultValue) Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value.Returns the concreteNode.NodeTypeof this node.Returns theRecordassociated with this container.getSingleValue(FieldPath path, boolean createField, boolean throwException) Returns theSingleValueat the specifiedFieldPath, optionally creating intermediate fields.longReturns the estimated size of this value node in bytes, including object overhead.longReturns the estimated total size of all field names in bytes, including object overhead.getState()Returns the current lifecycle state of this record.getType()Returns theFieldTypeof this value node.getValue()Returns the underlying value held by this node.ValueNode<?> Returns the value node at the specifiedFieldPath.ValueNode<?> Returns the value node at the specifiedFieldPath, optionally creating intermediate fields.ValueNode<?> Returns the value node at the specifiedFieldPath, optionally creating intermediate fields.Returns a string representation of the value held by this node.List<?> Returns all the field values in this record as aList.List<?> Returns the field values in this record as aListfor the fields matching the supplied FieldList.Returns all the field values in this record as anArrayValue.booleanReturnstrueif any field in this record contains anArrayValue.booleanReturnstrueif this node contains any sub nodes.booleanReturnstrueif this node contains any descendant, record nodes.inthashCode()Returns a hash code based on all fields in this record.intReturns a hash code based on the fields matching the givenFieldList, or all fields ifnull.protected intindexOfField(Field field) Returns the 0-based index of this exact field instance (compared by identity) or -1 if it is not in this record.intindexOfField(String fieldName, boolean throwExceptionOnFailure) Returns the index of the first field with the given name, or-1if not found.booleanReturnstrueif this record has been marked for deletion.booleanisEmpty()Returns true if this record has no fields or all field values are null.booleanReturns true if this record has at least one non-null field value.booleanisRecord()Returnstrueif this value node is aRecord.iterator()Returns an iterator over the fields in this record.voidmoveField(int oldIndex, int newIndex) Moves a field from one position to another within this record.voidMoves the field with the specified name to a new position within this record.voidmoveFieldAfter(FieldPath fieldPath, FieldPath afterFieldPath) Moves the field at the specified path to the position immediately after another field path.voidmoveFieldAfter(String fieldName, String afterFieldName) Moves the named field to the position immediately after another named field.voidmoveFieldBefore(FieldPath fieldPath, FieldPath beforeFieldPath) Moves the field at the specified path to the position immediately before another field path.voidmoveFieldBefore(String fieldName, String beforeFieldName) Moves the named field to the position immediately before another named field.Returns a parallel Stream of the fields in this record.protected voidremoveChildNode(Node child) Detaches the given child (matched by identity) from this node; called when the child is moved to another parent.removeField(int index) Removes and returns the field at the specified index.protected booleanremoveField(Field field) Removes this exact field instance (compared by identity); returns false if it is not in this record.removeField(FieldList fieldNamePath) Removes a sub-field matching the specified path.removeField(FieldPath fieldPath) Deletes the field at the specified path or throws an exception if it doesn't exist.removeField(String columnName) Removes and returns the field with the specified name.removeFields(Collection<FieldPath> fieldPaths) Removes all fields matching the given collection ofFieldPathexpressions.selectFields(FieldList fields) Retains only the fields specified in the given list, removing all others and reordering to match the list's order.selectFields(FieldList fields, boolean lenient) Retains only the fields specified in the given list, removing all others.voidsetAlive()Resets this record's state toRecord.State.ALIVE.Sets the value at the specifiedFieldPath.Sets the value at the specifiedFieldPath, creating intermediate fields as needed.Sets the value of the field with the given name, creating the field if necessary.setFieldNull(FieldPath fieldPath, FieldType type) Sets the field at the specifiedFieldPathto a typednullvalue, creating intermediate fields as needed.setFieldNull(String fieldName, FieldType type) Sets the field with the given name to a typednullvalue, creating the field if necessary.protected RecordsetParentNode(Node parentNode) Sets the parent node of this value node.Sorts the fields in this record alphabetically by name.stream()Returns a sequential Stream of the fields in this record.byte[]toBinary()Serializes this record to a binary byte array.static byte[]Serializes the given record or array to a binary byte array.static voidtoBinary(ValueNode<?> recordOrArray, DataOutput output) Serializes the given record or array as binary data to the specified data output.static voidtoBinary(ValueNode<?> recordOrArray, OutputStream outputStream) Serializes the given record or array as binary data to the specified output stream.toJson()Serializes this record to a JSON string.toJson(boolean pretty) Serializes this record to a JSON string, optionally pretty-printed.static StringSerializes the given record or array to a JSON string.static StringSerializes the given record or array to a JSON string, optionally pretty-printed.static voidSerializes the given record or array as JSON to the specified writer.static voidSerializes the given record or array as JSON to the specified writer, optionally pretty-printed.toString()Returns a human-readable string representation of this node and its contents.toXml()Serializes this record to an XML string.toXml(boolean writeRootDocument, boolean pretty) Serializes this record to an XML string with control over the root document and formatting.static StringSerializes the given record or array to an XML string.static StringSerializes the given record or array to an XML string with control over the root document and formatting.static voidWrites the record or array as unindented XML inside a<document>root element; the writer is flushed but left open.static voidWrites the record or array as XML, inside a<document>root element ifwriteRootDocumentand indented ifpretty; the writer is flushed but left open.Methods inherited from class com.northconcepts.datapipeline.core.ValueNode
asArray, asArrayValue, asRecord, asSingleValue, from, from, getParentNode, isArray, isNotArray, isNotNull, isNotRecord, isNotSingleValue, isNull, isSingleValue, isValueNode, nullValue, nullValueMethods 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, setSessionPropertyMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
spliterator
-
Constructor Details
-
Record
Creates a new record by copying the fields from another.- Parameters:
record- the record to copy from.
-
Record
public Record()Creates a new empty record with no fields. -
Record
Creates a new record with the specified field names.- Parameters:
fieldNames-
-
Record
Creates a new record with the specified field names.- Parameters:
fieldNames-
-
-
Method Details
-
getRecord
Returns theRecordassociated with this container.- Specified by:
getRecordin interfaceRecordContainer- Returns:
- this record
-
iterator
Returns an iterator over the fields in this record. -
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.- Specified by:
getTypein classValueNode<Record>- Returns:
FieldType.RECORD
-
getNodeType
Returns the concreteNode.NodeTypeof this node.- Specified by:
getNodeTypein classNode- Returns:
Node.NodeType.RECORD
-
hasChildNodes
public boolean hasChildNodes()Returnstrueif this node contains any sub nodes.- Specified by:
hasChildNodesin classNode
-
hasChildRecords
public boolean hasChildRecords()Returnstrueif this node contains any descendant, record nodes.- 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
-
isRecord
public boolean isRecord() -
hasArrayFields
public boolean hasArrayFields()Returnstrueif any field in this record contains anArrayValue.- Returns:
trueif at least one field is an array
-
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 this
Recordinstance (records are self-referencing values). -
getValueAsString
Returns a string representation of the value held by this node.- Specified by:
getValueAsStringin classValueNode<Record>- Returns:
- the value as a string, or
"null"if the value isnull
-
copyFrom
Copy all the fields and child fields from the specified record into this one.- Parameters:
sourceRecord- the record to copy from.fieldExistsAction- the action to take if a field with the same name already exists in this record.- Returns:
- this record.
-
copyFrom
Copy all the fields and child fields from the specified record into this one.- Parameters:
record- the record to copy from.overwriteFields- indicates if existing target fields should be replaced (Node.DuplicateNodeAction.OVERWRITE) or a new unique field created (Node.DuplicateNodeAction.APPEND).- Returns:
- this record.
-
copyFrom
Copy all the fields and child fields from the specified record into this one, creating new unique fields when target fields with the same name already exists (Node.DuplicateNodeAction.APPEND).- Parameters:
record- the record to copy from.- Returns:
- this record.
-
clone
Description copied from class:ValueNodeReturns a deep copy of this value node. -
getState
Returns the current lifecycle state of this record.- Returns:
- the record state, never
null
-
isDeleted
public boolean isDeleted()Returnstrueif this record has been marked for deletion.- Returns:
trueif the state isRecord.State.DELETED
-
setAlive
public void setAlive()Resets this record's state toRecord.State.ALIVE. -
delete
public void delete()Marks this record asRecord.State.DELETED. Deleted records are typically filtered out by the pipeline and not written to the output. -
getCreatedOn
public long getCreatedOn()Returns the time in milliseconds when this record was created. -
getField
Returns the field at the specified index (for zero or positive indexes) or from the end of the list (for negative indexes by adding index to the size of the list). -
getField
Returns the field at the specified index, creating new fields as needed ifcreateFieldistrue.- Parameters:
index- the field indexcreateField- iftrue, empty fields are appended until the index is valid- Returns:
- the field at the specified index
-
getField
Returns the first field with the given name or throws an exception if none are found. Special characters are not parsed and instead treated as part of the field name. -
getFieldOrNull
Returns the first field with the given name or null if none are found. Special characters are not parsed and instead treated as part of the field name. -
getField
Returns the first field with the given name. IfcreateFieldistrueand no matching field exists, a new field with the specified name is created and returned.- Parameters:
fieldName- the field name to look upcreateField- iftrue, create the field when not found- Returns:
- the matching or newly created field
- Throws:
DataException- ifcreateFieldisfalseand no matching field exists
-
getField
Returns the field at the specifiedFieldPath.- Parameters:
path- the path expression identifying the field- Returns:
- the field
- Throws:
DataException- if the path does not resolve to a field
-
getField
Returns the field at the specifiedFieldPath, optionally creating intermediate fields.- Parameters:
path- the path expression identifying the fieldcreateField- iftrue, intermediate fields and records are created as needed- Returns:
- the field
- Throws:
DataException- if the path does not resolve andcreateFieldisfalse
-
getField
Returns the field at the specifiedFieldPath, optionally creating intermediate fields.- Parameters:
path- the path expression identifying the fieldcreateField- iftrue, intermediate fields and records are created as neededthrowException- iftrue, an exception is thrown when the path does not resolve- Returns:
- the field, or
nullif not found andthrowExceptionisfalse
-
getValue
Returns the value node at the specifiedFieldPath.- Parameters:
path- the path expression- Returns:
- the value node
- Throws:
DataException- if the path does not resolve
-
getValue
Returns the value node at the specifiedFieldPath, optionally creating intermediate fields.- Parameters:
path- the path expressioncreateField- iftrue, intermediate fields and records are created as needed- Returns:
- the value node
- Throws:
DataException- if the path does not resolve and creation is not requested
-
getValue
Returns the value node at the specifiedFieldPath, optionally creating intermediate fields.- Parameters:
path- the path expression identifying the fieldcreateField- iftrue, intermediate fields and records are created as neededthrowException- iftrue, an exception is thrown when the path does not resolve- Returns:
- the value node, or
nullif not found andthrowExceptionisfalse
-
getSingleValue
Returns theSingleValueat the specifiedFieldPath, optionally creating intermediate fields.- Parameters:
path- the path expressioncreateField- iftrue, intermediate fields and records are created as neededthrowException- iftrue, an exception is thrown when the path does not resolve- Returns:
- the single value, or
nullif not found andthrowExceptionisfalse
-
getField
Retrieves a nested child field. IfcreateFieldis true, all missing intermediate records will be created, otherwise an exception will be thrown. This method will fail if an intermediate field has a non-record, non-null value. -
setField
Sets the value of the field with the given name, creating the field if necessary.- Parameters:
fieldName- the field namevalue- the value to set- Returns:
- this record for method chaining
-
setField
public Record setField(FieldPath fieldPath, boolean createField, boolean throwException, Object value) Sets the value at the specifiedFieldPath.- Parameters:
fieldPath- the path expressioncreateField- iftrue, intermediate fields and records are created as neededthrowException- iftrue, an exception is thrown when the path does not resolvevalue- the value to set- Returns:
- this record for method chaining
-
setField
Sets the value at the specifiedFieldPath, creating intermediate fields as needed.- Parameters:
fieldPath- the path expressionvalue- the value to set- Returns:
- this record for method chaining
-
setFieldNull
Sets the field with the given name to a typednullvalue, creating the field if necessary.- Parameters:
fieldName- the field nametype- the field type of the null value- Returns:
- this record for method chaining
-
setFieldNull
Sets the field at the specifiedFieldPathto a typednullvalue, creating intermediate fields as needed.- Parameters:
fieldPath- the path expressiontype- the field type of the null value- Returns:
- this record for method chaining
-
addField
Adds a new field with the specified value to this record. If a field with this name already exists,arrayFielddetermines if the existing field should be promoted to an array and the new value added to it, otherwise, a unique name is created for the new value by appending a number to the name starting with 1 until an unused name is found. -
addField
Adds a new field with the specified value to this record. If a field with this name already exists, this method searches for an unused name by appending an numeric offset starting with 1. -
getFieldCount
public int getFieldCount()Returns the number of fields in this record.- Returns:
- the field count
-
addField
Adds a new, unnamed field to this record and returns it for further configuration.- Returns:
- the newly created field
-
getFields
Returns a new collection of the fields in this record. The collection is not connected to this record and can be freely modified, however, the fields are the same instances in this record. -
forEach
Performs the given action for each field in this list. -
stream
Returns a sequential Stream of the fields in this record. -
parallelStream
Returns a parallel Stream of the fields in this record. -
getFieldNames
Returns a list of the field names in this record in order.- Returns:
- the field names
-
getFieldNameList
Returns aFieldListcontaining the names of all fields in this record.- Returns:
- the field name list
-
getFieldTypes
Returns the field types for the fields matching the givenFieldList, or all fields if the list isnullor empty.- Parameters:
fieldList- the fields to include, ornullfor all- Returns:
- the list of field types
-
getFieldTypes
Returns the field types for all fields in this record.- Returns:
- the list of field types
-
getValues
Returns the field values in this record as aListfor the fields matching the supplied FieldList. This method does not traverse nested records and nested arrays. -
getValues
Returns all the field values in this record as aList. This method does not traverse nested records and nested arrays. -
getValuesAsArray
Returns all the field values in this record as anArrayValue. This method does not traverse nested records and nested arrays. -
setParentNode
Description copied from class:ValueNodeSets 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.- Overrides:
setParentNodein classValueNode<Record>- Parameters:
parentNode- the new parent node, ornullto detach from the current parent- Returns:
- this value node
-
compareTo
Compares this record to another value node by delegating tocompareTo(Record).- Specified by:
compareToin interfaceComparable<ValueNode<Record>>- Parameters:
o- the other value node- Returns:
- a negative integer, zero, or a positive integer
-
compareTo
Compares this record to another using the defaultRecordComparator.- Parameters:
o- the other record- Returns:
- a negative integer, zero, or a positive integer
-
compareTo
Compares this record to another using the specifiedRecordComparator, or the default ifnull.- Parameters:
o- the other recordcomparator- the comparator to use, ornullfor the default- Returns:
- a negative integer, zero, or a positive integer
-
equals
Indicates whether the given object is aRecordwith equal fields. -
equals
Indicates whether this record is equal to another using the specifiedRecordComparator.- Parameters:
o- the other recordcomparator- the comparator to use, ornullfor the default- Returns:
trueif the records are equal
-
hashCode
public int hashCode()Returns a hash code based on all fields in this record. -
hashCode
Returns a hash code based on the fields matching the givenFieldList, or all fields ifnull.- Parameters:
fieldList- the fields to include in the hash, ornullfor all- Returns:
- the hash code
-
indexOfField
Returns the 0-based index of this exact field instance (compared by identity) or -1 if it is not in this record. -
indexOfField
Returns the index of the first field with the given name, or-1if not found.- Parameters:
fieldName- the field name to search forthrowExceptionOnFailure- iftrue, throws aDataExceptionwhen the field is not found- Returns:
- the field index, or
-1if not found andthrowExceptionOnFailureisfalse - Throws:
DataException- if the field is not found andthrowExceptionOnFailureistrue
-
containsField
Returnstrueif this record contains a field with the given name.- Parameters:
fieldName- the field name to check- Returns:
trueif the field exists
-
containsField
Indicates if this record contains a matching field for the specified path. This method will return false if the path matches an array value (for examplecity[2]orcustomer.address[0].city[2]) instead of a field. -
containsNonNullField
Indicates if this record contains a field at the specified path that is not null. -
containsNonNullField
Indicates if this record contains a field at the specified path with a non-null value. SeeFieldPathfor supported field name expressions. -
containsField
Returns true if all fields and sub fields in a nested path exists. -
contains
Deprecated.Indicates if this record contains a matching field or value for the specified path. UsecontainsValue(FieldPath)instead. -
containsNonNull
Deprecated.Indicates if this record contains a field or value at the specified path where the value is not null. UsecontainsNonNullValue(FieldPath)instead. -
containsValue
Indicates if this record contains a matching field or value for the specified path. -
containsNonNullValue
Indicates if this record contains a field or value at the specified path where the value is not null. -
removeField
Removes this exact field instance (compared by identity); returns false if it is not in this record. -
removeField
Removes and returns the field at the specified index.- Parameters:
index- the index of the field to remove- Returns:
- the removed field
- Throws:
IndexOutOfBoundsException- if the index is out of range
-
removeField
Removes and returns the field with the specified name.- Parameters:
columnName- the name of the field to remove- Returns:
- the removed field
- Throws:
DataException- if no field with the given name exists
-
removeField
Removes a sub-field matching the specified path. -
removeField
Deletes the field at the specified path or throws an exception if it doesn't exist.- Parameters:
fieldPath-- Returns:
- the removed field
-
moveField
public void moveField(int oldIndex, int newIndex) Moves a field from one position to another within this record.- Parameters:
oldIndex- the current index of the fieldnewIndex- the desired new index
-
moveField
Moves the field with the specified name to a new position within this record.- Parameters:
fieldName- the name of the field to movenewIndex- the desired new index
-
moveFieldBefore
Moves the named field to the position immediately before another named field.- Parameters:
fieldName- the name of the field to movebeforeFieldName- the name of the field to move before
-
moveFieldAfter
Moves the named field to the position immediately after another named field.- Parameters:
fieldName- the name of the field to moveafterFieldName- the name of the field to move after
-
moveFieldBefore
Moves the field at the specified path to the position immediately before another field path.- Parameters:
fieldPath- the path of the field to movebeforeFieldPath- the path of the field to move before
-
moveFieldAfter
Moves the field at the specified path to the position immediately after another field path.- Parameters:
fieldPath- the path of the field to moveafterFieldPath- the path of the field to move after
-
selectFields
Retains only the fields specified in the given list, removing all others and reordering to match the list's order. Equivalent to callingselectFields(fields, false).- Parameters:
fields- the fields to retain- Returns:
- this record for method chaining
-
selectFields
Retains only the fields specified in the given list, removing all others. Iflenientistrue, missing fields are silently ignored; otherwise an exception is thrown.- Parameters:
fields- the fields to retainlenient- iftrue, silently skip fields not found in this record- Returns:
- this record for method chaining
-
excludeFields
Removes all fields whose names appear in the given list.- Parameters:
fields- the field names to remove- Returns:
- this record for method chaining
-
excludeFields
Removes all fields whose names appear in the given set.- Parameters:
fields- the field names to remove- Returns:
- this record for method chaining
-
excludeFields
Removes all fields matching the givenFieldPathiterable that exist in this record.- Parameters:
fieldPaths- the field paths to remove- Returns:
- this record for method chaining
-
removeFields
Removes all fields matching the given collection ofFieldPathexpressions.- Parameters:
fieldPaths- the field paths to remove- Returns:
- this record for method chaining
- Throws:
DataException- if a path does not resolve
-
getSizeInBytesOfFieldNames
public long getSizeInBytesOfFieldNames()Returns the estimated total size of all field names in bytes, including object overhead.- Returns:
- the size in bytes
-
getSizeInBytes
public long getSizeInBytes()Returns the estimated size of this value node in bytes, including object overhead.- Specified by:
getSizeInBytesin classValueNode<Record>- Returns:
- the size in bytes
-
toString
Returns a human-readable string representation of this node and its contents. -
evaluate
Evaluates the given expression string against this record and returns the result.- Type Parameters:
T- the expected result type- Parameters:
expressionString- the expression to evaluate- Returns:
- the result of the expression
-
toJson
Serializes this record to a JSON string. -
toJson
Serializes the given record or array to a JSON string.- Parameters:
recordOrArray- the value node to serialize- Returns:
- the JSON representation
-
toJson
Serializes the given record or array as JSON to the specified writer.- Parameters:
recordOrArray- the value node to serializewriter- the target writer
-
toJson
Serializes this record to a JSON string, optionally pretty-printed.- Parameters:
pretty- iftrue, the output is indented for readability- Returns:
- the JSON representation
-
toJson
Serializes the given record or array to a JSON string, optionally pretty-printed.- Parameters:
recordOrArray- the value node to serializepretty- iftrue, the output is indented for readability- Returns:
- the JSON representation
-
toJson
Serializes the given record or array as JSON to the specified writer, optionally pretty-printed.- Parameters:
recordOrArray- the value node to serializewriter- the target writerpretty- iftrue, the output is indented for readability
-
fromJson
Deserializes a record or array from a JSON string.- Type Parameters:
T- the expected return type (RecordorArrayValue)- Parameters:
json- the JSON string- Returns:
- the deserialized value node
- Throws:
DataException- if the JSON cannot be parsed
-
fromJson
Deserializes a record or array from a JSON reader.- Type Parameters:
T- the expected return type (RecordorArrayValue)- Parameters:
reader- the JSON source- Returns:
- the deserialized value node
-
toXml
Serializes this record to an XML string. -
toXml
Serializes the given record or array to an XML string.- Parameters:
recordOrArray- the value node to serialize- Returns:
- the XML representation
-
toXml
Writes the record or array as unindented XML inside a<document>root element; the writer is flushed but left open. -
toXml
Serializes this record to an XML string with control over the root document and formatting.- Parameters:
writeRootDocument- iftrue, includes the XML declarationpretty- iftrue, the output is indented for readability- Returns:
- the XML representation
-
toXml
Serializes the given record or array to an XML string with control over the root document and formatting.- Parameters:
recordOrArray- the value node to serializewriteRootDocument- iftrue, includes the XML declarationpretty- iftrue, the output is indented for readability- Returns:
- the XML representation
-
toXml
public static void toXml(ValueNode<?> recordOrArray, Writer writer, boolean writeRootDocument, boolean pretty) Writes the record or array as XML, inside a<document>root element ifwriteRootDocumentand indented ifpretty; the writer is flushed but left open. -
fromXml
Deserializes a record or array from an XML string.- Type Parameters:
T- the expected return type (RecordorArrayValue)- Parameters:
xml- the XML string- Returns:
- the deserialized value node
- Throws:
DataException- if the XML cannot be parsed
-
fromXml
Deserializes a record or array from an XML reader.- Type Parameters:
T- the expected return type (RecordorArrayValue)- Parameters:
reader- the XML source- Returns:
- the deserialized value node
-
toBinary
public byte[] toBinary()Serializes this record to a binary byte array.- Returns:
- the binary representation
-
toBinary
Serializes the given record or array to a binary byte array.- Parameters:
recordOrArray- the value node to serialize- Returns:
- the binary representation
-
toBinary
Serializes the given record or array as binary data to the specified output stream.- Parameters:
recordOrArray- the value node to serializeoutputStream- the target output stream
-
toBinary
Serializes the given record or array as binary data to the specified data output.- Parameters:
recordOrArray- the value node to serializeoutput- the target data output
-
fromBinary
Deserializes a record or array from a binary byte array.- Type Parameters:
T- the expected return type (RecordorArrayValue)- Parameters:
bytes- the binary data- Returns:
- the deserialized value node, or
nullif the data is empty - Throws:
DataException- if the binary data cannot be parsed
-
fromBinary
Deserializes a record or array from a binary input stream.- Type Parameters:
T- the expected return type (RecordorArrayValue)- Parameters:
inputStream- the binary source- Returns:
- the deserialized value node
-
fromBinary
Deserializes a record or array from a binary data input.- Type Parameters:
T- the expected return type (RecordorArrayValue)- Parameters:
input- the binary source- Returns:
- the deserialized value node, or
nullif no records were read - Throws:
DataException- if the binary data cannot be parsed
-
isEmpty
public boolean isEmpty()Returns true if this record has no fields or all field values are null. -
isNotEmpty
public boolean isNotEmpty()Returns true if this record has at least one non-null field value. -
getFieldValueAsString
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsDatetime
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsDate
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsTime
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsInteger
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsLong
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsShort
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsByte
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsBytes
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsBoolean
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsChar
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsDouble
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsFloat
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsBigDecimal
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsBigInteger
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsRecord
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsArray
Returns the field's value as array if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsList
-
getFieldValueAsInstant
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsLocalDatetime
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsLocalDate
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsLocalTime
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValueAsUUID
Returns the field's value if the field exists and its value is not null, otherwise, it returns the default value. SeeFieldPathfor supported fieldPath expressions. -
getFieldValue
Returns the unconverted value at the givenFieldPathexpression or the default value if it is missing or null. -
getFieldValue
Gets the value at the specified field path, returning a default value if the field is null or not found. This method provides a type-safe way to retrieve field values with a fallback.- Type Parameters:
T- the expected type of the value- Parameters:
fieldPath- the path to the fielddefaultValue- the value to return if the field is null or not found- Returns:
- the field value, or defaultValue if the field is null or not found
-
ensureFields
Ensures that all specified field names exist in this record, creating any missing ones.- Parameters:
fieldNames- the field names to ensure exist
-
ensureFields
Ensures that all specified field names exist in this record, creating any missing ones.- Parameters:
fieldNames- the collection of field names to ensure exist
-
sortFieldsByName
Sorts the fields in this record alphabetically by name.- Returns:
- this record for method chaining
-