de.hagenah.diplomacy.game
Class Turn

java.lang.Object
  extended by de.hagenah.diplomacy.game.Turn
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable
Direct Known Subclasses:
DipTurn

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

The Turn class contains the state of the board for one phase.

See Also:
Serialized Form

Field Summary
static int NUMBER_FIRST
          Number of the first turn
static int TOSTRING_BUILDS
          Includes the builds
static int TOSTRING_CENTERS
          Includes the centers
static int TOSTRING_CSS
          The CSS class color-?
static int TOSTRING_DISLODGEDUNITS
          Includes the dislodged units
static int TOSTRING_HTML
          Returns a xhtml text, e.g. → instead of ->
static int TOSTRING_ORDERS
          Includes the orders
static int TOSTRING_SHORT
          Returns a short text
 
Constructor Summary
Turn(int number, Phase phase)
          Creates a new Turn
 
Method Summary
 void addDislodgedUnit(Unit dislodgedunit)
          Adds a dislodged unit.
 boolean addOrder(Order order)
          Adds an order.
 void addUnit(Unit unit)
          Adds a unit.
 boolean areBuildsKnown()
          Return true is the builds of this turn are known.
 boolean areCentersKnown()
          Return true is the centers of this turn are known.
 boolean areDislodgedUnitsKnown()
          Return true is the dislodged units of this turn are known.
 boolean areNoOrdersNeeded(Country country)
          Are no orders needed for the country?
 boolean areOrdersKnown()
          Return true is the orders of this turn are known.
 boolean areUnitsKnown()
          Return true is the units of this turn are known.
 int compareTo(java.lang.Object obj)
          Compares two Turns by Number
 boolean equals(java.lang.Object obj)
          Compares two Turns by Number
 java.util.Map getBuilds()
          Returns all builds (Country -> Integer).
 int getBuilds(Country country)
          Returns the builds for a country.
 Country getCenter(Province center)
          Returns the owner of a center or null.
 java.util.Map getCenters()
          Returns all centers (Province -> Country).
 java.util.SortedSet getCenters(Country owner)
          Returns all centers (Province) of owner.
 java.util.Date getDeadline()
          Returns the deadline of the turn (can be null)
 Unit getDislodgedUnit(Province province)
          Returns the dislodged unit in a province or null.
 java.util.Map getDislodgedUnits()
          Returns all dislodged units (Country -> Unit).
 java.lang.String getMissingInformation(boolean mostrecent)
          Returns which information is missing.
 int getNumber()
          Returns the number of the turn.
 Order getOrder(Country country, Province province)
          Returns the order of the country for the unit in province.
 Order getOrder(Province province)
          Returns the executed order for the unit in province. null if there is not order, there are circular proxy orders or the unit for the province is missing.
 java.util.SortedSet getOrders()
          Returns all orders.
 Phase getPhase()
          Returns the phase of the turn.
 Unit getUnit(Province province)
          Returns the unit in a province or null.
 Country getUnitCountry(Province province)
          Returns the owner of the unit in province.
 java.util.Map getUnits()
          Returns all units (Province -> Unit).
 java.util.Collection getWaiveOrders(Country country)
          Returns all waive orders of the country (Order objects)
 int hashCode()
          Returns a hashcode for this turn.
 boolean isComplete(boolean mostrecent)
          Is all possible data there?
 void removeDislodgedUnit(Province province)
          Removes a dislodged unit.
 boolean removeOrder(Order order)
          Removes a order.
 void removeUnit(Province province)
          Removes a unit.
 void setBuilds(Country country, int units)
          Sets the builds for a country
 void setBuilds(java.util.Map builds)
          Sets the builds for this turn (Country -> Integer).
 void setCenter(Province center, Country owner)
          Sets the owner for a center
 void setCenters(java.util.Map centers)
          Sets the centers for this turn.
 void setDeadline(java.util.Date deadline)
          Returns the deadline of the turn (can be null)
 void setDislodgedUnits(java.util.Collection dislodgedunits)
          Sets the dislodged units for this turn.
 void setOrders(java.util.Collection orders)
          Sets the orders for this turn.
 void setUnits(java.util.Collection units)
          Sets the units for this turn.
 java.lang.String toString()
          Returns the phase of the turn, e.g.
 java.lang.String toString(int flags)
          Returns a description of the turn.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NUMBER_FIRST

public static final int NUMBER_FIRST
Number of the first turn

See Also:
Constant Field Values

TOSTRING_SHORT

public static final int TOSTRING_SHORT
Returns a short text

See Also:
Constant Field Values

TOSTRING_HTML

public static final int TOSTRING_HTML
Returns a xhtml text, e.g. → instead of ->

See Also:
Constant Field Values

TOSTRING_CSS

public static final int TOSTRING_CSS
The CSS class color-? (e.g. color-m) is used for the color

See Also:
Constant Field Values

TOSTRING_ORDERS

public static final int TOSTRING_ORDERS
Includes the orders

See Also:
Constant Field Values

TOSTRING_DISLODGEDUNITS

public static final int TOSTRING_DISLODGEDUNITS
Includes the dislodged units

See Also:
Constant Field Values

TOSTRING_BUILDS

public static final int TOSTRING_BUILDS
Includes the builds

See Also:
Constant Field Values

TOSTRING_CENTERS

public static final int TOSTRING_CENTERS
Includes the centers

See Also:
Constant Field Values
Constructor Detail

Turn

public Turn(int number,
            Phase phase)
Creates a new Turn

Method Detail

getNumber

public int getNumber()
Returns the number of the turn.


getPhase

public Phase getPhase()
Returns the phase of the turn.


areUnitsKnown

public boolean areUnitsKnown()
Return true is the units of this turn are known.


getUnit

public Unit getUnit(Province province)
Returns the unit in a province or null.


getUnits

public java.util.Map getUnits()
Returns all units (Province -> Unit).


areDislodgedUnitsKnown

public boolean areDislodgedUnitsKnown()
Return true is the dislodged units of this turn are known.


getDislodgedUnit

public Unit getDislodgedUnit(Province province)
Returns the dislodged unit in a province or null.


getDislodgedUnits

public java.util.Map getDislodgedUnits()
Returns all dislodged units (Country -> Unit).


getDeadline

public java.util.Date getDeadline()
Returns the deadline of the turn (can be null)


setDeadline

public void setDeadline(java.util.Date deadline)
Returns the deadline of the turn (can be null)


areCentersKnown

public boolean areCentersKnown()
Return true is the centers of this turn are known.


getCenter

public Country getCenter(Province center)
Returns the owner of a center or null.


getCenters

public java.util.Map getCenters()
Returns all centers (Province -> Country).


getCenters

public java.util.SortedSet getCenters(Country owner)
Returns all centers (Province) of owner.


areBuildsKnown

public boolean areBuildsKnown()
Return true is the builds of this turn are known.


getBuilds

public int getBuilds(Country country)
Returns the builds for a country.


getBuilds

public java.util.Map getBuilds()
Returns all builds (Country -> Integer).


areOrdersKnown

public boolean areOrdersKnown()
Return true is the orders of this turn are known.


getOrder

public Order getOrder(Country country,
                      Province province)
Returns the order of the country for the unit in province.


getWaiveOrders

public java.util.Collection getWaiveOrders(Country country)
Returns all waive orders of the country (Order objects)


getUnitCountry

public Country getUnitCountry(Province province)
Returns the owner of the unit in province. If province is a gateway the owner of the unit in the gatekeeper province is returned.

Parameters:
province - The province
Returns:
The owner, null if there is no unit in province.
Throws:
java.lang.NullPointerException - If the units are not known
java.lang.IllegalArgumentException - If the phase is not a movement phase

getOrder

public Order getOrder(Province province)
Returns the executed order for the unit in province. null if there is not order, there are circular proxy orders or the unit for the province is missing.

Throws:
java.lang.NullPointerException - If the units or orders are not known
java.lang.IllegalArgumentException - If the phase is not a movement phase

getOrders

public java.util.SortedSet getOrders()
Returns all orders.


isComplete

public boolean isComplete(boolean mostrecent)
Is all possible data there?

Parameters:
mostrecent - Is it the most recent turn of the game?
Returns:
true <=> All possible data there.

getMissingInformation

public java.lang.String getMissingInformation(boolean mostrecent)
Returns which information is missing.

Parameters:
mostrecent - Is it the most recent turn of the game?
Returns:
Description of the missing information, e.g "units and centers", or null if no information is missing

setUnits

public void setUnits(java.util.Collection units)
Sets the units for this turn. Note: A Unit object must not be used in two two different turns.


addUnit

public void addUnit(Unit unit)
Adds a unit. Note:A Unit object must not be used in two two different turns.


removeUnit

public void removeUnit(Province province)
Removes a unit.


setDislodgedUnits

public void setDislodgedUnits(java.util.Collection dislodgedunits)
Sets the dislodged units for this turn. Note: A Unit object must not be used in two two different turns.


addDislodgedUnit

public void addDislodgedUnit(Unit dislodgedunit)
Adds a dislodged unit. Note: A Unit object must not be used in two two different turns.


removeDislodgedUnit

public void removeDislodgedUnit(Province province)
Removes a dislodged unit.


setCenters

public void setCenters(java.util.Map centers)
Sets the centers for this turn.


setCenter

public void setCenter(Province center,
                      Country owner)
Sets the owner for a center


setBuilds

public void setBuilds(java.util.Map builds)
Sets the builds for this turn (Country -> Integer).


setBuilds

public void setBuilds(Country country,
                      int units)
Sets the builds for a country


setOrders

public void setOrders(java.util.Collection orders)
Sets the orders for this turn.


areNoOrdersNeeded

public boolean areNoOrdersNeeded(Country country)
Are no orders needed for the country?

Parameters:
country - The country
Returns:
true if no orders are needed, false if orders are needed or some information is missing

addOrder

public boolean addOrder(Order order)
Adds an order.

Parameters:
order - The order to add
Returns:
true if the order was added, false if such an order (same owner and province) already existed

removeOrder

public boolean removeOrder(Order order)
Removes a order.

Parameters:
order - The order to remove
Returns:
true if an order was removed, false if no order was removed

equals

public boolean equals(java.lang.Object obj)
Compares two Turns by Number

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object obj)
Compares two Turns by Number

Specified by:
compareTo in interface java.lang.Comparable

hashCode

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

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns the phase of the turn, e.g. "Winter 1901 Adjustment".

Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(int flags)
Returns a description of the turn.

Parameters:
flags - TOSTRING_SHORT, TOSTRING_HTML, TOSTRING_CSS, TOSTRING_ORDERS, TOSTRING_DISLODGEDUNITS, TOSTRING_BUILDS