Class SimpleTraversal<DataType>

java.lang.Object
com.bazaarvoice.jolt.traversr.SimpleTraversal<DataType>

public class SimpleTraversal<DataType> extends Object
Utility class for use in custom Transforms. Allows a programmer to just provide a single "human readable path" that they will want to be able to execute against multiple trees of data. Internally, parses the "human readable path" into a Traversr and a set of keys, so that the user only needs to call get/set with their input tree. Because the path is static, it is assumed that you will always be reading and writing objects of the same type to the tree, therefore this class can take a generic parameter "K" to reduce casting.
  • Field Details

  • Constructor Details

    • SimpleTraversal

      public SimpleTraversal(String humanReadablePath)
  • Method Details

    • newTraversal

      public static <T> SimpleTraversal<T> newTraversal(String humanReadablePath)
      Google Maps.newHashMap() trick to fill in generic type
    • get

      public Optional<DataType> get(Object tree)
      Parameters:
      tree - tree of Map and List JSON structure to navigate
      Returns:
      the object you wanted, or null if the object or any step along the path to it were not there
    • set

      public Optional<DataType> set(Object tree, DataType data)
      Parameters:
      tree - tree of Map and List JSON structure to navigate
      data - JSON style data object you want to set
      Returns:
      returns the data object if successfully set, otherwise null if there was a problem walking the path
    • remove

      public Optional<DataType> remove(Object tree)
      Parameters:
      tree - tree of Map and List JSON structure to navigate
      Returns:
      removes and returns the data object if it was able to successfully navigate to it and remove it.