Added preconditions to BreadthFirstSearch and subclasses.

This commit is contained in:
sk89q 2014-03-30 13:48:15 -07:00
parent 25021b4a30
commit 7dc81f8350
4 changed files with 16 additions and 2 deletions

View File

@ -27,6 +27,8 @@ import com.sk89q.worldedit.function.RegionFunction;
import java.util.*;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Performs a breadth-first search starting from points added with
* {@link #visit(com.sk89q.worldedit.Vector)}. The search continues
@ -51,7 +53,8 @@ public abstract class BreadthFirstSearch implements Operation {
*
* @param function the function to apply to visited blocks
*/
public BreadthFirstSearch(RegionFunction function) {
protected BreadthFirstSearch(RegionFunction function) {
checkNotNull(function);
this.function = function;
addAxes();
}

View File

@ -25,6 +25,8 @@ import com.sk89q.worldedit.function.mask.Mask;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Visits adjacent points on the same X-Z plane as long as the points
* pass the given mask, and then executes the provided region
@ -45,6 +47,7 @@ public class DownwardVisitor extends RecursiveVisitor {
*/
public DownwardVisitor(Mask mask, RegionFunction function, int baseY) {
super(mask, function);
checkNotNull(mask);
this.baseY = baseY;

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.function.visitor;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;

View File

@ -23,6 +23,8 @@ import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.function.RegionFunction;
import com.sk89q.worldedit.function.mask.Mask;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* An implementation of an {@link BreadthFirstSearch} that uses a mask to
* determine where a block should be visited.
@ -31,8 +33,15 @@ public class RecursiveVisitor extends BreadthFirstSearch {
private final Mask mask;
/**
* Create a new recursive visitor.
*
* @param mask the mask
* @param function the function
*/
public RecursiveVisitor(Mask mask, RegionFunction function) {
super(function);
checkNotNull(mask);
this.mask = mask;
}