Package ortus.boxlang.runtime.util
Class DataNavigator.Navigator
java.lang.Object
ortus.boxlang.runtime.util.DataNavigator.Navigator
- Enclosing class:
DataNavigator
The Data Navigator Fluent Goodness Class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSafely navigate the data structure to a segment without blowing up.Get a value from data structure using nested keys if passedGet a value from data structure The value can be seeded using a ${code from} method call.getAsArray
(String... key) Get a value from data structure The value can be seeded using a ${code from} method call.getAsArray
(String key, Object defaultValue) Get a value from data structure The value can be seeded using a ${code from} method call.getAsBoolean
(String... key) Get a value from data structure The value can be seeded using a ${code from} method call.getAsBoolean
(String key, Object defaultValue) Get a value from data structure The value can be seeded using a ${code from} method call.Get a value from data structure The value can be seeded using a ${code from} method call.Get a value from data structure The value can be seeded using a ${code from} method call.getAsDouble
(String... key) Get a value from data structure The value can be seeded using a ${code from} method call.getAsDouble
(String key, Object defaultValue) Get a value from data structure The value can be seeded using a ${code from} method call.getAsInteger
(String... key) Get a value from data structure The value can be seeded using a ${code from} method call.getAsInteger
(String key, Object defaultValue) Get a value from data structure The value can be seeded using a ${code from} method call.Get a value from data structure The value can be seeded using a ${code from} method call.Get a value from data structure The value can be seeded using a ${code from} method call.Get a value from data structure The value can be seeded using a ${code from} method call.Get a value from data structure The value can be seeded using a ${code from} method call.getAsString
(String... key) Get a value from data structure The value can be seeded using a ${code from} method call.getAsString
(String key, Object defaultValue) Get a value from data structure The value can be seeded using a ${code from} method call.getAsStruct
(String... key) Get a value from data structure The value can be seeded using a ${code from} method call.getAsStruct
(String key, Object defaultValue) Get a value from data structure The value can be seeded using a ${code from} method call.getOrThrow
(String... key) Get a value from data structure using nested keys if passed If the key does not exist then throw an exceptionboolean
Verify if a path exists in the data structureCheck if a key exists in the data segment and if present execute a consumer.ifPresentOrElse
(String key, Consumer<Object> consumer, Runnable orElse) Check if a key exists in the data segment and if present execute a consumer.boolean
isEmpty()
Verifies if the segment or the data structure is empty or notboolean
Verifies if the segment or the data structure has data.
-
Constructor Details
-
Navigator
Construct a navigator from a file path- Parameters:
filePath
- The path to the JSON file
-
Navigator
Construct a navigator from a data structure- Parameters:
data
- The data structure to navigate
-
-
Method Details
-
isEmpty
public boolean isEmpty()Verifies if the segment or the data structure is empty or not- Returns:
- True if the segment or the data structure is empty, false otherwise
-
isPresent
public boolean isPresent()Verifies if the segment or the data structure has data. This is the inverse ofisEmpty()
- Returns:
- True if the segment or the data structure has data, false otherwise
-
ifPresent
Check if a key exists in the data segment and if present execute a consumer.- Parameters:
key
- The key to check forconsumer
- The consumer to execute if the key exists- Returns:
- The navigator again so you can chain calls
-
ifPresentOrElse
public DataNavigator.Navigator ifPresentOrElse(String key, Consumer<Object> consumer, Runnable orElse) Check if a key exists in the data segment and if present execute a consumer. If the key does not exist then execute the orElse runnable.- Parameters:
key
- The key to check forconsumer
- The consumer to execute if the key existsorElse
- The runnable to execute if the key does not exist- Returns:
- The navigator again so you can chain calls
-
has
Verify if a path exists in the data structure- Parameters:
path
- The path(s) to verify (nested keys accepted)- Returns:
- True if the key exists, false otherwise
-
from
Safely navigate the data structure to a segment without blowing up. If the path does not exist then a new empty struct is returned as the segment.- Parameters:
path
- The path to the object in the data structure- Returns:
- The navigator with the segment set
-
get
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist
-
getOrThrow
Get a value from data structure using nested keys if passed If the key does not exist then throw an exception- Parameters:
key
- One or more keys to retrieve the value for- Returns:
- The value of the key(s)
- Throws:
BoxRuntimeException
- If the key does not exist
-
get
Get a value from data structure using nested keys if passed- Parameters:
key
- One or more keys to navigate the box.json file- Returns:
- The value of the key(s) or null if it does not exist
-
getAsKey
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist
-
getAsKey
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value for
-
getAsString
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist
-
getAsString
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value for
-
getAsBoolean
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist
-
getAsBoolean
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value for
-
getAsInteger
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist
-
getAsInteger
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value for
-
getAsDate
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist- Returns:
- The value as a date
-
getAsDate
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value for
-
getAsLong
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist
-
getAsLong
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value for
-
getAsDouble
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist
-
getAsDouble
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value for
-
getAsStruct
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist
-
getAsStruct
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value for
-
getAsArray
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value fordefaultValue
- The default value to return if the key does not exist
-
getAsArray
Get a value from data structure The value can be seeded using a ${code from} method call.- Parameters:
key
- The key to get the value for
-