ps2
Class Route

java.lang.Object
  extended by ps2.Route

public class Route
extends Object

A Route is a path that traverses arbitrary GeoSegments, regardless of their names.

Routes are immutable. New Routes can be constructed by adding a segment to the end of a Route. An added segment must be properly oriented; that is, its p1 field must correspond to the end of the original Route, and its p2 field corresponds to the end of the new Route.

Because a Route is not necessarily straight, its length -- the distance traveled by following the path from start to end -- is not necessarily the same as the distance along a straight line between its endpoints.

Lastly, a Route may be viewed as a sequence of geographical features, using the getGeoFeatures() method which returns a List.

Specification Fields
Derived Fields

Constructor Summary
Route(GeoSegment gs)
           
 
Method Summary
 Route addSegment(GeoSegment gs)
          Creates a new route that is equal to this route with gs appended to its end.
 boolean equals(Object o)
          Compares the specified Object with this Route for equality.
 GeoPoint getEnd()
           
 double getEndHeading()
           
 GeoSegment getEndingGeoSegment()
           
 List<GeoFeature> getGeoFeatures()
          Returns a List of GeoFeature objects.
 List<GeoSegment> getGeoSegments()
          Returns a List of GeoSegment objects.
 double getLength()
           
 GeoPoint getStart()
           
 double getStartHeading()
           
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Route

public Route(GeoSegment gs)
Requires:
gs != null
Effects:
Constructs a new Route.
Method Detail

getStart

public GeoPoint getStart()
Returns:
location of the start of the route

getEnd

public GeoPoint getEnd()
Returns:
location of the end of the route

getEndingGeoSegment

public GeoSegment getEndingGeoSegment()
Returns:
the last GeoSegment of the route

getStartHeading

public double getStartHeading()
Returns:
direction (in compass heading) of travel at the start of the route, in degrees

getEndHeading

public double getEndHeading()
Returns:
direction of travel at the end of the route, in degrees

getLength

public double getLength()
Returns:
total length of the route, in miles. NOTE: this is NOT as-the-crow-flies, but rather the total distance required to traverse the route. These values are not necessarily equal.

addSegment

public Route addSegment(GeoSegment gs)
Creates a new route that is equal to this route with gs appended to its end.

Returns:
a new Route r such that r.end = gs.p2 && r.endHeading = gs.heading && r.length = this.length + gs.length
Requires:
gs != null && gs.p1 = this.end

getGeoFeatures

public List<GeoFeature> getGeoFeatures()
Returns a List of GeoFeature objects. The concatenation of the GeoFeatures, in order, is equivalent to this route. No two consecutive GeoFeature objects have the same name.

Returns:
a List of GeoFeatures such that
      this.start        = a.get(0).start
   && this.startHeading = a.get(0).startHeading
   && this.end          = a.get(a.length - 1).end
   && this.endHeading   = a.get(a.length - 1).endHeading
   && this.length       =  sum (0 <= i < a.size) . a.get(i).length
   && for all integers i .
          (0 <= i < a.size - 1 => (a.get(i).name != a.get(i+1).name &&
                                       a.get(i).end   = a.get(i+1).start))
 
See Also:
GeoFeature

getGeoSegments

public List<GeoSegment> getGeoSegments()
Returns a List of GeoSegment objects. The concatentation of the GeoSegments, in order, is equivalent to this route.

Returns:
a List of GeoSegments such that
      this.start        = a.get(0).p1
   && this.startHeading = a.get(0).heading
   && this.end          = a.get( a.size - 1 ).p2
   && this.endHeading   = a.get( a.size - 1 ).heading
   && this.length       =  sum (0 <= i < a.size) . a.get(i).length

 
See Also:
GeoSegment

equals

public boolean equals(Object o)
Compares the specified Object with this Route for equality.

Overrides:
equals in class Object
Returns:
true iff (o instanceof Route) && (o.geoFeatures and this.geoFeatures contain the same elements in the same order).

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
a valid hash code for this.

toString

public String toString()
Overrides:
toString in class Object
Returns:
a string representation of this.