Class CopyPathsAction
- java.lang.Object
-
- net.minidev.json.actions.navigate.CopyPathsAction
-
- All Implemented Interfaces:
JSONNavigateAction
,NavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
public class CopyPathsAction extends Object implements JSONNavigateAction
Creates a copy of aJSONObject
containing just the nodes on the paths specified.Specified paths that do not exist in the source object are ignored silently. Specifying an empty list of paths to navigate or only non-existent paths will result in an empty object being returned.
See package-info for more details
Example:
To copy the branch k1.k2 from {k1:{k2:v1}, k3:{k4:v2}} instantiate the copier like so: new JSONObjectCopier("k1.k2") The resulting copy would be {k1:{k2:v1}}
See unit tests for more examples
- Since:
- 15 March 2016.
- Author:
- [email protected]
-
-
Field Summary
Fields Modifier and Type Field Description protected net.minidev.json.JSONObject
destBranch
protected Stack<Object>
destNodeStack
protected net.minidev.json.JSONObject
destTree
-
Constructor Summary
Constructors Constructor Description CopyPathsAction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
end()
called after all navigation ends, and just before the navigation method exitsboolean
failFast(String path, Exception e)
called if navigation of a path throws an exceptionboolean
failSilently(String path, Exception e)
called if navigation of a path throws an exceptionvoid
foundLeafBeforePathEnd(TreePath jp, Object obj)
reached leaf node (not a container) in source but specified path expects children - the specified path does not exist in the sourcevoid
handleLeaf(TreePath jp, int arrIndex, Object o)
called when a leaf in a L is reached.void
handleLeaf(TreePath jp, Object o)
called when a leaf node is reached in a M.void
pathEnd(String path)
called after the navigation of a path endsboolean
pathStart(String path)
called before navigation of a new path startsvoid
pathTailNotFound(TreePath jp, Object source)
reached end of branch in source before end of specified path - the specified path does not exist in the sourcevoid
recurEnd(TreePath jp, net.minidev.json.JSONArray ja)
called when navigation of anNavigateAction
type object endsvoid
recurEnd(TreePath jp, net.minidev.json.JSONObject jo)
called when navigation of anNavigateAction
type object endsboolean
recurInto(TreePath jp, net.minidev.json.JSONArray o)
called when an array node is encountered on the pathboolean
recurInto(TreePath jp, net.minidev.json.JSONObject o)
called when an object node is encountered on the pathObject
result()
holds the result of the navigation, as assigned by the action implementing this interfaceboolean
start(net.minidev.json.JSONObject source, Collection<String> pathsToCopy)
called before any navigation of theNavigateAction
starts
-
-
-
Method Detail
-
start
public boolean start(net.minidev.json.JSONObject source, Collection<String> pathsToCopy)
Description copied from interface:NavigateAction
called before any navigation of theNavigateAction
starts- Specified by:
start
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Returns:
- true if navigation should start at all
-
recurInto
public boolean recurInto(TreePath jp, net.minidev.json.JSONObject o)
Description copied from interface:NavigateAction
called when an object node is encountered on the path- Specified by:
recurInto
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Returns:
- true if the navigator should navigate into the object
-
recurInto
public boolean recurInto(TreePath jp, net.minidev.json.JSONArray o)
Description copied from interface:NavigateAction
called when an array node is encountered on the path- Specified by:
recurInto
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Returns:
- true if the navigator should navigate into the array
-
foundLeafBeforePathEnd
public void foundLeafBeforePathEnd(TreePath jp, Object obj)
Description copied from interface:NavigateAction
reached leaf node (not a container) in source but specified path expects children - the specified path does not exist in the source- Specified by:
foundLeafBeforePathEnd
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
-
pathTailNotFound
public void pathTailNotFound(TreePath jp, Object source)
Description copied from interface:NavigateAction
reached end of branch in source before end of specified path - the specified path does not exist in the source- Specified by:
pathTailNotFound
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
-
handleLeaf
public void handleLeaf(TreePath jp, Object o)
Description copied from interface:NavigateAction
called when a leaf node is reached in a M. a leaf in a M is a key-value pair where the value is not a container itself (it is not a M nor a L)- Specified by:
handleLeaf
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
jp
- - the JsonPath pointing to the leaf
-
handleLeaf
public void handleLeaf(TreePath jp, int arrIndex, Object o)
Description copied from interface:NavigateAction
called when a leaf in a L is reached. a leaf in a L is a non-container item (it is not a M nor a L)- Specified by:
handleLeaf
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
arrIndex
- - the index of the item in the Lo
- - the item
-
recurEnd
public void recurEnd(TreePath jp, net.minidev.json.JSONObject jo)
Description copied from interface:NavigateAction
called when navigation of anNavigateAction
type object ends- Specified by:
recurEnd
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
jp
- the path pointing to the object
-
recurEnd
public void recurEnd(TreePath jp, net.minidev.json.JSONArray ja)
Description copied from interface:NavigateAction
called when navigation of anNavigateAction
type object ends- Specified by:
recurEnd
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Parameters:
jp
- the path pointing to the object
-
pathStart
public boolean pathStart(String path)
Description copied from interface:NavigateAction
called before navigation of a new path starts- Specified by:
pathStart
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Returns:
- true if the specified path should be navigated
-
pathEnd
public void pathEnd(String path)
Description copied from interface:NavigateAction
called after the navigation of a path ends- Specified by:
pathEnd
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
-
failSilently
public boolean failSilently(String path, Exception e)
Description copied from interface:NavigateAction
called if navigation of a path throws an exception- Specified by:
failSilently
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Returns:
- true if the failure on this path should not abort the rest of the navigation
-
failFast
public boolean failFast(String path, Exception e)
Description copied from interface:NavigateAction
called if navigation of a path throws an exception- Specified by:
failFast
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
- Returns:
- true if the failure on this path should abort the rest of the navigation
-
end
public void end()
Description copied from interface:NavigateAction
called after all navigation ends, and just before the navigation method exits- Specified by:
end
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
-
result
public Object result()
Description copied from interface:NavigateAction
holds the result of the navigation, as assigned by the action implementing this interface- Specified by:
result
in interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
-
-