Package graphql.util
Interface TraverserContext<T>
- Type Parameters:
T- type of tree node
- All Known Implementing Classes:
DefaultTraverserContext
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()-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeNode(T newNode) Change the current node to the provided node.voidDeletes the current node.List<Breadcrumb<T>> The exact location of this node inside the tree as a list ofBreadcrumbIn case of leave returns the children contexts, which have already been visited.<U> UThe current accumulate value used as "input" for the current step.The location of the current node regarding to the parent node.<U> UThe new accumulate value, previously set bysetAccumulate(Object)orgetCurrentAccumulate()ifsetAccumulate(Object)not invoked.Returns parent context.The parent node.The list of parent nodes starting from the current parent.getPhase()<U> UUsed to share something across all TraverserContext.<S> SObtains a context local variable<S> SgetVarFromParents(Class<? super S> key) Searches for a context variable starting from the parent up the hierarchy of contexts until the first variable is found.booleanbooleanbooleanbooleanReturns true for the root context, which doesn't have a node or a position.booleanInforms that the current node has been already "visited"Returns the original, unchanged, not deleted Node.voidsetAccumulate(Object accumulate) Sets the new accumulate value.<S> TraverserContext<T> Stores a variable in the contextthisNode()Returns current node being visited.Obtains all visited nodes and values received by theTraverserVisitor.enter(graphql.util.TraverserContext)method
-
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 afterchangeNode(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
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 followinggetParentContext()links one could obtain the current path as well as the variablesgetVar(java.lang.Class)stored in every parent context.- Returns:
- context associated with the node parent
-
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 ofBreadcrumb- 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:
trueif a node had been already visited
-
visitedNodes
Obtains all visited nodes and values received by theTraverserVisitor.enter(graphql.util.TraverserContext)method- Returns:
- a map containing all nodes visited and values passed when visiting nodes for the first time
-
getVar
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
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
Stores a variable in the context- Type Parameters:
S- type of a variable- Parameters:
key- key to create bindings for the variablevalue- value of variable- Returns:
- this context to allow operations chaining
-
setAccumulate
Sets the new accumulate value. Can be retrieved bygetNewAccumulate()- Parameters:
accumulate- to set
-
getNewAccumulate
<U> U getNewAccumulate()The new accumulate value, previously set bysetAccumulate(Object)orgetCurrentAccumulate()ifsetAccumulate(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
-
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
TraverserContext.Phase 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.
-