Class 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 Detail

      • keys

        private final java.util.List<java.lang.String> keys
    • Constructor Detail

      • SimpleTraversal

        public SimpleTraversal​(java.lang.String humanReadablePath)
    • 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 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​(java.lang.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.