Package graphql.util

Interface TraverserContext<T>

Type Parameters:
T - type of tree node
All Known Implementing Classes:
DefaultTraverserContext

@PublicApi public interface TraverserContext<T>
Traversal context. It is used as providing context for traversing, but also for returning an accumulate value. (setAccumulate(Object) There is always a "fake" root context with null node, null parent, null position. See isRootContext()
  • Method Details

    • thisNode

      T thisNode()
      Returns current node being visited. Special cases: It is null for the root context and it is the changed node after changeNode(Object) is called. Throws Exception if the node is deleted.
      Returns:
      current node traverser is visiting.
      Throws:
      AssertException - if the current node is deleted
    • originalThisNode

      T originalThisNode()
      Returns the original, unchanged, not deleted Node.
      Returns:
      the original node
    • changeNode

      void changeNode(T newNode)
      Change the current node to the provided node. Only applicable in enter. Useful when the tree should be changed while traversing. Also: changing a node makes only a difference when it has different children than the current one.
      Parameters:
      newNode - the new Node
    • deleteNode

      void deleteNode()
      Deletes the current node.
    • isDeleted

      boolean isDeleted()
      Returns:
      true if the current node is deleted (by calling deleteNode()
    • isChanged

      boolean isChanged()
      Returns:
      true if the current node is changed (by calling changeNode(Object)
    • getParentContext

      TraverserContext<T> getParentContext()
      Returns parent context. Effectively organizes Context objects in a linked list so by following getParentContext() links one could obtain the current path as well as the variables getVar(java.lang.Class) stored in every parent context.
      Returns:
      context associated with the node parent
    • getParentNodes

      List<T> getParentNodes()
      The list of parent nodes starting from the current parent.
      Returns:
      list of parent nodes
    • getParentNode

      T getParentNode()
      The parent node.
      Returns:
      The parent node.
    • getBreadcrumbs

      List<Breadcrumb<T>> getBreadcrumbs()
      The exact location of this node inside the tree as a list of Breadcrumb
      Returns:
      list of breadcrumbs. the first element is the location inside the parent.
    • getLocation

      NodeLocation getLocation()
      The location of the current node regarding to the parent node.
      Returns:
      the position or null if this node is a root node
    • isVisited

      boolean isVisited()
      Informs that the current node has been already "visited"
      Returns:
      true if a node had been already visited
    • visitedNodes

      Set<T> visitedNodes()
      Obtains all visited nodes and values received by the TraverserVisitor.enter(graphql.util.TraverserContext) method
      Returns:
      a map containing all nodes visited and values passed when visiting nodes for the first time
    • getVar

      <S> S getVar(Class<? super S> key)
      Obtains a context local variable
      Type Parameters:
      S - type of the variable
      Parameters:
      key - key to lookup the variable value
      Returns:
      a variable value or null
    • getVarFromParents

      <S> S getVarFromParents(Class<? super S> key)
      Searches for a context variable starting from the parent up the hierarchy of contexts until the first variable is found.
      Type Parameters:
      S - type of the variable
      Parameters:
      key - key to lookup the variable value
      Returns:
      a variable value or null
    • setVar

      <S> TraverserContext<T> setVar(Class<? super S> key, S value)
      Stores a variable in the context
      Type Parameters:
      S - type of a variable
      Parameters:
      key - key to create bindings for the variable
      value - value of variable
      Returns:
      this context to allow operations chaining
    • setAccumulate

      void setAccumulate(Object accumulate)
      Sets the new accumulate value. Can be retrieved by getNewAccumulate()
      Parameters:
      accumulate - to set
    • getNewAccumulate

      <U> U getNewAccumulate()
      The new accumulate value, previously set by setAccumulate(Object) or getCurrentAccumulate() if setAccumulate(Object) not invoked.
      Type Parameters:
      U - and me
      Returns:
      the new accumulate value
    • getCurrentAccumulate

      <U> U getCurrentAccumulate()
      The current accumulate value used as "input" for the current step.
      Type Parameters:
      U - and me
      Returns:
      the current accumulate value
    • getSharedContextData

      <U> U getSharedContextData()
      Used to share something across all TraverserContext.
      Type Parameters:
      U - and me
      Returns:
      contextData
    • isRootContext

      boolean isRootContext()
      Returns true for the root context, which doesn't have a node or a position.
      Returns:
      true for the root context, otherwise false
    • getChildrenContexts

      Map<String,List<TraverserContext<T>>> getChildrenContexts()
      In case of leave returns the children contexts, which have already been visited.
      Returns:
      the children contexts. If the childs are a simple list the key is null.
    • getPhase

      Returns:
      the phase in which the node visits currently happens (Enter,Leave or BackRef)
    • isParallel

      boolean isParallel()
      Returns:
      true if the traversing happens in parallel (multi threaded) or not.