de.hagenah.diplomacy.game
Class Message

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

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

A message in a game.

See Also:
Serialized Form

Field Summary
static int TOSTRING_BODY
          Returns the message body
static int TOSTRING_CSS
          The CSS class color-?
static int TOSTRING_DATE
          Returns the message date, e.g.
static int TOSTRING_HTML
          Returns a xhtml text, e.g. → instead of ->
static int TOSTRING_SHORT
          Returns a short text, e.g.
 
Constructor Summary
Message(boolean anonymous, Person from, boolean toallbut, java.util.Collection to, boolean faketoallbut, java.util.Collection faketo, java.lang.String text, java.util.Date messagedate, int lastturnnumber, int messagenumber)
          Creates a new message.
 
Method Summary
 int compareTo(java.lang.Object obj)
          Compares two messages by message number.
 boolean equals(java.lang.Object obj)
          Indicates whether obj is "equal to" this one.
 java.util.SortedSet getFakeTo()
          Return the fake to person set.
 Person getFrom()
          Returns the person that sent the message (can be null if unknown).
 int getLastTurnNumber()
          Return the number of the last turn, when the message was created
 java.util.Date getMessageDate()
          Returns the date of the message (can be null).
 int getMessageNumber()
          Returns the number of the message
 java.lang.String getMessageText()
          Returns the message text (\n as line separator)
 java.util.SortedSet getTo()
          Return the to person set.
 int hashCode()
          Returns a hashcode for this message.
 boolean isAnonymous()
          Is the message anonymous (grey)?
 boolean isBroadcast()
          Is the message a broadcast message?
 boolean isFake()
          Is the message a fake?
 boolean isFakeBroadcast()
          Is the message a fake broadcast message?
 boolean isFakeToAllBut()
          Return whether FakeTo must be interpreted as fake to or as fake to all but.
 boolean isToAllBut()
          Return whether To must be interpreted as to or as to all but.
 boolean isVisible(Person person)
          Is this message visible to the specified person?
 java.lang.String toString()
          Returns a short description for the message
 java.lang.String toString(int flags, java.util.Locale locale)
          Return a text for the message (e.g.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TOSTRING_BODY

public static final int TOSTRING_BODY
Returns the message body

See Also:
Constant Field Values

TOSTRING_SHORT

public static final int TOSTRING_SHORT
Returns a short text, e.g. "From M to A"

See Also:
Constant Field Values

TOSTRING_DATE

public static final int TOSTRING_DATE
Returns the message date, e.g. "From M to A (04/29/2002 3:45pm)"

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

Message

public Message(boolean anonymous,
               Person from,
               boolean toallbut,
               java.util.Collection to,
               boolean faketoallbut,
               java.util.Collection faketo,
               java.lang.String text,
               java.util.Date messagedate,
               int lastturnnumber,
               int messagenumber)
Creates a new message.

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 empty 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 empty it was a faked broadcast message).
faketo - The interpretation depends on faketoallbut (cannot be null)
text - The message text (\n as line separator)
messagedate - The date of the message (can be null)
lastturnnumber - The number of the last turn, when the message was created
messagenumber - The number of the message
Method Detail

isAnonymous

public boolean isAnonymous()
Is the message anonymous (grey)?

Returns:
true if the message is anonymous, false otherwise

getFrom

public Person getFrom()
Returns the person that sent the message (can be null if unknown).

Returns:
The person that sent the message

isToAllBut

public boolean isToAllBut()
Return whether To must be interpreted as to or as to all but.

Returns:
false → the message was sent to To, true → the message was send to all but To (if To is an empty set it was a broadcast message).

isBroadcast

public boolean isBroadcast()
Is the message a broadcast message?

Returns:
true if the message is a broadcast message, false if not or it's unknown

getTo

public java.util.SortedSet getTo()
Return the to person set. The interpretation depends on ToAllBut

Returns:
The persons (null if unknown)

isFakeToAllBut

public boolean isFakeToAllBut()
Return whether FakeTo must be interpreted as fake to or as fake to all but.

Returns:
false → the message was faked to FakeTo, true → the message was faked to all but FakeTo (if FakeTo is an empty set it was a faked broadcast message).

isFakeBroadcast

public boolean isFakeBroadcast()
Is the message a fake broadcast message?

Returns:
true if the message is a fake broadcast message, false if not

isFake

public boolean isFake()
Is the message a fake?

Returns:
true if the message is a fake, false if not or it's unknown whether the message is a fake.

getFakeTo

public java.util.SortedSet getFakeTo()
Return the fake to person set. The interpretation depends on faketoallbut

Returns:
The persons (cannot be null)

getMessageText

public java.lang.String getMessageText()
Returns the message text (\n as line separator)

Returns:
The message text

getMessageDate

public java.util.Date getMessageDate()
Returns the date of the message (can be null).

Returns:
The date of the message

getLastTurnNumber

public int getLastTurnNumber()
Return the number of the last turn, when the message was created

Returns:
The number of the turn

getMessageNumber

public int getMessageNumber()
Returns the number of the message

Returns:
The number of the message

isVisible

public boolean isVisible(Person person)
Is this message visible to the specified person?

Parameters:
person - The person
Returns:
true if the message is visible, false otherwise

equals

public boolean equals(java.lang.Object obj)
Indicates whether obj is "equal to" this one.

Overrides:
equals in class java.lang.Object
Parameters:
obj - The other obj
Returns:
true if obj is a Message object and has the same message number

compareTo

public int compareTo(java.lang.Object obj)
Compares two messages by message number.

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
obj - The other obj
Returns:
A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

hashCode

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

Overrides:
hashCode in class java.lang.Object
Returns:
The hashcode

toString

public java.lang.String toString(int flags,
                                 java.util.Locale locale)
Return a text for the message (e.g. "Message from Master to Austria")

Parameters:
flags - TOSTRING_BODY, TOSTRING_SHORT, TOSTRING_DATE, TOSTRING_HTML, TOSTRING_CSS
locale - The locale for the DateFormat. The default locale is used if null is specified.
Returns:
The text

toString

public java.lang.String toString()
Returns a short description for the message

Overrides:
toString in class java.lang.Object
Returns:
A short description, e.g. [From A] to E fake to all