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 TypeMethodDescriptionvoidchangeNode(T newNode) Change the current node to the provided node.voidDeletes the current node.static <T> DefaultTraverserContext<T> dummy()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 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> 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 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:TraverserContextReturns 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:
thisNodein interfaceTraverserContext<T>- Returns:
- current node traverser is visiting.
-
originalThisNode
Description copied from interface:TraverserContextReturns the original, unchanged, not deleted Node.- Specified by:
originalThisNodein interfaceTraverserContext<T>- Returns:
- the original node
-
changeNode
Description copied from interface:TraverserContextChange 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:
changeNodein interfaceTraverserContext<T>- Parameters:
newNode- the new Node
-
deleteNode
public void deleteNode()Description copied from interface:TraverserContextDeletes the current node.- Specified by:
deleteNodein interfaceTraverserContext<T>
-
isDeleted
public boolean isDeleted()- Specified by:
isDeletedin interfaceTraverserContext<T>- Returns:
- true if the current node is deleted (by calling
TraverserContext.deleteNode()
-
isChanged
public boolean isChanged()- Specified by:
isChangedin interfaceTraverserContext<T>- Returns:
- true if the current node is changed (by calling
TraverserContext.changeNode(Object)
-
getParentContext
Description copied from interface:TraverserContextReturns 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:
getParentContextin interfaceTraverserContext<T>- Returns:
- context associated with the node parent
-
getParentNodes
Description copied from interface:TraverserContextThe list of parent nodes starting from the current parent.- Specified by:
getParentNodesin interfaceTraverserContext<T>- Returns:
- list of parent nodes
-
getBreadcrumbs
Description copied from interface:TraverserContextThe exact location of this node inside the tree as a list ofBreadcrumb- Specified by:
getBreadcrumbsin interfaceTraverserContext<T>- Returns:
- list of breadcrumbs. the first element is the location inside the parent.
-
getParentNode
Description copied from interface:TraverserContextThe parent node.- Specified by:
getParentNodein interfaceTraverserContext<T>- Returns:
- The parent node.
-
visitedNodes
Description copied from interface:TraverserContextObtains all visited nodes and values received by theTraverserVisitor.enter(graphql.util.TraverserContext)method- Specified by:
visitedNodesin 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:TraverserContextInforms that the current node has been already "visited"- Specified by:
isVisitedin interfaceTraverserContext<T>- Returns:
trueif a node had been already visited
-
getVar
Description copied from interface:TraverserContextObtains a context local variable- Specified by:
getVarin 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:TraverserContextStores a variable in the context- Specified by:
setVarin 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:TraverserContextSets the new accumulate value. Can be retrieved byTraverserContext.getNewAccumulate()- Specified by:
setAccumulatein interfaceTraverserContext<T>- Parameters:
accumulate- to set
-
getNewAccumulate
public <U> U getNewAccumulate()Description copied from interface:TraverserContextThe new accumulate value, previously set byTraverserContext.setAccumulate(Object)orTraverserContext.getCurrentAccumulate()ifTraverserContext.setAccumulate(Object)not invoked.- Specified by:
getNewAccumulatein interfaceTraverserContext<T>- Type Parameters:
U- and me- Returns:
- the new accumulate value
-
getCurrentAccumulate
public <U> U getCurrentAccumulate()Description copied from interface:TraverserContextThe current accumulate value used as "input" for the current step.- Specified by:
getCurrentAccumulatein interfaceTraverserContext<T>- Type Parameters:
U- and me- Returns:
- the current accumulate value
-
getLocation
Description copied from interface:TraverserContextThe location of the current node regarding to the parent node.- Specified by:
getLocationin interfaceTraverserContext<T>- Returns:
- the position or null if this node is a root node
-
isRootContext
public boolean isRootContext()Description copied from interface:TraverserContextReturns true for the root context, which doesn't have a node or a position.- Specified by:
isRootContextin interfaceTraverserContext<T>- Returns:
- true for the root context, otherwise false
-
getVarFromParents
Description copied from interface:TraverserContextSearches for a context variable starting from the parent up the hierarchy of contexts until the first variable is found.- Specified by:
getVarFromParentsin 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:TraverserContextIn case of leave returns the children contexts, which have already been visited.- Specified by:
getChildrenContextsin interfaceTraverserContext<T>- Returns:
- the children contexts. If the childs are a simple list the key is null.
-
getPhase
- Specified by:
getPhasein interfaceTraverserContext<T>- Returns:
- the phase in which the node visits currently happens (Enter,Leave or BackRef)
-
isParallel
public boolean isParallel()- Specified by:
isParallelin interfaceTraverserContext<T>- Returns:
- true if the traversing happens in parallel (multi threaded) or not.
-