Class Encoding
- All Implemented Interfaces:
Named
Strings so they can serialized, saved to file, and transmitted between the
server and its agents. Encodings are primarily used to encode the
values of variables in a state
(see Variable.encoding).
An encoded object is one whose value can be encoded.
- Author:
- Stephen G. Ware
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final EncodingAn encoding for Boolean true and false valuesfinal StringThe unique name of this encoding methodstatic final EncodingAnd encoding for sessionRolevaluesstatic final EncodingAnd encoding forTurn.Typevaluesstatic final StringThe prefixed used by allunsigned integer encodings -
Method Summary
Modifier and TypeMethodDescriptionabstract ObjectReturns the object that produced the given encoding, or converts an easily recognizable object into the kind of object this encoding uses.abstract StringReturns a string of1's and0's that uniquely represents this object among other objects of the same type in the same story world.static EncodingReturns the encoding method with a given name.getName()Returns this object's unique name that distinguishes it from other objects of the same type in the same context.toString()
-
Field Details
-
UNSIGNED_INTEGER
The prefixed used by allunsigned integer encodings- See Also:
-
BOOLEAN
An encoding for Boolean true and false values -
ROLE
-
TURN_TYPE
-
name
The unique name of this encoding method
-
-
Method Details
-
get
Returns the encoding method with a given name.- Parameters:
name- the name of the desired encoding- Returns:
- the encoding objects with the given name
- Throws:
IllegalArgumentException- if the given names does not match a known encoding
-
toString
-
getName
-
encode
Returns a string of1's and0's that uniquely represents this object among other objects of the same type in the same story world.Encodings are returned as a string, rather than a number, to make it clear how many bits are required to represent other objects of the same type in the same
story world. For example,Entityis anencodedobject. A story world with 3 entities would require 2 bits to represent an etity (00fornull,01for the first entity,10for the second entity, and11for the third entity). All entities in that story world should return a string of length 2, even if they must be padded with0's, to make it clear how many bits are used in the encoding.- Parameters:
value- the object to be encoded- Returns:
- a string of
1's and0's that uniquely represents this object - Throws:
IllegalArgumentException- if the given object cannot be encoded using this method
-
decode
Returns the object that produced the given encoding, or converts an easily recognizable object into the kind of object this encoding uses. This method can be used as the reverse ofencode(Object), but it allows arbitrary objects as input in case other types of objects are already the right type or can be converted into the right type. This method can be used both as a decoder and also as a means of checking that an already decoded value is correctly formatted.For example, if this encoding represent an unsigned integer with a certain number of bits, this method can be used to decode a string of
1's and0's into the original integer; however, if it is passed a number object, this method can check that the number is of the correct format (i.e. that it is an integer and that it is small enough that it could be encoded using this encoding's number of bits).- Parameters:
value- an encoding string or a decided object which needs to be checked for correctness- Returns:
- the object that produced the encoding, or the original object (or something eqivalent) if this method is being used to check the correctness of a decoded object
- Throws:
IllegalArgumentException- if the given object cannot be decoded or is not properly formatted
-