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 aJSONObjectcontaining 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:
- adoneitan@gmail.com
-
-
Field Summary
Fields Modifier and Type Field Description protected net.minidev.json.JSONObjectdestBranchprotected Stack<Object>destNodeStackprotected net.minidev.json.JSONObjectdestTree
-
Constructor Summary
Constructors Constructor Description CopyPathsAction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidend()called after all navigation ends, and just before the navigation method exitsbooleanfailFast(String path, Exception e)called if navigation of a path throws an exceptionbooleanfailSilently(String path, Exception e)called if navigation of a path throws an exceptionvoidfoundLeafBeforePathEnd(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 sourcevoidhandleLeaf(TreePath jp, int arrIndex, Object o)called when a leaf in a L is reached.voidhandleLeaf(TreePath jp, Object o)called when a leaf node is reached in a M.voidpathEnd(String path)called after the navigation of a path endsbooleanpathStart(String path)called before navigation of a new path startsvoidpathTailNotFound(TreePath jp, Object source)reached end of branch in source before end of specified path - the specified path does not exist in the sourcevoidrecurEnd(TreePath jp, net.minidev.json.JSONArray ja)called when navigation of anNavigateActiontype object endsvoidrecurEnd(TreePath jp, net.minidev.json.JSONObject jo)called when navigation of anNavigateActiontype object endsbooleanrecurInto(TreePath jp, net.minidev.json.JSONArray o)called when an array node is encountered on the pathbooleanrecurInto(TreePath jp, net.minidev.json.JSONObject o)called when an object node is encountered on the pathObjectresult()holds the result of the navigation, as assigned by the action implementing this interfacebooleanstart(net.minidev.json.JSONObject source, Collection<String> pathsToCopy)called before any navigation of theNavigateActionstarts
-
-
-
Method Detail
-
start
public boolean start(net.minidev.json.JSONObject source, Collection<String> pathsToCopy)Description copied from interface:NavigateActioncalled before any navigation of theNavigateActionstarts- Specified by:
startin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
source- TODOpathsToCopy- TODO- Returns:
- true if navigation should start at all
-
recurInto
public boolean recurInto(TreePath jp, net.minidev.json.JSONObject o)
Description copied from interface:NavigateActioncalled when an object node is encountered on the path- Specified by:
recurIntoin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
jp- TODOo- TODO- 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:NavigateActioncalled when an array node is encountered on the path- Specified by:
recurIntoin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
jp- TODOo- TODO- Returns:
- true if the navigator should navigate into the array
-
foundLeafBeforePathEnd
public void foundLeafBeforePathEnd(TreePath jp, Object obj)
Description copied from interface:NavigateActionreached leaf node (not a container) in source but specified path expects children - the specified path does not exist in the source- Specified by:
foundLeafBeforePathEndin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
jp- TODOobj- TODO
-
pathTailNotFound
public void pathTailNotFound(TreePath jp, Object source)
Description copied from interface:NavigateActionreached end of branch in source before end of specified path - the specified path does not exist in the source- Specified by:
pathTailNotFoundin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
jp- TODOsource- TODO
-
handleLeaf
public void handleLeaf(TreePath jp, Object o)
Description copied from interface:NavigateActioncalled 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:
handleLeafin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
jp- - the JsonPath pointing to the leafo- TODO
-
handleLeaf
public void handleLeaf(TreePath jp, int arrIndex, Object o)
Description copied from interface:NavigateActioncalled 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:
handleLeafin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
jp- -arrIndex- -o- - the item
-
recurEnd
public void recurEnd(TreePath jp, net.minidev.json.JSONObject jo)
Description copied from interface:NavigateActioncalled when navigation of anNavigateActiontype object ends- Specified by:
recurEndin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
jp- the path pointing to the objectjo- TODO
-
recurEnd
public void recurEnd(TreePath jp, net.minidev.json.JSONArray ja)
Description copied from interface:NavigateActioncalled when navigation of anNavigateActiontype object ends- Specified by:
recurEndin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
jp- the path pointing to the objectja- TODO
-
pathStart
public boolean pathStart(String path)
Description copied from interface:NavigateActioncalled before navigation of a new path starts- Specified by:
pathStartin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
path- TODO- Returns:
- true if the specified path should be navigated
-
pathEnd
public void pathEnd(String path)
Description copied from interface:NavigateActioncalled after the navigation of a path ends- Specified by:
pathEndin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
path- TODO
-
failSilently
public boolean failSilently(String path, Exception e)
Description copied from interface:NavigateActioncalled if navigation of a path throws an exception- Specified by:
failSilentlyin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
path- TODOe- TODO- 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:NavigateActioncalled if navigation of a path throws an exception- Specified by:
failFastin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Parameters:
path- TODOe- TODO- Returns:
- true if the failure on this path should abort the rest of the navigation
-
end
public void end()
Description copied from interface:NavigateActioncalled after all navigation ends, and just before the navigation method exits- Specified by:
endin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>
-
result
public Object result()
Description copied from interface:NavigateActionholds the result of the navigation, as assigned by the action implementing this interface- Specified by:
resultin interfaceNavigateAction<net.minidev.json.JSONObject,net.minidev.json.JSONArray>- Returns:
- - result
-
-