becker.robots
Interface IPredicate


public interface IPredicate

A predicate says whether something is true or false about a Sim. A class implementing the IPredicate interface does this via the isOK method which returns true if some condition about a Sim is true and false otherwise.

A typical use for a predicate is to find a certain kind of thing for a robot to examine; for example, a Light. To do this, define a class implementing IPredicate as follows:

  public class ALightPred implements IPredicate
  {  //return true if the Sim passed is a Light, false otherwise
     public boolean isOK(Sim s)
     {  return s instanceof Light;
     }
  }

In a subclass of Robot invoke the examineThings method like this:

    Light t = this.examineLights(new ALightPred()).next()
which will return a light from the current intersection that matches the predicate, if there is one, and throw an exception if there is not. The isBesideThing method in the Robot class can be used to determine if the specified kind of Thing is available.

IPredicate also defines a number of useful predicates as constants. For example, to pick up a Thing that is a Flasher, one could write

  karel.pickThing(IPredicate.aFlasher);

Author:
Byron Weber Becker

Field Summary
static IPredicate aFlasher
          A predicate to test whether something is a Flasher.
static IPredicate aLight
          A predicate to test whether something is a Light.
static IPredicate anyFlasher
          A predicate to test whether something is a Flasher or a subclass of Flasher.
static IPredicate anyLight
          A predicate to test whether something is a Light or a subclass of Light.
static IPredicate anyRobot
          A predicate to test whether something is a Robot or a subclass of Robot.
static IPredicate anyStreetlight
          A predicate to test whether something is a Streetlight or a subclass of Streetlight.
static IPredicate anyThing
          A predicate to test whether something is a Thing or a subclass of Thing.
static IPredicate anyWall
          A predicate to test whether something is a Wall or a subclass of Wall.
static IPredicate aRobot
          A predicate to test whether something is a Robot.
static IPredicate aStreetlight
          A predicate to test whether something is a Streetlight.
static IPredicate aThing
          A predicate to test whether something is a Thing.
static IPredicate aWall
          A predicate to test whether something is a Wall.
static IPredicate canBeCarried
          A predicate to test whether the Thing is something that a robot can carry.
 
Method Summary
 boolean isOK(Sim theSim)
          Return true if a certain condition is true about theSim; false otherwise.
 

Field Detail

aFlasher

static final IPredicate aFlasher
A predicate to test whether something is a Flasher. Example Usage: karel.pickThing(IPredicate.aFlasher); to pick up a Flasher (but not a subclass of Flasher) from the current intersection.


anyFlasher

static final IPredicate anyFlasher
A predicate to test whether something is a Flasher or a subclass of Flasher. Example Usage: karel.pickThing(IPredicate.anyFlasher); to pick up a Flasher (or a subclass of Flasher) from the current intersection.


aLight

static final IPredicate aLight
A predicate to test whether something is a Light. Example Usage: karel.pickThing(IPredicate.aLight); to pick up a Light (but not a subclass of Light) from the current intersection.


anyLight

static final IPredicate anyLight
A predicate to test whether something is a Light or a subclass of Light. Example Usage: karel.pickThing(IPredicate.anyLight); to pick up a Light (or a subclass of Light) from the current intersection.


aRobot

static final IPredicate aRobot
A predicate to test whether something is a Robot. Example Usage: karel.pickThing(IPredicate.aRobot); to examine a Robot (but not a subclass of Robot) from the current intersection.


anyRobot

static final IPredicate anyRobot
A predicate to test whether something is a Robot or a subclass of Robot. Example Usage: karel.pickThing(IPredicate.anyRobot); to examine a Robot (or a subclass of Robot) from the current intersection.


aStreetlight

static final IPredicate aStreetlight
A predicate to test whether something is a Streetlight. Example Usage: karel.examineThing(IPredicate.aStreetlight); to examine a Streetlight (but not a subclass of Streetlight) from the current intersection.


anyStreetlight

static final IPredicate anyStreetlight
A predicate to test whether something is a Streetlight or a subclass of Streetlight. Example Usage: karel.examineThing(IPredicate.anyStreetlight); to examine a Streetlight (or a subclass of Streetlight) from the current intersection.


aThing

static final IPredicate aThing
A predicate to test whether something is a Thing. Example Usage: karel.pickThing(IPredicate.aThing); to pick up a Thing (but not a subclass of Thing) from the current intersection.


anyThing

static final IPredicate anyThing
A predicate to test whether something is a Thing or a subclass of Thing. Example Usage: karel.pickThing(IPredicate.anyThing); to pick up a Thing (or a subclass of Thing) from the current intersection.


canBeCarried

static final IPredicate canBeCarried
A predicate to test whether the Thing is something that a robot can carry. Example Usage: karel.pickThing(IPredicate.canBeCarried); to pick up a Thing (or a subclass of Thing) from the current intersection.


aWall

static final IPredicate aWall
A predicate to test whether something is a Wall. Example Usage: karel.examineThing(IPredicate.aWall); to examine a Wall (but not a subclass of Wall) from the current intersection.


anyWall

static final IPredicate anyWall
A predicate to test whether something is a Wall or a subclass of Wall. Example Usage: karel.pickThing(IPredicate.aWallPred); to examine a Wall (or a subclass of Wall) from the current intersection.

Method Detail

isOK

boolean isOK(Sim theSim)
Return true if a certain condition is true about theSim; false otherwise.

Parameters:
theSim - The Sim object to test.
Returns:
true if a condition is true; false otherwise.