Class GraphWalk

java.lang.Object
de.serra.graph_walker.GraphWalk

public class GraphWalk extends Object
Entry point to start the traversal of an object graph.

Methods in this class can be overriden to customize the traversal.

Author:
Peter Lamby
  • Constructor Details

    • GraphWalk

      public GraphWalk(ObjectgraphVisitor visitor)
      Constructs.
      Parameters:
      visitor - The visitor to use for this GraphWalk.
  • Method Details

    • walk

      public void walk(@Nullable Object toWalk)
      Start the traversal of toWalk.
      Parameters:
      toWalk - The root of the object graph.
    • dispatch

      protected void dispatch()
      Determins which method to call depending on the state of the current StackFrame.
    • beforeObject

      protected void beforeObject()
      Calls ObjectgraphVisitor.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 stopped or because there is nothing more to visit.

      Returns:
      true if the traversal is done.
    • isStopped

      @Pure protected boolean isStopped()
      Is the traversal stopped?
      Returns:
      true if the traversal is stopped.
    • isDontGoDeeper

      @Pure protected boolean isDontGoDeeper()
      Should the children not be traversed.
      Returns:
      true if the children should not be traversed.
    • isDontGoSuper

      @Pure protected boolean isDontGoSuper()
      Should the parent classes not be traversed.
      Returns:
      true if the parent classes should not be traversed.
    • currentStackFrame

      @Pure protected GraphWalkerStackFrame<?> currentStackFrame()
      Returns the current stack frame.
      Returns:
      the current stack frame.
    • relativeFromCurrent

      @Pure protected GraphWalkerStackFrame<?> relativeFromCurrent(int offset)
      Returns a stack frame relative to the current one.
      Parameters:
      offset - The offset. 0 to 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

      @Pure protected boolean alreadySeen(Object o)
      Used to detect circular object graphs.

      Should return true if o was already visited in the current path.

      If this returns true traversal will skip o.

      Parameters:
      o - The object to check.
      Returns:
      true if we already visited o in the current path.
    • pushOnStack

      protected void pushOnStack(GraphWalkerStackFrame<?> statestackFrame)
      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.