|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectpictionary.message.Message
public final class Message
This class defines the package of data that is sent between the server and
clients.
Messages can contain data or not.
If they do contain data, for example a chat message from a client, it is stored in messageData
.
Nested Class Summary | |
---|---|
static class |
Message.MessageType
Used in Message to determine the type of message. |
Field Summary | |
---|---|
java.lang.String |
client
The client. |
private static java.util.EnumSet<Message.MessageType> |
drawDataMessages
Contains all the message types that can contain draw data message. |
private static java.util.EnumSet<Message.MessageType> |
gameStatusMessages
Contains all the message types that can contain game status data. |
private static java.util.Hashtable<java.lang.Class<?>,java.util.EnumSet<Message.MessageType>> |
legalCombinations
HashTable which is used to check if a combination of data type and message type is legal. |
MessageData<?> |
messageData
The data associated with this message, is null with some message types where data is not needed; for example Message.MessageType.StopGuessing where the message type alone conveys enough information. |
Message.MessageType |
messageType
The type of message. |
private static java.util.EnumSet<Message.MessageType> |
startDrawDataMessages
Contains all the message types that can contain start draw data. |
private static java.util.EnumSet<Message.MessageType> |
statusMessages
Contains all the message types that can contain status message data. |
private static java.util.EnumSet<Message.MessageType> |
stringDataMessages
Contains all the message types that can contain string message data. |
Constructor Summary | |
---|---|
|
Message(Message.MessageType messageType)
Constructor for the simplest message. |
|
Message(Message.MessageType messageType,
java.lang.String client)
Constructor for a basic message without message data. |
private |
Message(Message.MessageType messageType,
java.lang.String client,
MessageData<?> messageData)
Creates a Message with the specified type, client and data. |
Method Summary | ||
---|---|---|
static
|
CreateDataMessage(Message.MessageType messageType,
java.lang.String client,
T data)
Creates and returns a Message object containing data. |
|
static
|
CreateDataMessage(Message.MessageType messageType,
T data)
Convenience method. |
|
private static boolean |
legalCombination(Message.MessageType messageType,
java.lang.Class<?> klass)
Determines whether a combination of message type and data is legal or not. |
|
private static boolean |
shouldContainData(Message.MessageType messageType)
Determines whether a message of the specified messageType should contain data or not. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.util.Hashtable<java.lang.Class<?>,java.util.EnumSet<Message.MessageType>> legalCombinations
legalCombination(MessageType, Class)
.
private static final java.util.EnumSet<Message.MessageType> stringDataMessages
private static final java.util.EnumSet<Message.MessageType> startDrawDataMessages
private static final java.util.EnumSet<Message.MessageType> statusMessages
private static final java.util.EnumSet<Message.MessageType> gameStatusMessages
private static final java.util.EnumSet<Message.MessageType> drawDataMessages
public final Message.MessageType messageType
public final java.lang.String client
public final MessageData<?> messageData
Message.MessageType.StopGuessing
where the message type alone conveys enough information. MessageData
for details.
Constructor Detail |
---|
public Message(Message.MessageType messageType)
messageType
is set, but both client
and messageData
is null.
messageType
- The message's Message.MessageType
.public Message(Message.MessageType messageType, java.lang.String client) throws java.lang.IllegalArgumentException
messageType
and client
is set,
but messageData
is null.
messageType
- The Message.MessageType
.client
- The client
.
java.lang.IllegalArgumentException
- If messages of this message type should contain data,
uses shouldContainData(MessageType)
to perform this check.private Message(Message.MessageType messageType, java.lang.String client, MessageData<?> messageData) throws java.lang.IllegalArgumentException
messageType
- The message type.client
- The client, see client
.messageData
- The data contained in this message, see messageData
java.lang.IllegalArgumentException
- If the combination of message type and message data is illegal,
uses legalCombination(MessageType, Class)
to perform this check.Method Detail |
---|
public static <T> Message CreateDataMessage(Message.MessageType messageType, java.lang.String client, T data)
MessageType#ClientDrawData
and a data object that
is anything else but Point
. Message(MessageType, String, MessageData)
.
T
- The type of data.messageType
- he type of message.client
- The client, see client
.data
- This message's message data, see messageData
.
public static <T> Message CreateDataMessage(Message.MessageType messageType, T data)
CreateDataMessage(MessageType, String, Object)
,
using null for the String object.
messageType
- See CreateDataMessage(MessageType, String, Object)
data
- See CreateDataMessage(MessageType, String, Object)
.CreateDataMessage(MessageType, String, Object)
private static boolean legalCombination(Message.MessageType messageType, java.lang.Class<?> klass)
messageType
- The Message.MessageType
.klass
- The Class
.
legalCombinations
containsan EnumSet
which in turn contains the specified message type, else false.private static boolean shouldContainData(Message.MessageType messageType)
messageType
should contain data or not. EnumSet
s contained in legalCombinations
,
looking for the specified message type.
messageType
- The messageType
.
messageType
was found in any of the EnumSet
s,
else false.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |