com.waldura.tw
Class Route

java.lang.Object
  extended by com.waldura.tw.Route
All Implemented Interfaces:
java.lang.Cloneable

public final class Route
extends java.lang.Object
implements java.lang.Cloneable

This class models a route. A route has the following properties:

Route instances are created by the RouteBuilder.

Version:
$Id: Route.java 2368 2007-08-20 22:08:03Z renaud $
Author:
Renaud Waldura <renaud+tw@waldura.com>

Field Summary
private  java.util.ArrayList<City> cities
           
private  int distance
           
 
Constructor Summary
Route()
          Instances of this class are created by the RouteBuilder.
 
Method Summary
(package private)  void addStop(City stop, int distance)
          Add a new stop to this route with the given distance.
 Route clone()
           
 int getDistance()
           
 City getLastStop()
           
 int getLength()
           
 boolean hasCity(City city)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cities

private java.util.ArrayList<City> cities

distance

private int distance
Constructor Detail

Route

Route()
Instances of this class are created by the RouteBuilder.

Method Detail

clone

public Route clone()
Overrides:
clone in class java.lang.Object

addStop

void addStop(City stop,
             int distance)
Add a new stop to this route with the given distance. If this is the first stop (i.e. the starting point), the distance argument is meaningless.

Parameters:
stop - the next city on this route.
distance - the distance between the previous city and this one.

getDistance

public int getDistance()
Returns:
the total distance of this route.

getLength

public int getLength()
Returns:
the number of stops on this route. The starting city is not considered a stop and thus is not counted.

getLastStop

public City getLastStop()
Returns:
the last stop on this route. The last stop may be the starting point if there are no other stops, or NULL is this route has no stops.

hasCity

public boolean hasCity(City city)
Returns:
whether this route goes through the given city.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object