All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class busrider.Location

java.lang.Object
   |
   +----busrider.Location

public class Location
extends Object
This class represents a location. This is either a junction or a point along a segment plus a direction. A Location is mutable but easily copied.


Constructor Index

Location(Junction)
constructs a location at the given junction.
Location(Location)
copies a Location.

Method Index

getDistanceTraversed()
returns the distance already traversed along the Segment, or -1 if at a junction.
getJunction()
returns the location's junction, or null if within a segment.
getNextJunction()
returns the "moving to" junction of the location, or null if at a junction.
getPrevJunction()
returns the "moving from" junction of the location, or null if at a junction.
getSegment()
returns the location's segment, or null if at a junction.
setSegment(Segment)
sets the location's segment.
toString()
returns a string representation.
travel(int)
moves the location along a segment.

Constructors

Location
 public Location(Junction junc)
constructs a location at the given junction.

Location
 public Location(Location loc)
copies a Location.

Methods

getJunction
 public Junction getJunction()
returns the location's junction, or null if within a segment.

getSegment
 public Segment getSegment()
returns the location's segment, or null if at a junction.

getPrevJunction
 public Junction getPrevJunction()
returns the "moving from" junction of the location, or null if at a junction.

getNextJunction
 public Junction getNextJunction()
returns the "moving to" junction of the location, or null if at a junction.

getDistanceTraversed
 public int getDistanceTraversed()
returns the distance already traversed along the Segment, or -1 if at a junction.

toString
 public String toString()
returns a string representation. It shows: junction; or source-junction, destination-junction, and distance from source-junction.

Overrides:
toString in class Object
setSegment
 public void setSegment(Segment seg)
sets the location's segment. The location must be a junction, and that junction must be one of the segment's endpoints. That junction becomes the source junction; the segment's other junction becomes the destination junction. The distance-from-source-junction is zero.

travel
 public int travel(int distance)
moves the location along a segment. If at a junction, the method just returns. Otherwise, motion goes in the Location's direction. The distance parm specifies how far to move. Either way, the return value indicates how much motion remains.


All Packages  Class Hierarchy  This Package  Previous  Next  Index