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 void
changeNode(T newNode)
Change the current node to the provided node.void
deleteNode()
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 ofBreadcrumb
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.<U> U
getCurrentAccumulate()
The current accumulate value used as "input" for the current step.NodeLocation
getLocation()
The location of the current node regarding to the parent node.<U> U
getNewAccumulate()
The new accumulate value, previously set byTraverserContext.setAccumulate(Object)
orTraverserContext.getCurrentAccumulate()
ifTraverserContext.setAccumulate(Object)
not invoked.TraverserContext<T>
getParentContext()
Returns parent context.T
getParentNode()
The parent node.java.util.List<T>
getParentNodes()
The list of parent nodes starting from the current parent.TraverserContext.Phase
getPhase()
java.lang.Object
getSharedContextData()
Used to share something across all TraverserContext.<S> S
getVar(java.lang.Class<? super S> key)
Obtains a context local variable<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.boolean
isChanged()
boolean
isDeleted()
boolean
isParallel()
boolean
isRootContext()
Returns true for the root context, which doesn't have a node or a position.boolean
isVisited()
Informs that the current node has been already "visited"T
originalThisNode()
Returns the original, unchanged, not deleted Node.void
setAccumulate(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)
T
thisNode()
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: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
public T originalThisNode()
Description copied from interface:TraverserContext
Returns the original, unchanged, not deleted Node.- Specified by:
originalThisNode
in interfaceTraverserContext<T>
- Returns:
- the original node
-
changeNode
public void changeNode(T newNode)
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
public TraverserContext<T> 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
public java.util.List<T> 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
public java.util.List<Breadcrumb<T>> 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
public T getParentNode()
Description copied from interface:TraverserContext
The parent node.- Specified by:
getParentNode
in interfaceTraverserContext<T>
- Returns:
- The parent node.
-
visitedNodes
public java.util.Set<T> 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
public <S> S getVar(java.lang.Class<? super S> key)
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
public <S> TraverserContext<T> setVar(java.lang.Class<? super S> key, S value)
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
public void setAccumulate(java.lang.Object accumulate)
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
-
getSharedContextData
public java.lang.Object getSharedContextData()
Description copied from interface:TraverserContext
Used to share something across all TraverserContext.- Specified by:
getSharedContextData
in interfaceTraverserContext<T>
- Returns:
- contextData
-
getLocation
public NodeLocation 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
public <S> S getVarFromParents(java.lang.Class<? super S> key)
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
public java.util.Map<java.lang.String,java.util.List<TraverserContext<T>>> 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
public TraverserContext.Phase 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.
-
-