de.hagenah.diplomacy.map
Class Province

java.lang.Object
  extended by de.hagenah.diplomacy.map.Province
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable

public final class Province
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

The Province class represents a province of a map. A province can have subprovinces, e.g. has the province Bulgaria the three subprovinces east coast, south coast, and land.

See Also:
Serialized Form

Field Summary
static int SPECIAL_COASTALCONVOY
          At this coast convoys are allowed - SpecialSubProvinces is null
static int SPECIAL_GATEWAY
          A gateway - SpecialSubProvinces are the gatekeeper subprovince and the two adjacent subprovinces
static int SPECIAL_NORMAL
          A normal province - SpecialSubProvinces is null
static int SPECIAL_RAILWAY
          A railway - SpecialSubProvinces are the subprovinces of the railway, SpecialCountry is the country that can use the railway
static java.util.Comparator SUMMARY_CENTER_ORDER
          Compares two provinces corresponding to the summary center order
 
Method Summary
 boolean coastalConvoy()
          Can a fleet at the coast of this land province convoy an army?
 int compareTo(java.lang.Object obj)
          Compares two Provinces by Name ignoring case
 boolean equals(java.lang.Object obj)
          Compares two Provinces by Name ignoring case
 java.lang.String getAbbreviation()
          Returns the abbreviation of the province.
 Province getGatekeeper()
          Returns the gatekeeper province for this gateway
 Province getGatewaySide(int side)
          Returns a side of the gateway
 Province getGatewaySide(Province side)
          Returns the other side of the gateway
 java.lang.String getName()
          Returns the name of the province.
 java.util.List getRailway()
          Returns the railway subprovinces
 java.util.List getRailway(SubProvince start, SubProvince end)
          Returns the railway subprovinces (except start) if an army moves from start to end.
 Country getRailwayOwner()
          Return the owner of the railway (only his units can use it).
 int getSpecial()
          Returns whether or not this province is a special province
 java.util.Collection getSpecialProvinces()
          Returns all special provinces that influence this province.
 SubProvince getSubProvince(int coast)
          Retrieves the SubProvince with the specified coast.
 SubProvince getSubProvince(java.lang.String coast)
          Retrieves the SubProvince with the specified coast.
 java.util.SortedSet getSubProvinces()
          Returns all SubProvinces.
 int hashCode()
          Returns a hashcode for this Province.
 boolean hasSubProvince(int coast)
          Has this province a SubProvince with the specified coast?
 boolean isCenter()
          Is a center in the province?
 boolean isCenter(Country country)
          Is this province a center for country?
 boolean isGateway()
          Is this province a gateway?
 boolean isRailway()
          Is this province a railway?
 boolean isSea()
          Is it a sea province?
 java.lang.String toString()
          Returns the name of the province
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SUMMARY_CENTER_ORDER

public static final java.util.Comparator SUMMARY_CENTER_ORDER
Compares two provinces corresponding to the summary center order


SPECIAL_NORMAL

public static final int SPECIAL_NORMAL
A normal province - SpecialSubProvinces is null

See Also:
Constant Field Values

SPECIAL_RAILWAY

public static final int SPECIAL_RAILWAY
A railway - SpecialSubProvinces are the subprovinces of the railway, SpecialCountry is the country that can use the railway

See Also:
Constant Field Values

SPECIAL_GATEWAY

public static final int SPECIAL_GATEWAY
A gateway - SpecialSubProvinces are the gatekeeper subprovince and the two adjacent subprovinces

See Also:
Constant Field Values

SPECIAL_COASTALCONVOY

public static final int SPECIAL_COASTALCONVOY
At this coast convoys are allowed - SpecialSubProvinces is null

See Also:
Constant Field Values
Method Detail

getName

public java.lang.String getName()
Returns the name of the province.


getAbbreviation

public java.lang.String getAbbreviation()
Returns the abbreviation of the province.


isSea

public boolean isSea()
Is it a sea province?


isCenter

public boolean isCenter()
Is a center in the province?


isCenter

public boolean isCenter(Country country)
Is this province a center for country? E.g. Hong Kong in Colonial is a center but it isn't a center for China.

Parameters:
country - The owner of the center

getSubProvinces

public java.util.SortedSet getSubProvinces()
Returns all SubProvinces.


getSubProvince

public SubProvince getSubProvince(java.lang.String coast)
                           throws java.lang.IllegalArgumentException
Retrieves the SubProvince with the specified coast.

Parameters:
coast - The Coast of the province (!=null).
Returns:
The SubProvince (!=null).
Throws:
java.lang.IllegalArgumentException

getSubProvince

public SubProvince getSubProvince(int coast)
                           throws java.lang.IllegalArgumentException
Retrieves the SubProvince with the specified coast.

Parameters:
coast - The Coast of the province.
Returns:
The SubProvince (!=null).
Throws:
java.lang.IllegalArgumentException

hasSubProvince

public boolean hasSubProvince(int coast)
Has this province a SubProvince with the specified coast?

Parameters:
coast - The Coast of the province.
Returns:
true if it has such a SubProvince, false otherwise

getRailway

public java.util.List getRailway()
Returns the railway subprovinces

Returns:
The subprovinces of the railway (SubProvince objects), unmodifiable
Throws:
java.lang.IllegalArgumentException - If this province isn't a railway

getRailwayOwner

public Country getRailwayOwner()
Return the owner of the railway (only his units can use it).


getRailway

public java.util.List getRailway(SubProvince start,
                                 SubProvince end)
Returns the railway subprovinces (except start) if an army moves from start to end.

Parameters:
start - The current position of the army (must be part of the railway)
end - The target of the army (must be part of the railway)
Returns:
The subprovinces of the railway(SubProvince objects), unmodifiable
Throws:
java.lang.IllegalArgumentException - If this province isn't a railway

getGatekeeper

public Province getGatekeeper()
Returns the gatekeeper province for this gateway

Returns:
The gatekeeper
Throws:
java.lang.IllegalArgumentException - If this province isn't a gateway

getGatewaySide

public Province getGatewaySide(int side)
Returns a side of the gateway

Parameters:
side - The side of the gateway (0 or 1)
Returns:
The side of the gateway
Throws:
java.lang.IllegalArgumentException - If this province isn't a gateway or side is not 0 or 1

getGatewaySide

public Province getGatewaySide(Province side)
Returns the other side of the gateway

Parameters:
side - One side of the gateway
Returns:
The other side of the gateway
Throws:
java.lang.IllegalArgumentException - If this province isn't a gateway or side is not a side of the gateway

getSpecial

public int getSpecial()
Returns whether or not this province is a special province


getSpecialProvinces

public java.util.Collection getSpecialProvinces()
Returns all special provinces that influence this province.

Returns:
A list (Province objects) with the railways through this province and all gateways where this province is a gatekeeper or a side of the gateway.

isRailway

public boolean isRailway()
Is this province a railway?


isGateway

public boolean isGateway()
Is this province a gateway?


coastalConvoy

public boolean coastalConvoy()
Can a fleet at the coast of this land province convoy an army?


equals

public boolean equals(java.lang.Object obj)
Compares two Provinces by Name ignoring case

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object obj)
Compares two Provinces by Name ignoring case

Specified by:
compareTo in interface java.lang.Comparable

hashCode

public int hashCode()
Returns a hashcode for this Province.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns the name of the province

Overrides:
toString in class java.lang.Object