de.hagenah.diplomacy.game
Class Unit

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

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

The Unit class represents an unit in a phase of a game.

See Also:
Serialized Form

Field Summary
static int TOSTRING_COUNTRY
          Includes the country, e.g.
static int TOSTRING_CSS
          The CSS class color-?
static int TOSTRING_HTML
          Returns a xhtml text, e.g. → instead of ->
static int TOSTRING_JUDGE
          Judge compatible output, e.g.
static int TOSTRING_LIST
          Returns a list output, e.g.
static int TOSTRING_RETREATS
          Includes the retreats, e.g.
static int TOSTRING_SHORT
          Returns a short text, e.g.
 
Constructor Summary
Unit(Country country, SubProvince subprovince)
          Creates a unit that cannot retreat.
Unit(Country country, SubProvince subprovince, java.util.Collection retreats)
          Creates a dislodged unit.
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compares two Units by Country, SubProvince, Retreats.
 boolean equals(java.lang.Object obj)
          Compares two Units by Country, SubProvince, Retreats.
 Country getCountry()
          Returns the owner of the unit.
 java.util.SortedSet getRetreats()
          Returns all possible retreats. null if the unit cannot retreat.
 SubProvince getSubProvince()
          Returns the subprovince in which the unit is.
 int hashCode()
          Returns a hashcode for this unit.
 boolean isDislodged()
          Is the unit dislodged?
 boolean isFleet()
          Is the unit a fleet?
 java.lang.String toString()
          Returns a description of the unit, e.g.
 java.lang.String toString(int flags)
          Returns a text for this unit.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TOSTRING_LIST

public static final int TOSTRING_LIST
Returns a list output, e.g. "Fleet Ionian Sea"

See Also:
Constant Field Values

TOSTRING_SHORT

public static final int TOSTRING_SHORT
Returns a short text, e.g. "F ION"

See Also:
Constant Field Values

TOSTRING_COUNTRY

public static final int TOSTRING_COUNTRY
Includes the country, e.g. "Turkish fleet in the Ionian Sea"

See Also:
Constant Field Values

TOSTRING_RETREATS

public static final int TOSTRING_RETREATS
Includes the retreats, e.g. "fleet in the Ionian Sea can retreat to Aegean Sea"

See Also:
Constant Field Values

TOSTRING_JUDGE

public static final int TOSTRING_JUDGE
Judge compatible output, e.g. "The fleet in the Ionian Sea."

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
Constructor Detail

Unit

public Unit(Country country,
            SubProvince subprovince)
Creates a unit that cannot retreat.

Parameters:
country - Owner of the unit
subprovince - Subprovince in which the unit is

Unit

public Unit(Country country,
            SubProvince subprovince,
            java.util.Collection retreats)
Creates a dislodged unit.

Parameters:
country - Owner of the unit (!=null).
subprovince - Subprovince in which the unit is (!=null).
retreats - Subprovinces to which the unit can retreat (!=null). Must not be empty, contain null or duplicated values or provinces that are not neighbours.
Method Detail

getCountry

public Country getCountry()
Returns the owner of the unit.


getSubProvince

public SubProvince getSubProvince()
Returns the subprovince in which the unit is.


isDislodged

public boolean isDislodged()
Is the unit dislodged?


getRetreats

public java.util.SortedSet getRetreats()
Returns all possible retreats. null if the unit cannot retreat.


isFleet

public boolean isFleet()
Is the unit a fleet?


equals

public boolean equals(java.lang.Object obj)
Compares two Units by Country, SubProvince, Retreats.

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object obj)
Compares two Units by Country, SubProvince, Retreats.

Specified by:
compareTo in interface java.lang.Comparable

hashCode

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

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString(int flags)
Returns a text for this unit.

Parameters:
flags - TOSTRING_LIST, TOSTRING_COUNTRY, TOSTRING_RETREATS, TOSTRING_SHORT, TOSTRING_JUDGE, TOSTRING_HTML, TOSTRING_CSS
Returns:
The text

toString

public java.lang.String toString()
Returns a description of the unit, e.g. "Turkey: Fleet Ionian Sea can retreat to Aegean Sea.".

Overrides:
toString in class java.lang.Object