ps2
Class RouteFormatter

java.lang.Object
  extended by ps2.RouteFormatter
Direct Known Subclasses:
DrivingRouteFormatter, WalkingRouteFormatter

public abstract class RouteFormatter
extends Object

A RouteFormatter class knows how to create a textual description of directions from one location to another. The class is abstract to support different textual descriptions.

These classes may be thought of as views on the Route model. (see Sun's buzzword-filled explanation of this design pattern)


Constructor Summary
Constructor and Description
RouteFormatter()
           
 
Method Summary
Modifier and Type Method and Description
 String computeDirections(Route route, double heading)
           Give directions for following this Route, starting at its start point and facing in the specified heading.
abstract  String computeLine(GeoFeature geoFeature, double origHeading)
          Computes a single line of a multi-line directions String that represents the intructions for traversing a single geograhpical feature.
protected  String getTurnString(double origHeading, double newHeading)
          Computes directions to turn based on the heading change.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RouteFormatter

public RouteFormatter()
Method Detail

computeDirections

public String computeDirections(Route route,
                                double heading)

Give directions for following this Route, starting at its start point and facing in the specified heading.

This method should call computeLine for each geographical feature in this route and concatenate the results into a single String.

Parameters:
route - The route for which to print directions.
heading - The initial heading.
Returns:
A newline-terminated directions String giving human-readable directions from start to end along this route.
Requires:
0 ≤ heading < 360 && route != null

computeLine

public abstract String computeLine(GeoFeature geoFeature,
                                   double origHeading)
Computes a single line of a multi-line directions String that represents the intructions for traversing a single geograhpical feature.

Parameters:
geoFeature - The geographical feature to traverse.
origHeading - The initial heading
Returns:
A newline-terminated String that gives directions on how to traverse this geographical feature.
Requires:
geoFeature != null

getTurnString

protected String getTurnString(double origHeading,
                               double newHeading)
Computes directions to turn based on the heading change. Let a be the angle from the original heading to the new heading (that is, a is the difference between the two headings). The turn should be annotated as:

 Continue             if a < 10
 Turn slight right    if 10 ≤ a < 60
 Turn right           if 60 ≤ a < 120
 Turn sharp right     if 120 ≤ a < 179
 U-turn               if 179 ≤ a
 
and likewise for left turns.

Parameters:
origHeading - the start heading
newHeading - the desired new heading
Returns:
English directions to go from the old heading to the new one.
Requires:
  • 0 ≤ origHeading < 360
  • 0 ≤ newHeading < 360