Class LocatePathsJsonAction

  • All Implemented Interfaces:
    JSONTraverseAction, TreeTraverseAction<JSONObject,​JSONArray>

    public class LocatePathsJsonAction
    extends java.lang.Object
    implements JSONTraverseAction
    Searches for paths in a JSONObject and returns those found

    A path is not removed from the user-specified list once its processing is over, because identical objects in the same array are supported by this action.

    See package-info for more details

    See unit tests for examples

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected PathDelimiter delim
      The path delimiter to use
      protected java.util.List<java.lang.String> pathsFound
      The list of paths found during traversal
      protected java.util.List<java.lang.String> pathsToFind
      The list of paths to search for
    • Constructor Summary

      Constructors 
      Constructor Description
      LocatePathsJsonAction​(java.util.List<java.lang.String> pathsToFind, PathDelimiter delim)
      Creates a new locate paths action.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void end()
      called after the traversal ends, and just before the TreeTraverseAction.start(M) method exits
      void handleLeaf​(java.lang.String fullPathToContainingList, int listIndex, java.lang.Object listItem)
      called for each leaf of an L list is encountered
      void handleLeaf​(java.lang.String pathToEntry, java.util.Map.Entry<java.lang.String,​java.lang.Object> entry)
      called for each leaf of an M map is encountered
      private void locatePath​(java.lang.String pathToEntry)  
      boolean recurInto​(java.lang.String pathToEntry, JSONArray entryValue)
      called when a non-leaf item is encountered inside an L object
      boolean recurInto​(java.lang.String pathToEntry, JSONObject entryValue)
      called when a non-leaf entry is encountered inside an M object
      boolean removeEntry​(java.lang.String fullPathToEntry, java.util.Map.Entry<java.lang.String,​java.lang.Object> entry)
      the last callback for each entry in an TreeTraverseAction map.
      java.lang.Object result()
      holds the result of the traversal, as assigned by the action implementing this interface
      boolean start​(JSONObject object)
      called before any traversal of the TreeTraverseAction tree starts
      boolean traverseEntry​(java.lang.String fullPathToEntry, java.util.Map.Entry<java.lang.String,​java.lang.Object> entry)
      called when a new entry is encountered and before any processing is performed on it
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • pathsFound

        protected java.util.List<java.lang.String> pathsFound
        The list of paths found during traversal
      • pathsToFind

        protected java.util.List<java.lang.String> pathsToFind
        The list of paths to search for
    • Constructor Detail

      • LocatePathsJsonAction

        public LocatePathsJsonAction​(java.util.List<java.lang.String> pathsToFind,
                                     PathDelimiter delim)
        Creates a new locate paths action.
        Parameters:
        pathsToFind - A path to a field in the JSONObject should be specified in n-gram format where keys are chained: k0[[[.k1].k2]...]
        delim - the path delimiter to use
    • Method Detail

      • traverseEntry

        public boolean traverseEntry​(java.lang.String fullPathToEntry,
                                     java.util.Map.Entry<java.lang.String,​java.lang.Object> entry)
        Description copied from interface: TreeTraverseAction
        called when a new entry is encountered and before any processing is performed on it
        Specified by:
        traverseEntry in interface TreeTraverseAction<JSONObject,​JSONArray>
        Parameters:
        fullPathToEntry - TODO
        entry - TODO
        Returns:
        true if the entry should be processed
      • recurInto

        public boolean recurInto​(java.lang.String pathToEntry,
                                 JSONObject entryValue)
        Description copied from interface: TreeTraverseAction
        called when a non-leaf entry is encountered inside an M object
        Specified by:
        recurInto in interface TreeTraverseAction<JSONObject,​JSONArray>
        Parameters:
        pathToEntry - TODO
        entryValue - TODO
        Returns:
        true if the non-leaf entry should be recursively traversed
      • recurInto

        public boolean recurInto​(java.lang.String pathToEntry,
                                 JSONArray entryValue)
        Description copied from interface: TreeTraverseAction
        called when a non-leaf item is encountered inside an L object
        Specified by:
        recurInto in interface TreeTraverseAction<JSONObject,​JSONArray>
        Parameters:
        pathToEntry - TODO
        entryValue - TODO
        Returns:
        true if the non-leaf item should be recursively traversed
      • handleLeaf

        public void handleLeaf​(java.lang.String pathToEntry,
                               java.util.Map.Entry<java.lang.String,​java.lang.Object> entry)
        Description copied from interface: TreeTraverseAction
        called for each leaf of an M map is encountered
        Specified by:
        handleLeaf in interface TreeTraverseAction<JSONObject,​JSONArray>
        Parameters:
        pathToEntry - TODO
        entry - TODO
      • handleLeaf

        public void handleLeaf​(java.lang.String fullPathToContainingList,
                               int listIndex,
                               java.lang.Object listItem)
        Description copied from interface: TreeTraverseAction
        called for each leaf of an L list is encountered
        Specified by:
        handleLeaf in interface TreeTraverseAction<JSONObject,​JSONArray>
        Parameters:
        fullPathToContainingList - - the item
        listIndex - - the ordered location of the item in the list
        listItem - -
      • removeEntry

        public boolean removeEntry​(java.lang.String fullPathToEntry,
                                   java.util.Map.Entry<java.lang.String,​java.lang.Object> entry)
        Description copied from interface: TreeTraverseAction
        the last callback for each entry in an TreeTraverseAction map. if this method returns true the TreeTraverser removes the entry from the map. there is no further handling of the entry.
        Specified by:
        removeEntry in interface TreeTraverseAction<JSONObject,​JSONArray>
        Parameters:
        fullPathToEntry - TODO
        entry - TODO
        Returns:
        true if the entry and its subtree should be removed from the M tree
      • locatePath

        private void locatePath​(java.lang.String pathToEntry)