java.lang.Object
de.serra.graph_walker.GraphWalk
Entry point to start the traversal of an object graph.
Methods in this class can be overriden to customize the traversal.
- Author:
- Peter Lamby
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanUsed to detect circular object graphs.protected voidCallsObjectgraphVisitor.beforeObject(Object, VisitController, boolean)and determins the next state depending on the object.createSubwalk(ObjectgraphVisitor visitor) Creates a "sub" graphwalk from the current position.protected GraphWalkerStackFrame<?>Returns the current stack frame.protected voiddispatch()Determins which method to call depending on the state of the currentStackFrame.protected voidgoBack()Removes the current stack frame.protected voidgrow(int minCapacity) Increases the capacity to ensure that it can hold at least the number of elements specified by the minimum capacity argument.protected booleanisDone()Used to determin if the current traversal is done.protected booleanShould the children not be traversed.protected booleanShould the parent classes not be traversed.protected booleanIs the traversal stopped?protected voidleave()Removes the current stack frame and informs the next stack frame that we are returning to it.protected voidpushOnStack(GraphWalkerStackFrame<?> statestackFrame) Adds a new stack frame on top of the stack.protected GraphWalkerStackFrame<?>relativeFromCurrent(int offset) Returns a stack frame relative to the current one.protected voidUsed to continue the traversal as normal.protected voidVisits an array.protected voidVisits an array member.protected voidVisits an "normal" object.protected voidVisits the field of an Object.voidStart the traversal oftoWalk.
-
Constructor Details
-
GraphWalk
Constructs.- Parameters:
visitor- The visitor to use for this GraphWalk.
-
-
Method Details
-
walk
Start the traversal oftoWalk.- Parameters:
toWalk- The root of the object graph.
-
createSubwalk
Creates a "sub" graphwalk from the current position.It remembers the already visited nodes but otherwise acts as a walk on it's own.
- Parameters:
visitor- The visitor to use for this GraphWalk.- Returns:
- the new graph walk.
-
dispatch
protected void dispatch()Determins which method to call depending on the state of the currentStackFrame. -
beforeObject
protected void beforeObject()CallsObjectgraphVisitor.beforeObject(Object, VisitController, boolean)and determins the next state depending on the object. -
visitArray
protected void visitArray()Visits an array. -
visitArrayMember
protected void visitArrayMember()Visits an array member. -
visitClass
protected void visitClass()Visits an "normal" object. -
visitClassField
protected void visitClassField()Visits the field of an Object. -
isDone
@Pure protected boolean isDone()Used to determin if the current traversal is done.Either because we
stoppedor because there is nothing more to visit.- Returns:
trueif the traversal is done.
-
isStopped
@Pure protected boolean isStopped()Is the traversal stopped?- Returns:
trueif the traversal is stopped.
-
isDontGoDeeper
@Pure protected boolean isDontGoDeeper()Should the children not be traversed.- Returns:
trueif the children should not be traversed.
-
isDontGoSuper
@Pure protected boolean isDontGoSuper()Should the parent classes not be traversed.- Returns:
trueif the parent classes should not be traversed.
-
currentStackFrame
Returns the current stack frame.- Returns:
- the current stack frame.
-
relativeFromCurrent
Returns a stack frame relative to the current one.- Parameters:
offset- The offset.0to get the current one.- Returns:
- the specified stack frame.
-
leave
protected void leave()Removes the current stack frame and informs the next stack frame that we are returning to it. -
alreadySeen
Used to detect circular object graphs.Should return
trueifowas already visited in the current path.If this returns
truetraversal will skipo.- Parameters:
o- The object to check.- Returns:
trueif we already visitedoin the current path.
-
pushOnStack
Adds a new stack frame on top of the stack.- Parameters:
statestackFrame- The stack frame to add.
-
grow
protected void grow(int minCapacity) Increases the capacity to ensure that it can hold at least the number of elements specified by the minimum capacity argument.- Parameters:
minCapacity- the desired minimum capacity
-
resetControl
protected void resetControl()Used to continue the traversal as normal. Used after leaving an object to reset any flags only meant for that node. -
goBack
protected void goBack()Removes the current stack frame.
-