Package graphql.util
Class DefaultTraverserContext<T>
java.lang.Object
graphql.util.DefaultTraverserContext<T>
- All Implemented Interfaces:
TraverserContext<T>
-
Nested Class Summary
Nested classes/interfaces inherited from interface graphql.util.TraverserContext
TraverserContext.Phase
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultTraverserContext
(T curNode, TraverserContext<T> parent, Set<T> visited, Map<Class<?>, Object> vars, Object sharedContextData, NodeLocation location, boolean isRootContext, boolean parallel) -
Method Summary
Modifier and TypeMethodDescriptionvoid
changeNode
(T newNode) Change the current node to the provided node.void
Deletes the current node.static <T> DefaultTraverserContext
<T> dummy()
List
<Breadcrumb<T>> The exact location of this node inside the tree as a list ofBreadcrumb
In case of leave returns the children contexts, which have already been visited.<U> U
The current accumulate value used as "input" for the current step.The location of the current node regarding to the parent node.<U> U
The new accumulate value, previously set byTraverserContext.setAccumulate(Object)
orTraverserContext.getCurrentAccumulate()
ifTraverserContext.setAccumulate(Object)
not invoked.Returns parent context.The parent node.The list of parent nodes starting from the current parent.getPhase()
Used to share something across all TraverserContext.<S> S
Obtains a context local variable<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.boolean
boolean
boolean
boolean
Returns true for the root context, which doesn't have a node or a position.boolean
Informs that the current node has been already "visited"Returns the original, unchanged, not deleted Node.void
setAccumulate
(Object accumulate) Sets the new accumulate value.<S> TraverserContext
<T> Stores a variable in the contextstatic <T> DefaultTraverserContext
<T> simple
(T node) thisNode()
Returns current node being visited.Obtains all visited nodes and values received by theTraverserVisitor.enter(graphql.util.TraverserContext)
method
-
Constructor Details
-
DefaultTraverserContext
public DefaultTraverserContext(T curNode, TraverserContext<T> parent, Set<T> visited, Map<Class<?>, Object> vars, Object sharedContextData, NodeLocation location, boolean isRootContext, boolean parallel)
-
-
Method Details
-
dummy
-
simple
-
thisNode
Description copied from interface:TraverserContext
Returns current node being visited. Special cases: It is null for the root context and it is the changed node afterTraverserContext.changeNode(Object)
is called. Throws Exception if the node is deleted.- Specified by:
thisNode
in interfaceTraverserContext<T>
- Returns:
- current node traverser is visiting.
-
originalThisNode
Description copied from interface:TraverserContext
Returns the original, unchanged, not deleted Node.- Specified by:
originalThisNode
in interfaceTraverserContext<T>
- Returns:
- the original node
-
changeNode
Description copied from interface:TraverserContext
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.- Specified by:
changeNode
in interfaceTraverserContext<T>
- Parameters:
newNode
- the new Node
-
deleteNode
public void deleteNode()Description copied from interface:TraverserContext
Deletes the current node.- Specified by:
deleteNode
in interfaceTraverserContext<T>
-
isDeleted
public boolean isDeleted()- Specified by:
isDeleted
in interfaceTraverserContext<T>
- Returns:
- true if the current node is deleted (by calling
TraverserContext.deleteNode()
-
isChanged
public boolean isChanged()- Specified by:
isChanged
in interfaceTraverserContext<T>
- Returns:
- true if the current node is changed (by calling
TraverserContext.changeNode(Object)
-
getParentContext
Description copied from interface:TraverserContext
Returns parent context. Effectively organizes Context objects in a linked list so by followingTraverserContext.getParentContext()
links one could obtain the current path as well as the variablesTraverserContext.getVar(java.lang.Class)
stored in every parent context.- Specified by:
getParentContext
in interfaceTraverserContext<T>
- Returns:
- context associated with the node parent
-
getParentNodes
Description copied from interface:TraverserContext
The list of parent nodes starting from the current parent.- Specified by:
getParentNodes
in interfaceTraverserContext<T>
- Returns:
- list of parent nodes
-
getBreadcrumbs
Description copied from interface:TraverserContext
The exact location of this node inside the tree as a list ofBreadcrumb
- Specified by:
getBreadcrumbs
in interfaceTraverserContext<T>
- Returns:
- list of breadcrumbs. the first element is the location inside the parent.
-
getParentNode
Description copied from interface:TraverserContext
The parent node.- Specified by:
getParentNode
in interfaceTraverserContext<T>
- Returns:
- The parent node.
-
visitedNodes
Description copied from interface:TraverserContext
Obtains all visited nodes and values received by theTraverserVisitor.enter(graphql.util.TraverserContext)
method- Specified by:
visitedNodes
in interfaceTraverserContext<T>
- Returns:
- a map containing all nodes visited and values passed when visiting nodes for the first time
-
isVisited
public boolean isVisited()Description copied from interface:TraverserContext
Informs that the current node has been already "visited"- Specified by:
isVisited
in interfaceTraverserContext<T>
- Returns:
true
if a node had been already visited
-
getVar
Description copied from interface:TraverserContext
Obtains a context local variable- Specified by:
getVar
in interfaceTraverserContext<T>
- Type Parameters:
S
- type of the variable- Parameters:
key
- key to lookup the variable value- Returns:
- a variable value or
null
-
setVar
Description copied from interface:TraverserContext
Stores a variable in the context- Specified by:
setVar
in interfaceTraverserContext<T>
- 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
Description copied from interface:TraverserContext
Sets the new accumulate value. Can be retrieved byTraverserContext.getNewAccumulate()
- Specified by:
setAccumulate
in interfaceTraverserContext<T>
- Parameters:
accumulate
- to set
-
getNewAccumulate
public <U> U getNewAccumulate()Description copied from interface:TraverserContext
The new accumulate value, previously set byTraverserContext.setAccumulate(Object)
orTraverserContext.getCurrentAccumulate()
ifTraverserContext.setAccumulate(Object)
not invoked.- Specified by:
getNewAccumulate
in interfaceTraverserContext<T>
- Type Parameters:
U
- and me- Returns:
- the new accumulate value
-
getCurrentAccumulate
public <U> U getCurrentAccumulate()Description copied from interface:TraverserContext
The current accumulate value used as "input" for the current step.- Specified by:
getCurrentAccumulate
in interfaceTraverserContext<T>
- Type Parameters:
U
- and me- Returns:
- the current accumulate value
-
getLocation
Description copied from interface:TraverserContext
The location of the current node regarding to the parent node.- Specified by:
getLocation
in interfaceTraverserContext<T>
- Returns:
- the position or null if this node is a root node
-
isRootContext
public boolean isRootContext()Description copied from interface:TraverserContext
Returns true for the root context, which doesn't have a node or a position.- Specified by:
isRootContext
in interfaceTraverserContext<T>
- Returns:
- true for the root context, otherwise false
-
getVarFromParents
Description copied from interface:TraverserContext
Searches for a context variable starting from the parent up the hierarchy of contexts until the first variable is found.- Specified by:
getVarFromParents
in interfaceTraverserContext<T>
- Type Parameters:
S
- type of the variable- Parameters:
key
- key to lookup the variable value- Returns:
- a variable value or
null
-
getChildrenContexts
Description copied from interface:TraverserContext
In case of leave returns the children contexts, which have already been visited.- Specified by:
getChildrenContexts
in interfaceTraverserContext<T>
- Returns:
- the children contexts. If the childs are a simple list the key is null.
-
getPhase
- Specified by:
getPhase
in interfaceTraverserContext<T>
- Returns:
- the phase in which the node visits currently happens (Enter,Leave or BackRef)
-
isParallel
public boolean isParallel()- Specified by:
isParallel
in interfaceTraverserContext<T>
- Returns:
- true if the traversing happens in parallel (multi threaded) or not.
-