Package net.dv8tion.jda.api.utils.data
Class DataPath
java.lang.Object
net.dv8tion.jda.api.utils.data.DataPath
This utility class can be used to access nested values within
DataObjects and DataArrays.
Path Expression Grammar
The syntax for paths is given by this grammar:
<name-syntax> ::= /[^.\[\]]+/;
<index-syntax> ::= "[" <number> "]";
<name> ::= <name-syntax> | <name-syntax> "?";
<index> ::= <index-syntax> | <index-syntax> "?";
<element> ::= <name> ( <index> )*;
<path-start> ::= <element> | <index> ( <index> )*;
<path> ::= <path-start> ( "." <element> )*;
Examples
Given a JSON object such as:
{
"array": [{
"foo": "bar",
}]
}
The content of "foo" can be accessed using the code:
String foo = DataPath.getString(root, "array[0].foo")
With the safe-access operator "?", you can also allow missing values within your path:
String foo = DataPath.getString(root, "array[1]?.foo", "default")
This will result in foo == "default", since the array element 1 is marked as optional, and missing in the actual object.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Tget(DataArray root, String path, BiFunction<DataObject, String, ? extends T> fromObject, BiFunction<DataArray, Integer, ? extends T> fromArray) Parses the givenpathand finds the appropriate value within thisDataArray.static <T> Tget(DataObject root, String path, BiFunction<DataObject, String, ? extends T> fromObject, BiFunction<DataArray, Integer, ? extends T> fromArray) Parses the givenpathand finds the appropriate value within thisDataObject.static DataArrayParses the givenpathand finds the appropriate value within thisDataArray.static DataArraygetArray(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static booleangetBoolean(DataArray root, String path) Parses the givenpathand finds the appropriate value within thisDataArray.static booleangetBoolean(DataArray root, String path, boolean fallback) Parses the givenpathand finds the appropriate value within thisDataArray.static booleangetBoolean(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static booleangetBoolean(DataObject root, String path, boolean fallback) Parses the givenpathand finds the appropriate value within thisDataObject.static doubleParses the givenpathand finds the appropriate value within thisDataArray.static doubleParses the givenpathand finds the appropriate value within thisDataArray.static doublegetDouble(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static doublegetDouble(DataObject root, String path, double fallback) Parses the givenpathand finds the appropriate value within thisDataObject.static intParses the givenpathand finds the appropriate value within thisDataArray.static intParses the givenpathand finds the appropriate value within thisDataArray.static intgetInt(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static intgetInt(DataObject root, String path, int fallback) Parses the givenpathand finds the appropriate value within thisDataObject.static longParses the givenpathand finds the appropriate value within thisDataArray.static longParses the givenpathand finds the appropriate value within thisDataArray.static longgetLong(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static longgetLong(DataObject root, String path, long fallback) Parses the givenpathand finds the appropriate value within thisDataObject.static DataObjectParses the givenpathand finds the appropriate value within thisDataArray.static DataObjectgetObject(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static StringParses the givenpathand finds the appropriate value within thisDataArray.static StringParses the givenpathand finds the appropriate value within thisDataArray.static StringgetString(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static StringgetString(DataObject root, String path, String fallback) Parses the givenpathand finds the appropriate value within thisDataObject.static intgetUnsignedInt(DataArray root, String path) Parses the givenpathand finds the appropriate value within thisDataArray.static intgetUnsignedInt(DataArray root, String path, int fallback) Parses the givenpathand finds the appropriate value within thisDataArray.static intgetUnsignedInt(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static intgetUnsignedInt(DataObject root, String path, int fallback) Parses the givenpathand finds the appropriate value within thisDataObject.static longgetUnsignedLong(DataArray root, String path) Parses the givenpathand finds the appropriate value within thisDataArray.static longgetUnsignedLong(DataArray root, String path, long fallback) Parses the givenpathand finds the appropriate value within thisDataArray.static longgetUnsignedLong(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static longgetUnsignedLong(DataObject root, String path, long fallback) Parses the givenpathand finds the appropriate value within thisDataObject.static DataArrayParses the givenpathand finds the appropriate value within thisDataArray.static DataArrayoptArray(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.static DataObjectParses the givenpathand finds the appropriate value within thisDataArray.static DataObjectoptObject(DataObject root, String path) Parses the givenpathand finds the appropriate value within thisDataObject.
-
Constructor Details
-
DataPath
public DataPath()
-
-
Method Details
-
get
@UnknownNullability public static <T> T get(@Nonnull DataObject root, @Nonnull String path, @Nonnull BiFunction<DataObject, String, ? extends T> fromObject, @Nonnull BiFunction<DataArray, Integer, ? extends T> fromArray) Parses the givenpathand finds the appropriate value within thisDataObject.- Type Parameters:
T- The result type- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".fromObject- Object relative resolver of the value, this is used for the final reference and resolves the value. The first parameter is theDataObjectwhere you get the value from, and the second is the field name. An example would be(obj, name) -> obj.getString(name)or as a method referenceDataObject::getString.fromArray- Array relative resolver of the value, this is used for the final reference and resolves the value. The first parameter is theDataArraywhere you get the value from, and the second is the field index. An example would be(array, index) -> obj.getString(index)or as a method referenceDataArray::getString.- Returns:
- The value at the provided path, using the provided resolver functions. Possibly null, if the path ends with a "?" operator, or the resolver function returns null.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
get
@UnknownNullability public static <T> T get(@Nonnull DataArray root, @Nonnull String path, @Nonnull BiFunction<DataObject, String, ? extends T> fromObject, @Nonnull BiFunction<DataArray, Integer, ? extends T> fromArray) Parses the givenpathand finds the appropriate value within thisDataArray.- Type Parameters:
T- The result type- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".fromObject- Object relative resolver of the value, this is used for the final reference and resolves the value. The first parameter is theDataObjectwhere you get the value from, and the second is the field name. An example would be(obj, name) -> obj.getString(name)or as a method referenceDataObject::getString.fromArray- Array relative resolver of the value, this is used for the final reference and resolves the value. The first parameter is theDataArraywhere you get the value from, and the second is the field index. An example would be(array, index) -> obj.getString(index)or as a method referenceDataArray::getString.- Returns:
- The value at the provided path, using the provided resolver functions. Possibly null, if the path ends with a "?" operator, or the resolver function returns null.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getBoolean
Parses the givenpathand finds the appropriate value within thisDataObject.- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The boolean value at the given path, if declared as optional this returns false when the value is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getBoolean
Parses the givenpathand finds the appropriate value within thisDataObject.- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The boolean value at the given path, if declared as optional this returns the provided fallback when the value is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getBoolean
Parses the givenpathand finds the appropriate value within thisDataArray.- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The boolean value at the given path, if declared as optional this returns false when the value is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getBoolean
Parses the givenpathand finds the appropriate value within thisDataArray.- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The boolean value at the given path, if declared as optional this returns the provided fallback when the value is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getInt
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingInteger.parseInt(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The int value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getInt
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingInteger.parseInt(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The int value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getInt
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingInteger.parseInt(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The int value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getInt
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingInteger.parseInt(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The int value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getUnsignedInt
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingInteger.parseUnsignedInt(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The unsigned int value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getUnsignedInt
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingInteger.parseUnsignedInt(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The unsigned int value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getUnsignedInt
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingInteger.parseUnsignedInt(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The unsigned int value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getUnsignedInt
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingInteger.parseUnsignedInt(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The unsigned int value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getLong
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingLong.parseLong(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The long value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getLong
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingLong.parseLong(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The long value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getLong
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingLong.parseLong(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The long value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getLong
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingLong.parseLong(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The long value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getUnsignedLong
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingLong.parseUnsignedLong(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The unsigned long value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getUnsignedLong
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingLong.parseUnsignedLong(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The unsigned long value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getUnsignedLong
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingLong.parseUnsignedLong(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The unsigned long value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getUnsignedLong
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingLong.parseUnsignedLong(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The unsigned long value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getDouble
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingDouble.parseDouble(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The double value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getDouble
Parses the givenpathand finds the appropriate value within thisDataObject.
If the resulting value is a string, this will parse the string usingDouble.parseDouble(String).- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The double value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getDouble
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingDouble.parseDouble(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The double value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getDouble
Parses the givenpathand finds the appropriate value within thisDataArray.
If the resulting value is a string, this will parse the string usingDouble.parseDouble(String).- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The double value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getString
Parses the givenpathand finds the appropriate value within thisDataObject.- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The String value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getString
@Contract("_, _, !null -> !null") public static String getString(@Nonnull DataObject root, @Nonnull String path, @Nullable String fallback) Parses the givenpathand finds the appropriate value within thisDataObject.- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The String value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getString
Parses the givenpathand finds the appropriate value within thisDataArray.- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The String value at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getString
@Contract("_, _, !null -> !null") public static String getString(@Nonnull DataArray root, @Nonnull String path, @Nullable String fallback) Parses the givenpathand finds the appropriate value within thisDataArray.- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The String value at the given path, returning the fallback if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getObject
Parses the givenpathand finds the appropriate value within thisDataObject.- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The DataObject at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
optObject
Parses the givenpathand finds the appropriate value within thisDataObject.- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The DataObject at the given path, or null if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getObject
Parses the givenpathand finds the appropriate value within thisDataArray.- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The DataObject at the given path
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
optObject
Parses the givenpathand finds the appropriate value within thisDataArray.- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The DataObject at the given path, or null if the path resolves to an optional value that is missing.
- Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getArray
Parses the givenpathand finds the appropriate value within thisDataObject.- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The
DataArrayat the given path - Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
optArray
Parses the givenpathand finds the appropriate value within thisDataObject.- Parameters:
root- The root data object, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with a name element, such as"foo".- Returns:
- The
DataArrayat the given path, or null if the path resolves to an optional value that is missing. - Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
getArray
Parses the givenpathand finds the appropriate value within thisDataArray.- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The
DataArrayat the given path - Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-
optArray
Parses the givenpathand finds the appropriate value within thisDataArray.- Parameters:
root- The root data array, which is the top level accessor.
The very first element in the path corresponds to a field of that name within this root object.path- The path of the value, in accordance with the described grammar byDataPath. This must start with an index element, such as"[0]".- Returns:
- The
DataArrayat the given path, or null if the path resolves to an optional value that is missing. - Throws:
ParsingException- If the path is invalid or resolving fails due to missing elementsIndexOutOfBoundsException- If any of the elements in the path refer to an array index that is out of boundsIllegalArgumentException- If null is provided or the path is empty
-