Class BreadthFirstSearch

java.lang.Object
com.sk89q.worldedit.function.visitor.BreadthFirstSearch
All Implemented Interfaces:
Operation
Direct Known Subclasses:
RecursiveVisitor

public abstract class BreadthFirstSearch extends Object implements Operation
Performs a breadth-first search starting from points added with visit(BlockVector3). The search continues to a certain adjacent point provided that the method isVisitable(BlockVector3, BlockVector3) returns true for that point.

As an abstract implementation, this class can be used to implement functionality that starts at certain points and extends outward from those points.

  • Constructor Details

    • BreadthFirstSearch

      protected BreadthFirstSearch(RegionFunction function)
      Create a new instance.
      Parameters:
      function - the function to apply to visited blocks
  • Method Details

    • getDirections

      protected Collection<BlockVector3> getDirections()
      Get the list of directions will be visited.

      Directions are BlockVector3s that determine what adjacent points area available. Vectors should not be unit vectors. An example of a valid direction is BlockVector3.at(1, 0, 1).

      The list of directions can be cleared.

      Returns:
      the list of directions
    • addAxes

      protected void addAxes()
      Add the directions along the axes as directions to visit.
    • addDiagonal

      protected void addDiagonal()
      Add the diagonal directions as directions to visit.
    • visit

      public void visit(BlockVector3 position)
      Add the given location to the list of locations to visit, provided that it has not been visited. The position passed to this method will still be visited even if it fails isVisitable(BlockVector3, BlockVector3).

      This method should be used before the search begins, because if the position does fail the test, and the search has already visited it (because it is connected to another root point), the search will mark the position as "visited" and a call to this method will do nothing.

      Parameters:
      position - the position
    • isVisitable

      protected abstract boolean isVisitable(BlockVector3 from, BlockVector3 to)
      Return whether the given 'to' block should be visited, starting from the 'from' block.
      Parameters:
      from - the origin block
      to - the block under question
      Returns:
      true if the 'to' block should be visited
    • getAffected

      public int getAffected()
      Get the number of affected objects.
      Returns:
      the number of affected
    • resume

      public Operation resume(RunContext run) throws WorldEditException
      Description copied from interface: Operation
      Complete the next step. If this method returns true, then the method may be called again in the future, or possibly never. If this method returns false, then this method should not be called again.
      Specified by:
      resume in interface Operation
      Parameters:
      run - describes information about the current run
      Returns:
      another operation to run that operation again, or null to stop
      Throws:
      WorldEditException - an error
    • cancel

      public void cancel()
      Description copied from interface: Operation
      Abort the current task. After the this method is called, Operation.resume(RunContext) should not be called at any point in the future. This method should not be called after successful completion of the operation. This method must be called if the operation is interrupted before completion.
      Specified by:
      cancel in interface Operation
    • getStatusMessages

      public Iterable<com.sk89q.worldedit.util.formatting.text.Component> getStatusMessages()
      Description copied from interface: Operation
      Gets an iterable of messages that describe the current status of the operation.
      Specified by:
      getStatusMessages in interface Operation
      Returns:
      The status messages