Class TreeNavigator<M extends java.util.Map<java.lang.String,java.lang.Object>,L extends java.util.List<java.lang.Object>>
- java.lang.Object
-
- net.minidev.json.actions.navigate.TreeNavigator<M,L>
-
- Type Parameters:
M- the map type that extends Map<String, Object>L- the list type that extends List<Object>
- Direct Known Subclasses:
JSONNavigator
public class TreeNavigator<M extends java.util.Map<java.lang.String,java.lang.Object>,L extends java.util.List<java.lang.Object>> extends java.lang.ObjectNavigates only the branches of aJSONObjectcorresponding to the paths specified.For each specified path to navigate, the
TreeNavigatoronly traverses the matching branch.The navigator accepts an action and provides callback hooks for it to act on the traversed nodes at each significant step. See
NavigateAction.See package-info for more details
Example:
To navigate the branch k1.k2 of the object {"k1":{"k2":"v1"}, "k3":{"k4":"v2"}} instantiate the navigator like so: new JSONNavigator("k1.k2")
- Since:
- 15 June 2016.
-
-
Field Summary
Fields Modifier and Type Field Description protected NavigateAction<M,L>actionThe navigation action to executeprotected java.lang.StringpathPrefixThe path prefix to useprotected java.util.List<java.lang.String>pathsToNavigateThe list of paths to navigate
-
Constructor Summary
Constructors Constructor Description TreeNavigator(NavigateAction<M,L> action, java.lang.String... pathsToNavigate)Creates a tree navigator with the specified action and pathsTreeNavigator(NavigateAction<M,L> action, java.util.List<java.lang.String> pathsToNavigate)Creates a tree navigator with the specified action and paths
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private TreePathgetClone(TreePath jp)voidnav(M object)Navigates the specified object using the configured pathsvoidnav(TreePath jp, L list)voidnav(TreePath jp, M map)TreeNavigator<M,L>with(java.lang.String pathPrefix)Sets a path prefix for this navigator
-
-
-
Field Detail
-
pathsToNavigate
protected java.util.List<java.lang.String> pathsToNavigate
The list of paths to navigate
-
action
protected NavigateAction<M extends java.util.Map<java.lang.String,java.lang.Object>,L extends java.util.List<java.lang.Object>> action
The navigation action to execute
-
pathPrefix
protected java.lang.String pathPrefix
The path prefix to use
-
-
Constructor Detail
-
TreeNavigator
public TreeNavigator(NavigateAction<M,L> action, java.util.List<java.lang.String> pathsToNavigate)
Creates a tree navigator with the specified action and paths
-
TreeNavigator
public TreeNavigator(NavigateAction<M,L> action, java.lang.String... pathsToNavigate)
Creates a tree navigator with the specified action and paths
-
-
Method Detail
-
with
public TreeNavigator<M,L> with(java.lang.String pathPrefix)
Sets a path prefix for this navigator
-
nav
public void nav(M object) throws java.lang.Exception
Navigates the specified object using the configured paths- Throws:
java.lang.Exception
-
-