Class DataNavigator.Navigator

java.lang.Object
ortus.boxlang.runtime.util.DataNavigator.Navigator
Enclosing class:
DataNavigator

public static class DataNavigator.Navigator extends Object
The Data Navigator Fluent Goodness Class
  • Constructor Details

    • Navigator

      public Navigator(Path filePath)
      Construct a navigator from a file path
      Parameters:
      filePath - The path to the JSON file
    • Navigator

      public Navigator(IStruct data)
      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 of isEmpty()
      Returns:
      True if the segment or the data structure has data, false otherwise
    • ifPresent

      public DataNavigator.Navigator ifPresent(String key, Consumer<Object> consumer)
      Check if a key exists in the data segment and if present execute a consumer.
      Parameters:
      key - The key to check for
      consumer - 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 for
      consumer - The consumer to execute if the key exists
      orElse - The runnable to execute if the key does not exist
      Returns:
      The navigator again so you can chain calls
    • has

      public boolean has(String... path)
      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

      public DataNavigator.Navigator from(String... path)
      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

      public Object get(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
    • getOrThrow

      public Object getOrThrow(String... key)
      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

      public Object get(String... key)
      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

      public Key getAsKey(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
    • getAsKey

      public Key getAsKey(String... key)
      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

      public String getAsString(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
    • getAsString

      public String getAsString(String... key)
      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

      public Boolean getAsBoolean(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
    • getAsBoolean

      public Boolean getAsBoolean(String... key)
      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

      public Integer getAsInteger(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
    • getAsInteger

      public Integer getAsInteger(String... key)
      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

      public DateTime getAsDate(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
      Returns:
      The value as a date
    • getAsDate

      public DateTime getAsDate(String... key)
      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

      public Long getAsLong(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
    • getAsLong

      public Long getAsLong(String... key)
      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

      public Double getAsDouble(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
    • getAsDouble

      public Double getAsDouble(String... key)
      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

      public IStruct getAsStruct(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
    • getAsStruct

      public IStruct getAsStruct(String... key)
      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

      public Array getAsArray(String key, Object defaultValue)
      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
      defaultValue - The default value to return if the key does not exist
    • getAsArray

      public Array getAsArray(String... key)
      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