|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectbecker.robots.Sim
becker.robots.Intersection
public class Intersection
Karel the Robot lives in a city composed of intersections connected by roads. Roads that run north and south (up and down) are called "Avenues" and roads that run east and west are called "Streets".
Intersections may contain Things such as Flashers,
Walls or Streetlights. Some kinds of things block
robots from entering or exiting an intersection. It is possible
to build things which are one-way, blocking robots from entering but
not exiting (or visa versa) an intersection.
| Constructor Summary | |
|---|---|
Intersection(City city,
int street,
int avenue)
Construct a new intersection. |
|
| Method Summary | |
|---|---|
protected void |
addSim(Sim theSim)
Add a sim to this intersection. |
int |
countSims(IPredicate pred)
Determine the number of sims currently on this intersection that match the given predicate. |
int |
countThings()
Determine the number of Things currently on this intersection. |
protected boolean |
entryIsBlocked(Direction dir)
Determine whether something on this intersection blocks robots from entering the intersection from the given direction. |
IIterate<Light> |
examineLights(IPredicate aPredicate)
Examine all the lights on this intersection that match the given predicate, one at a time. |
IIterate<Robot> |
examineRobots(IPredicate aPredicate)
Examine all the robots on this intersection that match the given predicate, one at a time. |
IIterate<Thing> |
examineThings()
Examine all the Things that are on this intersection, one at a time. |
IIterate<Thing> |
examineThings(IPredicate aPredicate)
Examine all the things on this intersection that match the given predicate, one at a time. |
protected boolean |
exitIsBlocked(Direction dir)
Determine whether something on this intersection blocks robots from exiting the intersection. |
int |
getAvenue()
The avenue intersecting this intersection. |
protected Intersection |
getIntersection()
Return this intersection. |
String |
getLabel()
Get the label for this intersection. |
Intersection |
getNeighbor(Direction dir)
The intersection neighboring this one in the given direction. |
int |
getStreet()
The street intersecting this intersection. |
int |
hashCode()
Used internally. |
protected void |
removeSim(Sim s)
Remove the given Sim (robot, flasher, streetlight, wall, and so on) from this intersection. |
protected void |
save(String indent,
PrintWriter out)
Save a representation of this intersection to an output stream. |
void |
setLabel(String aLabel)
Set a label for this intersection. |
String |
toString()
Report the internal state of the intersection. |
| Methods inherited from class becker.robots.Sim |
|---|
getCity, getColor, getIcon, keyTyped, notifyObservers, notifyObservers, setColor, setIcon |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Intersection(City city,
int street,
int avenue)
city - The city in which this intersection exists.avenue - The intersection's avenue within the city.street - The intersection's street within the city.| Method Detail |
|---|
public Intersection getNeighbor(Direction dir)
dir - the direction of the desired neighboring
intersection.
public void setLabel(String aLabel)
setLabel in interface ILabelaLabel - the new labelpublic String getLabel()
getLabel in interface ILabelpublic String toString()
toString in class Simpublic final int getAvenue()
public final int getStreet()
public int hashCode()
hashCode in class Objectprotected Intersection getIntersection()
getIntersection in class Simprotected boolean exitIsBlocked(Direction dir)
dir - the direction to check for a blockage.
One of {Direction.NORTH, SOUTH, EAST, WEST}.
direction is blocked from
exiting the intersection; false otherwise.protected boolean entryIsBlocked(Direction dir)
dir - the direction to check for a blockage.
One of {Direction.NORTH, SOUTH, EAST, WEST}.
direction side
is blocked from entering the intersection; false otherwise.protected void addSim(Sim theSim)
theSim - The sim to add.removeSim(becker.robots.Sim)protected void removeSim(Sim s)
s - The Sim to remove. It is an error to attempt to
remove a Sim which isn't on this intersection.addSim(becker.robots.Sim)public int countThings()
public int countSims(IPredicate pred)
pred - the predicate that determines which sims to count
protected void save(String indent,
PrintWriter out)
indent - the indentation, for formatting purposesout - the output streampublic IIterate<Thing> examineThings()
Things that are on this intersection, one at a time.
examineThings returns an iterator, which may be used as follows:
Thing can be obtained from this intersection with
Thing t = anIntersection.examineThings().next();If there are no things on the intersection, an exception is thrown.
for(Thing t : anIntersection.examineThings())
{ // do something with t
} Iteratorthings = anIntersection.examineThings(); while (things.hasNext()) { Thing t = things.next(); // do something with t }
public IIterate<Thing> examineThings(IPredicate aPredicate)
Thing can be obtained with
Thing t = anIntersection.examineThings(aPredicate).next();If there are no things matching the predicate on the intersection, an exception is thrown. All of the things on the intersection that match the predicate can be obtained, one at a time, with
for(Thing t : anIntersection.examineThings(aPredicate))
{ // do something with t
}
aPredicate - A predicate used to test whether a thing should be
included in the iteration.
public IIterate<Robot> examineRobots(IPredicate aPredicate)
examineThings(IPredicate aPredicate).
aPredicate - A predicate used to test whether a robot should be
included in the iteration.
public IIterate<Light> examineLights(IPredicate aPredicate)
examineThings(IPredicate aPredicate).
aPredicate - A predicate used to test whether a light should be
included in the iteration.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||