games.strategy.engine.data
Class Route

java.lang.Object
  extended by games.strategy.engine.data.Route
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<Territory>

public class Route
extends java.lang.Object
implements java.io.Serializable, java.lang.Iterable<Territory>

A route between two territories.

A route consists of a start territory, and a sequence of steps. To create a route do, Route aRoute = new Route(); route.setStart(someTerritory); route.add(anotherTerritory); route.add(yetAnotherTerritory);

Version:
1.0
Author:
Sean Bridges
See Also:
Serialized Form

Constructor Summary
Route()
           
Route(java.util.List<Territory> route)
           
Route(Territory start, Territory... route)
           
 
Method Summary
 void add(Territory t)
          Add the given territory to the end of the route.
 boolean allMatch(Match<Territory> aMatch)
          Do all territories in this route match the given match?
 Territory at(int i)
          Get the territory we will be in after the i'th step for this route has been made.
 boolean crossesWater()
          Determines if the route crosses water by checking if any of the territories except the start and end are sea territories.
 boolean equals(java.lang.Object o)
           
 boolean extend(Route baseRoute)
          does this route extend another route
 Territory getEnd()
          Get the last territory in the route, this is the destination.
 int getLength()
           
 java.util.Collection<Territory> getMatches(Match<Territory> aMatch)
          Get all territories in this route match the given match?
 Territory getStart()
          Get the start territory for this route.
 java.util.List<Territory> getTerritories()
          Returns a collection of all territories in this route, including the start.
 int hashCode()
           
 java.util.Iterator<Territory> iterator()
           
static Route join(Route r1, Route r2)
          Join the two routes.
 void setStart(Territory t)
          Set the start of this route.
 boolean someMatch(Match<Territory> aMatch)
          Do some territories in this route match the given match?
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Route

public Route()

Route

public Route(java.util.List<Territory> route)

Route

public Route(Territory start,
             Territory... route)
Method Detail

join

public static Route join(Route r1,
                         Route r2)
Join the two routes. It must be the case that r1.end() equals r2.start() or r1.end() == null and r1.start() equals r2

Returns:
a new Route starting at r1.start() going to r2.end() along r1, r2, or null if the routes cant be joined it the joining would form a loop

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

setStart

public void setStart(Territory t)
Set the start of this route.


getStart

public Territory getStart()
Get the start territory for this route.


crossesWater

public boolean crossesWater()
Determines if the route crosses water by checking if any of the territories except the start and end are sea territories.

Returns:
whether the route encounters water other than at the start of the route.

add

public void add(Territory t)
Add the given territory to the end of the route.


getLength

public int getLength()
Returns:
the number of steps in this route.

at

public Territory at(int i)
Get the territory we will be in after the i'th step for this route has been made.


allMatch

public boolean allMatch(Match<Territory> aMatch)
Do all territories in this route match the given match? The start territory is not tested.


someMatch

public boolean someMatch(Match<Territory> aMatch)
Do some territories in this route match the given match? The start territory is not tested.


getMatches

public java.util.Collection<Territory> getMatches(Match<Territory> aMatch)
Get all territories in this route match the given match? The start territory is not tested.


toString

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

getTerritories

public java.util.List<Territory> getTerritories()
Returns a collection of all territories in this route, including the start.


getEnd

public Territory getEnd()
Get the last territory in the route, this is the destination. If the route consists of only a starting territory, this will return null.


extend

public boolean extend(Route baseRoute)
does this route extend another route


iterator

public java.util.Iterator<Territory> iterator()
Specified by:
iterator in interface java.lang.Iterable<Territory>