public class RetainPathsJsonAction extends Object implements JSONTraverseAction
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
Modifier and Type | Field and Description |
---|---|
protected PathDelimiter |
delim |
protected List<String> |
pathsToRetain |
protected net.minidev.json.JSONObject |
result |
Constructor and Description |
---|
RetainPathsJsonAction(List<String> pathsToRetain,
PathDelimiter delim) |
Modifier and Type | Method and 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 retain
|
void |
end()
called after the traversal ends,
and just before the
#start(M) method exits |
protected boolean |
foundAsPrefix(String path) |
void |
handleLeaf(String fullPathToContainingList,
int listIndex,
Object listItem)
called for each leaf of an
L list is encountered |
void |
handleLeaf(String pathToEntry,
Map.Entry<String,Object> entry)
called for each leaf of an
M map is encountered |
boolean |
recurInto(String fullPathToArrayItem,
net.minidev.json.JSONArray entryValue)
called when a non-leaf item is encountered inside an object
|
boolean |
recurInto(String fullPathToSubtree,
net.minidev.json.JSONObject entryValue)
called when a non-leaf entry is encountered inside an object
|
boolean |
removeEntry(String fullPathToEntry,
Map.Entry<String,Object> entry)
the last callback for each entry in an
M map. |
Object |
result()
holds the result of the traversal,
as assigned by the action implementing this interface
|
boolean |
start(net.minidev.json.JSONObject object)
called before any traversal of the
M tree starts |
boolean |
traverseEntry(String fullPathToEntry,
Map.Entry<String,Object> entry)
called when a new entry is encountered and before any processing is performed on it
|
protected final PathDelimiter delim
protected net.minidev.json.JSONObject result
public RetainPathsJsonAction(List<String> pathsToRetain, PathDelimiter delim)
public boolean start(net.minidev.json.JSONObject object)
TreeTraverseAction
M
tree startsstart
in interface TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public boolean traverseEntry(String fullPathToEntry, Map.Entry<String,Object> entry)
TreeTraverseAction
traverseEntry
in interface TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public boolean recurInto(String fullPathToSubtree, net.minidev.json.JSONObject entryValue)
TreeTraverseAction
recurInto
in interface TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public boolean recurInto(String fullPathToArrayItem, net.minidev.json.JSONArray entryValue)
TreeTraverseAction
recurInto
in interface TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public void handleLeaf(String pathToEntry, Map.Entry<String,Object> entry)
TreeTraverseAction
M
map is encounteredhandleLeaf
in interface TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public void handleLeaf(String fullPathToContainingList, int listIndex, Object listItem)
TreeTraverseAction
L
list is encounteredhandleLeaf
in interface TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
listIndex
- - the ordered location of the item in the listlistItem
- - the itempublic boolean removeEntry(String fullPathToEntry, Map.Entry<String,Object> entry)
TreeTraverseAction
M
map. if this method returns true
the TreeTraverser
removes the entry from the map. there is no further
handling of the entry.removeEntry
in interface TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
M
treepublic void end()
TreeTraverseAction
#start(M)
method exitsend
in interface TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public Object result()
TreeTraverseAction
result
in interface TreeTraverseAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
protected boolean discardPath(String pathToEntry, Map.Entry<String,Object> entry)
protected boolean foundAsPrefix(String path)
Copyright © 2020 Chemouni Uriel. All rights reserved.