Package graphql.util
Class DefaultTraverserContext<T>
- java.lang.Object
-
- graphql.util.DefaultTraverserContext<T>
-
- All Implemented Interfaces:
TraverserContext<T>
public class DefaultTraverserContext<T> extends java.lang.Object implements TraverserContext<T>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface graphql.util.TraverserContext
TraverserContext.Phase
-
-
Constructor Summary
Constructors Constructor Description DefaultTraverserContext(T curNode, TraverserContext<T> parent, java.util.Set<T> visited, java.util.Map<java.lang.Class<?>,java.lang.Object> vars, java.lang.Object sharedContextData, NodeLocation location, boolean isRootContext, boolean parallel)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchangeNode(T newNode)Change the current node to the provided node.voiddeleteNode()Deletes the current node.static <T> DefaultTraverserContext<T>dummy()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 byTraverserContext.setAccumulate(Object)orTraverserContext.getCurrentAccumulate()ifTraverserContext.setAccumulate(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()java.lang.ObjectgetSharedContextData()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 contextstatic <T> DefaultTraverserContext<T>simple(T node)TthisNode()Returns current node being visited.java.util.Set<T>visitedNodes()Obtains all visited nodes and values received by theTraverserVisitor.enter(graphql.util.TraverserContext)method
-
-
-
Constructor Detail
-
DefaultTraverserContext
public DefaultTraverserContext(T curNode, TraverserContext<T> parent, java.util.Set<T> visited, java.util.Map<java.lang.Class<?>,java.lang.Object> vars, java.lang.Object sharedContextData, NodeLocation location, boolean isRootContext, boolean parallel)
-
-
Method Detail
-
dummy
public static <T> DefaultTraverserContext<T> dummy()
-
simple
public static <T> DefaultTraverserContext<T> simple(T node)
-
thisNode
public T 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
public T originalThisNode()
Description copied from interface:TraverserContextReturns the original, unchanged, not deleted Node.- Specified by:
originalThisNodein interfaceTraverserContext<T>- Returns:
- the original node
-
changeNode
public void changeNode(T newNode)
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
public TraverserContext<T> 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
public java.util.List<T> 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
public java.util.List<Breadcrumb<T>> 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
public T getParentNode()
Description copied from interface:TraverserContextThe parent node.- Specified by:
getParentNodein interfaceTraverserContext<T>- Returns:
- The parent node.
-
visitedNodes
public java.util.Set<T> 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
public <S> S getVar(java.lang.Class<? super S> key)
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
public <S> TraverserContext<T> setVar(java.lang.Class<? super S> key, S value)
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
public void setAccumulate(java.lang.Object accumulate)
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
-
getSharedContextData
public java.lang.Object getSharedContextData()
Description copied from interface:TraverserContextUsed to share something across all TraverserContext.- Specified by:
getSharedContextDatain interfaceTraverserContext<T>- Returns:
- contextData
-
getLocation
public NodeLocation 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
public <S> S getVarFromParents(java.lang.Class<? super S> key)
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
public java.util.Map<java.lang.String,java.util.List<TraverserContext<T>>> 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
public TraverserContext.Phase 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.
-
-