Package com.bazaarvoice.jolt.traversr
Class SimpleTraversal<DataType>
- java.lang.Object
-
- com.bazaarvoice.jolt.traversr.SimpleTraversal<DataType>
-
public class SimpleTraversal<DataType> extends java.lang.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 Summary
Fields Modifier and Type Field Description private java.util.List<java.lang.String>
keys
private SimpleTraversr
traversr
-
Constructor Summary
Constructors Constructor Description SimpleTraversal(java.lang.String humanReadablePath)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<DataType>
get(java.lang.Object tree)
static <T> SimpleTraversal<T>
newTraversal(java.lang.String humanReadablePath)
Google Maps.newHashMap() trick to fill in generic typeOptional<DataType>
remove(java.lang.Object tree)
Optional<DataType>
set(java.lang.Object tree, DataType data)
-
-
-
Field Detail
-
traversr
private final SimpleTraversr traversr
-
keys
private final java.util.List<java.lang.String> keys
-
-
Method Detail
-
newTraversal
public static <T> SimpleTraversal<T> newTraversal(java.lang.String humanReadablePath)
Google Maps.newHashMap() trick to fill in generic type
-
get
public Optional<DataType> get(java.lang.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(java.lang.Object tree, DataType data)
- Parameters:
tree
- tree of Map and List JSON structure to navigatedata
- 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
-
-