com.waldura.tw
Class Route
java.lang.Object
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:
- a list of cities, maybe empty
- a length, its number of stops
- a distance, the total distance of all its segments
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>
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
cities
private java.util.ArrayList<City> cities
distance
private int distance
Route
Route()
- Instances of this class are created by the
RouteBuilder
.
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