Class FieldPath
- All Implemented Interfaces:
JsonSerializable,RecordSerializable,XmlSerializable,JavaCodeGenerator
parse(String) or programmatically by adding name (name(String))
and index (index(int)) segments to an instance.
For example, the field path customer.address[0].city can be created in two ways:
FieldPath.parse("customer.address[0].city")new FieldPath().name("customer").name("address").index(0).name("city")
Other examples of parsed field paths include:
- Single field names: firstName
- Nested field names: customer.firstName
- Array values: customer.address[2].city
- Positional field access: customer.address[2][0]
- Positional field access: [1]
- String arrays (for field names with spaces): customer.address[2]["zip code"]
- String arrays (using single quotes): customer.address[2]['zip code']
- Quoted field names (for field names with spaces or symbols): 'Company Flag (Y/N)'
- Quoted nested field names (for field names with spaces or symbols): customer."Company Flag (Y/N)"
- Quoted array values (for field names with spaces or symbols): `Company Address`[0]
Identifiers in field expressions may start with letters, underscores (_), at symbols (@), or dollar signs ($) and contain letters, numbers, underscores, at symbols, and dollar signs. You will need to quote field expressions that contain other symbols and spaces if they should be treated as part of the field name. For example, if your field name contains a period, you will need to quote it ("Package Lbs.").
Quoting:When quoting fields, you can use double quotes ("), single quotes ('), or grave accent (`).
A note of caution: FieldPath can also represent the location of values in array fields. For example,
city[2] or customer.address[0].city[2] could match the third city in an array field. Some methods
and operations expecting a field will throw an exception (or return false) if the supplied FieldPath matches an array value
and not a field.
- See Also:
-
Field Summary
Fields inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
SERIALIZED_CLASS_NAME, TYPEFields inherited from interface com.northconcepts.datapipeline.core.XmlSerializable
XML_SERIALIZED_CLASS_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDeprecated.booleancontainsField(Record record) Returns true if this path leads to a field (not an array element) in the record.booleancontainsNonNullField(Record record) Returns true if this path leads to a field in the record whose value is not null.booleancontainsNonNullValue(Record record) Returns true if this path leads to a field or array element in the record whose value is not null.booleancontainsValue(Record record) Returns true if this path leads to anything in the record (a field or an array element), even if it holds null.booleanfromJson(InputStream inputStream) Loads this object's state from the UTF-8 encoded JSON in the stream.Loads this object's state from the given JSON text.static FieldPathConverts a single field name into a FieldPath.fromRecord(Record source) Loads this instance's state from a record and returnsthis(for fluid API call chaining).fromXml(InputStream inputStream) Parses the XML in the stream and loads this object's state from its root element.fromXmlElement(Element element) voidgenerateJavaCode(JavaCodeBuilder javaCodeBuilder) Appends Java source code representing this object to the given builder.Returns the field at this path, creating missing parts ifcreateis true; if the path does not resolve it returns null, or throws whenthrowExceptionis true.Returns the node (field, record, array or single value) this path leads to fromrootNode, creating missing parts ifcreateis true.Returns the name (or number/index) of the last segment in this path as a string.getSingleValue(Record record, boolean create, boolean throwException) Returns theSingleValueat this path (a field's value or an array element), handlingcreateandthrowExceptionlikegetField(Record, boolean, boolean).Returns the plain value of the node thatgetValueNode(ValueNode, boolean, boolean)finds, or null if there is none.ValueNode<?> getValueNode(ValueNode<?> recordOrArray, boolean create, boolean throwException) Returns the value (record, array or single value) at this path below the given record or array, handlingcreateandthrowExceptionlikegetField(Record, boolean, boolean).inthashCode()index(int index) Appends a 0-based index segment that selects an array element or a record's field by position; negative indexes count back from the end.booleanIndicates if this path matches against a flat record (i.e.Appends a new field name segment to this field path.static FieldPathConverts a field path expression into a FieldPath object.static FieldPathParses the expression asparse(String)does, except that a null or blank expression returns null, or throws iffailOnEmptyis true.ValueNode<?> Sets the value of the field or array element at this path, creating missing parts ifcreateis true; returns the new value node or null if the path does not resolve.Returns this path as an expression, quoting names that contain characters other than letters and digits (unliketoString()).toRecord()Converts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.toString()toXmlElement(Document document) Returns an element, created withdocument, describing this object; the default implementation throws aDataException.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
toJson, toJson, toJson
-
Constructor Details
-
FieldPath
public FieldPath()
-
-
Method Details
-
parse
Converts a field path expression into a FieldPath object. Expressions can be:- Single field names: firstName
- Nested field names: customer.firstName
- Array values: customer.address[2].city
- Positional field access: customer.address[2][0]
- Positional field access: [1]
- String arrays (for field names with spaces): customer.address[2]["zip code"]
- String arrays (using single quotes): customer.address[2]['zip code']
- Quoted field names (for field names with spaces or symbols): 'Company Flag (Y/N)'
- Quoted nested field names (for field names with spaces or symbols): customer."Company Flag (Y/N)"
- Quoted array values (for field names with spaces or symbols): `Company Address`[0]
Identifiers in field expressions may start with letters, underscores (_), at symbols (@), or dollar signs ($) and contain letters, numbers, underscores, at symbols, and dollar signs. You will need to quote field expressions that contain other symbols and spaces if they should be treated as part of the field name. For example, if your field name contains a period, you will need to quote it ("Package Lbs.").
Quoting:When quoting fields, you can use double quotes ("), single quotes ('), or grave accent (`).
-
parse
Parses the expression asparse(String)does, except that a null or blank expression returns null, or throws iffailOnEmptyis true. -
fromName
Converts a single field name into a FieldPath. This method does no parsing and treats all characters as part of the field name. -
name
Appends a new field name segment to this field path. -
index
Appends a 0-based index segment that selects an array element or a record's field by position; negative indexes count back from the end. -
isTabular
public boolean isTabular()Indicates if this path matches against a flat record (i.e. no nested records or array fields). -
getField
Returns the field at this path, creating missing parts ifcreateis true; if the path does not resolve it returns null, or throws whenthrowExceptionis true. -
getSingleValue
Returns theSingleValueat this path (a field's value or an array element), handlingcreateandthrowExceptionlikegetField(Record, boolean, boolean). -
getValueNode
public ValueNode<?> getValueNode(ValueNode<?> recordOrArray, boolean create, boolean throwException) Returns the value (record, array or single value) at this path below the given record or array, handlingcreateandthrowExceptionlikegetField(Record, boolean, boolean). -
setValue
public ValueNode<?> setValue(ValueNode<?> parentNode, boolean create, boolean throwException, Object value) Sets the value of the field or array element at this path, creating missing parts ifcreateis true; returns the new value node or null if the path does not resolve. -
getValue
Returns the plain value of the node thatgetValueNode(ValueNode, boolean, boolean)finds, or null if there is none. -
getNode
Returns the node (field, record, array or single value) this path leads to fromrootNode, creating missing parts ifcreateis true. -
containsField
Returns true if this path leads to a field (not an array element) in the record. -
containsNonNullField
Returns true if this path leads to a field in the record whose value is not null. -
contains
Deprecated.UsecontainsValue(Record)instead. -
containsValue
Returns true if this path leads to anything in the record (a field or an array element), even if it holds null. -
containsNonNullValue
Returns true if this path leads to a field or array element in the record whose value is not null. -
getSimpleName
Returns the name (or number/index) of the last segment in this path as a string. -
hashCode
public int hashCode() -
equals
-
toString
-
toExpression
Returns this path as an expression, quoting names that contain characters other than letters and digits (unliketoString()). -
toRecord
Description copied from interface:RecordSerializableConverts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.- Specified by:
toRecordin interfaceRecordSerializable
-
fromRecord
Description copied from interface:RecordSerializableLoads this instance's state from a record and returnsthis(for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.- Specified by:
fromRecordin interfaceRecordSerializable- Parameters:
source-- Returns:
- this instance.
-
toXmlElement
Description copied from interface:XmlSerializableReturns an element, created withdocument, describing this object; the default implementation throws aDataException.- Specified by:
toXmlElementin interfaceXmlSerializable
-
fromXmlElement
- Specified by:
fromXmlElementin interfaceXmlSerializable
-
fromXml
Description copied from interface:XmlSerializableParses the XML in the stream and loads this object's state from its root element.- Specified by:
fromXmlin interfaceXmlSerializable
-
fromXml
- Specified by:
fromXmlin interfaceXmlSerializable
-
fromJson
Description copied from interface:JsonSerializableLoads this object's state from the UTF-8 encoded JSON in the stream.- Specified by:
fromJsonin interfaceJsonSerializable- Specified by:
fromJsonin interfaceRecordSerializable
-
fromJson
Description copied from interface:JsonSerializableLoads this object's state from the given JSON text.- Specified by:
fromJsonin interfaceJsonSerializable- Specified by:
fromJsonin interfaceRecordSerializable
-
generateJavaCode
Description copied from interface:JavaCodeGeneratorAppends Java source code representing this object to the given builder.- Specified by:
generateJavaCodein interfaceJavaCodeGenerator
-