Class RetainPathsJsonAction
- java.lang.Object
-
- net.minidev.json.actions.traverse.RetainPathsJsonAction
-
- All Implemented Interfaces:
JSONTraverseAction
,TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public class RetainPathsJsonAction extends 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
- Author:
- [email protected]
-
-
Field Summary
Fields Modifier and Type Field Description protected PathDelimiter
delim
protected List<String>
pathsToRetain
protected net.minidev.json.JSONObject
result
-
Constructor Summary
Constructors Constructor Description RetainPathsJsonAction(List<String> pathsToRetain, PathDelimiter delim)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
discardPath(String pathToEntry, Map.Entry<String,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 retainvoid
end()
called after the traversal ends, and just before theTreeTraverseAction.start(M)
method exitsprotected boolean
foundAsPrefix(String path)
void
handleLeaf(String fullPathToContainingList, int listIndex, Object listItem)
called for each leaf of an L list is encounteredvoid
handleLeaf(String pathToEntry, Map.Entry<String,Object> entry)
called for each leaf of an M map is encounteredboolean
recurInto(String fullPathToArrayItem, net.minidev.json.JSONArray entryValue)
called when a non-leaf item is encountered inside an L objectboolean
recurInto(String fullPathToSubtree, net.minidev.json.JSONObject entryValue)
called when a non-leaf entry is encountered inside an M objectboolean
removeEntry(String fullPathToEntry, Map.Entry<String,Object> entry)
the last callback for each entry in anTreeTraverseAction
map.Object
result()
holds the result of the traversal, as assigned by the action implementing this interfaceboolean
start(net.minidev.json.JSONObject object)
called before any traversal of theTreeTraverseAction
tree startsboolean
traverseEntry(String fullPathToEntry, Map.Entry<String,Object> entry)
called when a new entry is encountered and before any processing is performed on it
-
-
-
Field Detail
-
delim
protected final PathDelimiter delim
-
result
protected net.minidev.json.JSONObject result
-
-
Constructor Detail
-
RetainPathsJsonAction
public RetainPathsJsonAction(List<String> pathsToRetain, PathDelimiter delim)
- Parameters:
pathsToRetain
- TODOdelim
- TODO
-
-
Method Detail
-
start
public boolean start(net.minidev.json.JSONObject object)
Description copied from interface:TreeTraverseAction
called before any traversal of theTreeTraverseAction
tree starts- Specified by:
start
in interfaceTreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
object
- TODO- Returns:
- true if traversal should start at all
-
traverseEntry
public boolean traverseEntry(String fullPathToEntry, Map.Entry<String,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 interfaceTreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
fullPathToEntry
- TODOentry
- TODO- Returns:
- true if the entry should be processed
-
recurInto
public boolean recurInto(String fullPathToSubtree, net.minidev.json.JSONObject entryValue)
Description copied from interface:TreeTraverseAction
called when a non-leaf entry is encountered inside an M object- Specified by:
recurInto
in interfaceTreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
fullPathToSubtree
- TODOentryValue
- TODO- Returns:
- true if the non-leaf entry should be recursively traversed
-
recurInto
public boolean recurInto(String fullPathToArrayItem, net.minidev.json.JSONArray entryValue)
Description copied from interface:TreeTraverseAction
called when a non-leaf item is encountered inside an L object- Specified by:
recurInto
in interfaceTreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
fullPathToArrayItem
- TODOentryValue
- TODO- Returns:
- true if the non-leaf item should be recursively traversed
-
handleLeaf
public void handleLeaf(String pathToEntry, Map.Entry<String,Object> entry)
Description copied from interface:TreeTraverseAction
called for each leaf of an M map is encountered- Specified by:
handleLeaf
in interfaceTreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
pathToEntry
- TODOentry
- TODO
-
handleLeaf
public void handleLeaf(String fullPathToContainingList, int listIndex, Object listItem)
Description copied from interface:TreeTraverseAction
called for each leaf of an L list is encountered- Specified by:
handleLeaf
in interfaceTreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
fullPathToContainingList
- - the itemlistIndex
- - the ordered location of the item in the listlistItem
- -
-
removeEntry
public boolean removeEntry(String fullPathToEntry, Map.Entry<String,Object> entry)
Description copied from interface:TreeTraverseAction
the last callback for each entry in anTreeTraverseAction
map. if this method returns true theTreeTraverser
removes the entry from the map. there is no further handling of the entry.- Specified by:
removeEntry
in interfaceTreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
fullPathToEntry
- TODOentry
- TODO- Returns:
- true if the entry and its subtree should be removed from the M tree
-
end
public void end()
Description copied from interface:TreeTraverseAction
called after the traversal ends, and just before theTreeTraverseAction.start(M)
method exits- Specified by:
end
in interfaceTreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
-
result
public Object result()
Description copied from interface:TreeTraverseAction
holds the result of the traversal, as assigned by the action implementing this interface- Specified by:
result
in interfaceTreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Returns:
- result
-
discardPath
protected boolean discardPath(String pathToEntry, Map.Entry<String,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
- TODOentry
- TODO- Returns:
- TODO
-
foundAsPrefix
protected boolean foundAsPrefix(String path)
- Parameters:
path
- TODO- Returns:
- TODO
-
-