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. SeeisRootContext()
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classTraverserContext.Phase
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidchangeNode(T newNode)Change the current node to the provided node.voiddeleteNode()Deletes the current node.java.util.List<Breadcrumb<T>>getBreadcrumbs()The exact location of this node inside the tree as a list ofBreadcrumbjava.util.Map<java.lang.String,java.util.List<TraverserContext<T>>>getChildrenContexts()In case of leave returns the children contexts, which have already been visited.<U> UgetCurrentAccumulate()The current accumulate value used as "input" for the current step.NodeLocationgetLocation()The location of the current node regarding to the parent node.<U> UgetNewAccumulate()The new accumulate value, previously set bysetAccumulate(Object)orgetCurrentAccumulate()ifsetAccumulate(Object)not invoked.TraverserContext<T>getParentContext()Returns parent context.TgetParentNode()The parent node.java.util.List<T>getParentNodes()The list of parent nodes starting from the current parent.TraverserContext.PhasegetPhase()<U> UgetSharedContextData()Used to share something across all TraverserContext.<S> SgetVar(java.lang.Class<? super S> key)Obtains a context local variable<S> SgetVarFromParents(java.lang.Class<? super S> key)Searches for a context variable starting from the parent up the hierarchy of contexts until the first variable is found.booleanisChanged()booleanisDeleted()booleanisParallel()booleanisRootContext()Returns true for the root context, which doesn't have a node or a position.booleanisVisited()Informs that the current node has been already "visited"ToriginalThisNode()Returns the original, unchanged, not deleted Node.voidsetAccumulate(java.lang.Object accumulate)Sets the new accumulate value.<S> TraverserContext<T>setVar(java.lang.Class<? super S> key, S value)Stores a variable in the contextTthisNode()Returns current node being visited.java.util.Set<T>visitedNodes()Obtains all visited nodes and values received by theTraverserVisitor.enter(graphql.util.TraverserContext)method
-
-
-
Method Detail
-
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
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 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
java.util.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
java.util.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
java.util.Set<T> 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
<S> S getVar(java.lang.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(java.lang.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(java.lang.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 variablevalue- value of variable- Returns:
- this context to allow operations chaining
-
setAccumulate
void setAccumulate(java.lang.Object accumulate)
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
-
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
java.util.Map<java.lang.String,java.util.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.
-
-