de.hagenah.diplomacy.game
Class Game

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

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

The Game class contains all Turns of a game.

See Also:
Serialized Form

Constructor Summary
Game(java.lang.String name, java.lang.String judge, MapData map)
          Creates a new Game
 
Method Summary
protected  boolean areMessagesCached()
          Returns whether or not messages are cached
 int compareTo(java.lang.Object obj)
          Compares two Games by Name and Judge
 DiaryEntry createDiaryEntry(Person from, int number, java.lang.String text, Phase phase)
          Creates a new diary entry (if the diary entry doesn't already exist)
 Message createMessage(boolean anonymous, Person from, boolean toallbut, java.util.Collection to, boolean faketoallbut, java.util.Collection faketo, java.lang.String text, java.util.Date date)
          Creates a new broadcast/press message (if the message doesn't already exist)
 Turn createTurn(int number, Phase phase, java.util.Date turndate)
          Retrieves the specified turn.
 void deleteDiaryEntry(DiaryEntry entry)
          Deletes a diary entry.
 void deleteMessage(Message msg)
          Removes the message msg.
 boolean equals(java.lang.Object obj)
          Compares two Games by Name and Judge
 java.lang.String getComment()
          Returns the game comment, null if unknown (Note: \n is used as line separator)
 java.lang.String getDescription()
          Returns a string with the variant, the victor(s), the persons, the parameters, and the comment
 java.util.List getDiaryEntries(int number)
          Returns a (ordered) list with the diary entries for the specified turn.
 DiaryEntry getDiaryEntry(Person from, int number)
          Returns the specified diary entry.
 int getDiaryEntryTurn(DiaryEntry entry)
          Returns the turn for the specified diary entry
 Person getIdentity()
          Returns your role in this game (a country, master, or observer).
 java.lang.String getJudge()
          Returns the judge of the game.
 Phase getLastPhase()
          Returns the last phase of this game, null if unknown
 MapData getMap()
          Returns the map of the game.
 java.util.List getMessages(int number)
          Returns a (ordered) list with the messages for the specified turn.
 int getMessageTurn(Message msg)
          Returns the turn for the specified message
 Turn getMostRecentTurn()
          Returns the most recent turn of the game or null if there are no turns
 java.lang.String getName()
          Returns the name of the game.
 java.util.SortedSet getOptions()
          Returns the options of the game.
 java.lang.String getParameter(java.lang.String parameter)
          Returns the specified parameter
 java.util.Map getParameters()
          Returns the parameters of the game, null if unknown (keys without a trailing colon, values without a trailing dot, keys and values without leading or trailing whitespace).
 java.lang.String getParameterValue(java.lang.String parameter, java.lang.String key)
          Returns the value of a key of a parameter, e.g.
 java.util.SortedSet getPersonInfo()
          Returns all person informations
 java.util.Map getSpecialCenters(Phase phase)
          Returns the special centers for the specified phase.
 java.util.Map getSpecialPhaseCenters(Phase phase)
          Returns the special phase centers.
 Turn getTurn(int number)
          Returns a turn of the game or null.
 Turn getTurn(Phase phase)
          Returns a turn of the game or null.
 java.util.Date getTurnDate(int number)
          Returns the date of the turn.
 int getTurnIndex(int number)
          Returns a index of the turn .
 java.util.Collection getTurns()
          Returns all turns of the game
 java.util.SortedSet getVictors()
          Returns the victor resp. the draw participants, null if unknown
 int hashCode()
          Returns a hashcode for this game.
 boolean hasOption(java.lang.String option)
          Is the option for the game set?
 boolean hasParameterFlag(java.lang.String parameter, java.lang.String flag)
          Tests whether or not the specified flag is set in the specified parameter.
protected  Turn internCreateTurn(int number, Phase phase)
          Creates a Turn object
 void processTurns()
          Calculates data that can be calculated from the existing data and that the JudgeParser does not set.
 void rollback(int number, boolean removeallorders)
          Rolls the game back to the turn number.
 void setComment(java.lang.String comment)
          Sets the game comment (Note: \n is used as line separator)
 void setIdentity(Person identity)
          Sets your role in this game (a country, master, or observer).
 void setLastPhase(Phase phase)
          Sets the last phase of this game
 void setOptions(java.util.Collection options)
          Sets the options of the game.
 void setParameters(java.util.Map parameters)
          Sets the parameters of the game (keys without a trailing colon, values without a trailing dot, keys and values without leading or trailing whitespace).
 void setPersonInfo(PersonInfo personinfo)
          Adds a person information
 void setTurnDate(int number, java.util.Date turndate)
          Sets the date of the turn.
 void setVictors(java.util.Collection victors, boolean concession)
          Sets the victor resp. the draw participants
 java.lang.String toString()
          Returns the name and judge of the game, e.g.
 boolean wasConceded()
          Was the game conceded to the victor?
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Game

public Game(java.lang.String name,
            java.lang.String judge,
            MapData map)
Creates a new Game

Method Detail

internCreateTurn

protected Turn internCreateTurn(int number,
                                Phase phase)
Creates a Turn object


areMessagesCached

protected boolean areMessagesCached()
Returns whether or not messages are cached


getIdentity

public Person getIdentity()
Returns your role in this game (a country, master, or observer).

Returns:
The role, null if unknown

setIdentity

public void setIdentity(Person identity)
Sets your role in this game (a country, master, or observer).


getDiaryEntryTurn

public int getDiaryEntryTurn(DiaryEntry entry)
Returns the turn for the specified diary entry

Parameters:
entry - The diary entry
Returns:
The turn or -1 if there are no turns

getMessageTurn

public int getMessageTurn(Message msg)
Returns the turn for the specified message

Parameters:
msg - The message
Returns:
The turn or -1 if there are no turns

createDiaryEntry

public DiaryEntry createDiaryEntry(Person from,
                                   int number,
                                   java.lang.String text,
                                   Phase phase)
Creates a new diary entry (if the diary entry doesn't already exist)

Parameters:
from - The person that created the diary entry (can be null if unknown)
number - The number of the diary entry (-1 if unknown)
text - The diary entry text (\n as line separator)
phase - The phase in which the diary entry was created
Returns:
The created diary entry or null if the diary entry already existed

getDiaryEntry

public DiaryEntry getDiaryEntry(Person from,
                                int number)
Returns the specified diary entry.

Parameters:
from - The person who wrote it (can be null for the identity)
number - The number of the diary entry.
Returns:
The diary entry (null if the diary entry doesn't exist)

deleteDiaryEntry

public void deleteDiaryEntry(DiaryEntry entry)
Deletes a diary entry.

Parameters:
entry - The diary entry to delete.

getDiaryEntries

public java.util.List getDiaryEntries(int number)
Returns a (ordered) list with the diary entries for the specified turn.

Parameters:
number - The number of the turn
Returns:
The diary entries

createMessage

public Message createMessage(boolean anonymous,
                             Person from,
                             boolean toallbut,
                             java.util.Collection to,
                             boolean faketoallbut,
                             java.util.Collection faketo,
                             java.lang.String text,
                             java.util.Date date)
Creates a new broadcast/press message (if the message doesn't already exist)

Parameters:
anonymous - Is the message anonymous (grey)?
from - The person that sent the message (can be null if unknown)
toallbut - false → the message was sent to to, true → the message was send to all but to (if to is an empty list it was a broadcast message).
to - The interpretation depends on toallbut (can be null if unknown)
faketoallbut - false → the message was faked to faketo, true → the message was faked to all but faketo (if faketo is an empty list it was a faked broadcast message).
faketo - The interpretation depends on faketoallbut (cannot be null)
text - The message text (\n as line separator)
date - The date of the message (can be null)
Returns:
The created message or null if the message already existed

deleteMessage

public void deleteMessage(Message msg)
Removes the message msg.

Parameters:
msg - The message to delete

getMessages

public java.util.List getMessages(int number)
Returns a (ordered) list with the messages for the specified turn.

Parameters:
number - The number of the turn
Returns:
The messages

setTurnDate

public void setTurnDate(int number,
                        java.util.Date turndate)
Sets the date of the turn. If the date is not between existing dates it is ignored.

Parameters:
number - The number of the turn
turndate - The date of the turn (can be null to clear the date)

getTurnDate

public java.util.Date getTurnDate(int number)
Returns the date of the turn.

Returns:
The date of the turn (can be null)

getName

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


getJudge

public java.lang.String getJudge()
Returns the judge of the game.


getMap

public MapData getMap()
Returns the map of the game.


getOptions

public java.util.SortedSet getOptions()
Returns the options of the game.


setOptions

public void setOptions(java.util.Collection options)
Sets the options of the game.


hasOption

public boolean hasOption(java.lang.String option)
Is the option for the game set?


getTurn

public Turn getTurn(int number)
Returns a turn of the game or null.


getMostRecentTurn

public Turn getMostRecentTurn()
Returns the most recent turn of the game or null if there are no turns


getTurn

public Turn getTurn(Phase phase)
Returns a turn of the game or null.


getTurnIndex

public int getTurnIndex(int number)
Returns a index of the turn .


getTurns

public java.util.Collection getTurns()
Returns all turns of the game


getVictors

public java.util.SortedSet getVictors()
Returns the victor resp. the draw participants, null if unknown


wasConceded

public boolean wasConceded()
Was the game conceded to the victor?


setVictors

public void setVictors(java.util.Collection victors,
                       boolean concession)
Sets the victor resp. the draw participants


getComment

public java.lang.String getComment()
Returns the game comment, null if unknown (Note: \n is used as line separator)


setComment

public void setComment(java.lang.String comment)
Sets the game comment (Note: \n is used as line separator)


getParameters

public java.util.Map getParameters()
Returns the parameters of the game, null if unknown (keys without a trailing colon, values without a trailing dot, keys and values without leading or trailing whitespace).


getParameter

public java.lang.String getParameter(java.lang.String parameter)
Returns the specified parameter

Returns:
null if the the parameters are unknown or the parameter doesn't exist

hasParameterFlag

public boolean hasParameterFlag(java.lang.String parameter,
                                java.lang.String flag)
Tests whether or not the specified flag is set in the specified parameter.

Parameters:
parameter - The name of the parameter
flag - The name of the flag
Returns:
true, if the parameters are known, the parameter exists and the flag is set in the parameter

getParameterValue

public java.lang.String getParameterValue(java.lang.String parameter,
                                          java.lang.String key)
Returns the value of a key of a parameter, e.g. parameter="Access", key="Dedication" returns the dedication needed to sign on to the game.

Parameters:
parameter - The name of the parameter
key - The name of the key
Returns:
the value of the key, null if the key doesn't exist or the key has no value.

setParameters

public void setParameters(java.util.Map parameters)
Sets the parameters of the game (keys without a trailing colon, values without a trailing dot, keys and values without leading or trailing whitespace). Note: If a Variant parameter exists the options are set, too.


setPersonInfo

public void setPersonInfo(PersonInfo personinfo)
Adds a person information


getPersonInfo

public java.util.SortedSet getPersonInfo()
Returns all person informations


setLastPhase

public void setLastPhase(Phase phase)
Sets the last phase of this game


getLastPhase

public Phase getLastPhase()
Returns the last phase of this game, null if unknown


createTurn

public Turn createTurn(int number,
                       Phase phase,
                       java.util.Date turndate)
Retrieves the specified turn. If it does not exist it is created.

Parameters:
number - The number of the phase (>=Turn.NUMBER_FIRST).
phase - The phase (!=null).
turndate - The date of the turn (can be null if unknown)
Returns:
The turn (!=null)

rollback

public void rollback(int number,
                     boolean removeallorders)
Rolls the game back to the turn number.

Parameters:
number - The number of the turn to rollback to
removeallorders - true: all orders of the turn number are removed, false: only the NMR orders are removed and the result flags of the remaining orders are cleared.

getSpecialPhaseCenters

public java.util.Map getSpecialPhaseCenters(Phase phase)
Returns the special phase centers.

Returns:
If the home centers type is HOME_CENTERS_PHASE and the special home centers phase is before the phase of the turn the centers for the special home centers phase, null otherwise. If the information about the center for the special home center phase in unknown, null, too.

getSpecialCenters

public java.util.Map getSpecialCenters(Phase phase)
Returns the special centers for the specified phase.

Parameters:
phase - A phase
Returns:
The centers of the phase (Province → Country). If the home centers type is HOME_CENTERS_PHASE and the special home centers phase is before the phase the centers for the special home centers phase. If the information is not available null.

processTurns

public void processTurns()
Calculates data that can be calculated from the existing data and that the JudgeParser does not set.


getDescription

public java.lang.String getDescription()
Returns a string with the variant, the victor(s), the persons, the parameters, and the comment


equals

public boolean equals(java.lang.Object obj)
Compares two Games by Name and Judge

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object obj)
Compares two Games by Name and Judge

Specified by:
compareTo in interface java.lang.Comparable

hashCode

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

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns the name and judge of the game, e.g. "Shaftsbu (USIN)".

Overrides:
toString in class java.lang.Object