Class RetainPathsJsonAction

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

    public class RetainPathsJsonAction
    extends java.lang.Object
    implements JSONTraverseAction
    Retain branches or parts of branches matching a specified list of paths.

    Paths are matched from the root down. If a user-specified path ends at a non-leaf node, the rest of the branch from that node to the leaf is not retained.

    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

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean discardPath​(java.lang.String pathToEntry, java.util.Map.Entry<java.lang.String,​java.lang.Object> entry)
      if the full path to the entry is not contained in any of the paths to retain - remove it from the object this step does not remove entries whose full path is contained in a path to retain but are not equal to an entry to retain
      void end()
      called after the traversal ends, and just before the TreeTraverseAction.start(M) method exits
      protected boolean foundAsPrefix​(java.lang.String path)  
      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
      boolean recurInto​(java.lang.String fullPathToArrayItem, JSONArray entryValue)
      called when a non-leaf item is encountered inside an L object
      boolean recurInto​(java.lang.String fullPathToSubtree, 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

      • pathsToRetain

        protected java.util.List<java.lang.String> pathsToRetain
    • Constructor Detail

      • RetainPathsJsonAction

        public RetainPathsJsonAction​(java.util.List<java.lang.String> pathsToRetain,
                                     PathDelimiter delim)
        Parameters:
        pathsToRetain - TODO
        delim - TODO
    • 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 fullPathToSubtree,
                                 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:
        fullPathToSubtree - TODO
        entryValue - TODO
        Returns:
        true if the non-leaf entry should be recursively traversed
      • recurInto

        public boolean recurInto​(java.lang.String fullPathToArrayItem,
                                 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:
        fullPathToArrayItem - 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
      • discardPath

        protected boolean discardPath​(java.lang.String pathToEntry,
                                      java.util.Map.Entry<java.lang.String,​java.lang.Object> entry)
        if the full path to the entry is not contained in any of the paths to retain - remove it from the object this step does not remove entries whose full path is contained in a path to retain but are not equal to an entry to retain
        Parameters:
        pathToEntry - TODO
        entry - TODO
        Returns:
        TODO
      • foundAsPrefix

        protected boolean foundAsPrefix​(java.lang.String path)
        Parameters:
        path - TODO
        Returns:
        TODO