|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object us.asciiroth.client.Registry
public class Registry
A singleton that ensures our collection of piece instances, which are all immutable,
are cached for reuse. Also manages the serialization and deserialization of pieces,
since the serialized form of a Piece
, also known as its key, is used
to cache the pieces for lookup as well. Finally, the serializers themselves contain
additional information that is used by the Map Editor to represent and manipulate
piece types.
It is essential that pieces are created through the Registry; the game assumes two pieces, of the same type and with the same state, will be the same object instance. It is also required that all piece instances be immutable for this reason. With the exception of the player (who is an agent on the board), and effects (which are not saved and so never serialized), all changes in the game are modeled by swapping piece instances, not by changing piece state.
Field Summary | |
---|---|
static java.lang.String |
FIELD_DELIMITER
The delimiter used to mark fields in serialized keys. |
Method Summary | ||
---|---|---|
|
cache(T piece)
Use the provided piece as an example to retrieve the cached version of this piece instance. |
|
static Registry |
get()
Get the Registry singleton. |
|
java.lang.String |
getEntitySpec()
|
|
Piece |
getExample(java.lang.String type)
Get an example instance for the given type. |
|
java.lang.String |
getKey(Piece piece)
For the supplied piece, get its "key", its representation or serialization in String form. |
|
Piece |
getPiece(java.lang.Class<?> c)
For the supplied class, create a piece instance. |
|
Piece |
getPiece(java.lang.String key)
For the supplied key, create a piece instance. |
|
java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> |
getSerializersByTags()
Get the templates for all available pieces; used by the editor to create a library of types from which individual instances can be created. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String FIELD_DELIMITER
Method Detail |
---|
public <T extends Piece> T cache(T piece)
piece
-
public static Registry get()
Registry
singleton.
Registry
singleton.public java.lang.String getEntitySpec()
public Piece getExample(java.lang.String type)
type
- the type of a piece
public java.lang.String getKey(Piece piece)
Serializer
must be created for the piece type and registered with
the registry.
piece
- the piece to create a key for
public Piece getPiece(java.lang.Class<?> c)
Serializer
must be created for the piece type
and registered with the registry.
c
- the class of the piece to be created (must be a type-only serializable
piece, otherwise use the string key for the piece).
public Piece getPiece(java.lang.String key)
Serializer
must be created for the piece type
and registered with the registry.
key
- a String representation of the piece and its state
public java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> getSerializersByTags()
|
0.7 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
© 2009 Alx Dark