Class TreeNavigator<M extends java.util.Map<java.lang.String,​java.lang.Object>,​L extends java.util.List<java.lang.Object>>

  • 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.Object
    Navigates only the branches of a JSONObject corresponding to the paths specified.

    For each specified path to navigate, the TreeNavigator only 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> action
      The navigation action to execute
      protected java.lang.String pathPrefix
      The path prefix to use
      protected java.util.List<java.lang.String> pathsToNavigate
      The 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 paths
      TreeNavigator​(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 TreePath getClone​(TreePath jp)  
      void nav​(M object)
      Navigates the specified object using the configured paths
      void nav​(TreePath jp, L list)  
      void nav​(TreePath jp, M map)  
      TreeNavigator<M,​L> with​(java.lang.String pathPrefix)
      Sets a path prefix for this navigator
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
      • nav

        public void nav​(TreePath jp,
                        M map)
      • nav

        public void nav​(TreePath jp,
                        L list)