Package marauroa.common.game
Class Attributes
java.lang.Object
marauroa.common.game.Attributes
- All Implemented Interfaces:
Cloneable,Iterable<String>,Serializable
This class hosts a list of Attributes stored as pairs String=String. There
are some important things to remark on Attributes.
1) This class is more than a Map, as it stores information like its class.
2) It has several special attributes that should be handle with care like:
- id It contains the unique per zone @Link {marauroa.common.game.IRPZone} identification of the object.
- zoneid It contains the zone identification. Both id and zoneid uniquely identify an object on server runtime.
- type It contains the name of the RPClass (@Link {marauroa.common.game.RPClass} that defines this attributes object.
Attributes also features a part of the implementation of Delta^2 that try to
reduce data send to clients by just sending differences on the objects from a
previous state. This mainly consists on sending which attributes has been
added or modified and what attributes has been deleted.
- Author:
- miguel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds value to a previously existing attribute or just put it if it doesn't exist.voidapplyDifferences(Attributes addedChanges, Attributes deletedChanges)applies the added and deleted changes from the paramters to the current objectsvoidclearVisible(boolean sync)Removes all the visible attributesclone()booleanThis method returns true of both object are equal.fill(Attributes attr)This method fills this object with data from the attributes object passed as paramThis methods return the value of an attributebooleanThis methods return the value of an attributedoubleThis methods return the value of an attributeintThis methods return the value of an attributeThis methods return the value of an attributelongThis methods returns the long integer value of an attribute.Returns the RPClass of the attributesbooleanThis method returns true if the attribute existsinthashCode()booleaninstanceOf(RPClass baseclass)This method returns true if this attributes is an instance of RPClass or any of its subclassesbooleanisEmpty()Returns true if the attributes contains nothing.iterator()returns an iterator over the attribute namesvoidThis method set the value of an attributevoidThis method set the value of an attributevoidThis method set the value of an attributevoidThis method set the value of an attributevoidThis method set the value of an attributevoidreadFromMap(Map<String,Object> in)Fills this object with the data that has been serialized into a map.voidFills this object with the data that has been serialized.This methods remove the attribute from the containervoidReset the Delta^2 information of the attribute.voidsetAddedAttributes(Attributes attr)Fills this attribute with the added infomation of the Delta^2.voidsetDeletedAttributes(Attributes attr)Fills this attribute with the deleted infomation of the Delta^2.voidsetRPClass(String rpclass)This method sets the RPClass of this attributesvoidsetRPClass(RPClass rpclass)This method sets the RPClass of this attributesintsize()Returns the number of attributes contained.This method returns a String that represent the attributestoString()This method returns a String that represent the objectvoidwriteObject(OutputSerializer out)This method serialize the object with the default level of detail, that removes private and hidden attributesvoidwriteObject(OutputSerializer out, DetailLevel level)This method serialize the object with the given level of detail.voidwriteToJson(StringBuilder out, DetailLevel level)This method serialize the object with the given level of detail.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Attributes
Constructor- Parameters:
rpclass- class that this attribute belongs too.
-
-
Method Details
-
fill
This method fills this object with data from the attributes object passed as param- Parameters:
attr- the attribute object to use to fill this one.- Returns:
- the object itself.
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
setRPClass
This method sets the RPClass of this attributes- Parameters:
rpclass- the rp class
-
setRPClass
This method sets the RPClass of this attributes- Parameters:
rpclass- the rp class
-
getRPClass
Returns the RPClass of the attributes- Returns:
- the object RPClass
-
instanceOf
This method returns true if this attributes is an instance of RPClass or any of its subclasses- Parameters:
baseclass- the class we want to know if we are instance of.- Returns:
- true if it is an instance of class
-
isEmpty
public boolean isEmpty()Returns true if the attributes contains nothing.- Returns:
- true if is empty
-
size
public int size()Returns the number of attributes contained.- Returns:
- amount of attributes
-
has
This method returns true if the attribute exists- Parameters:
attribute- the attribute name to check- Returns:
- true if it exist or false otherwise
-
put
This method set the value of an attribute- Parameters:
attribute- the attribute to be set.value- the value we want to set.
-
add
Adds value to a previously existing attribute or just put it if it doesn't exist.- Parameters:
attribute- the attribute to be set.value- the value we want to set.
-
put
This method set the value of an attribute- Parameters:
attribute- the attribute to be set.value- the value we want to set.
-
put
This method set the value of an attribute- Parameters:
attribute- the attribute to be set.value- the value we want to set.
-
put
This method set the value of an attribute- Parameters:
attribute- the attribute to be set.value- the value we want to set.
-
put
This method set the value of an attribute- Parameters:
attribute- the attribute to be set.value- the value we want to set.
-
get
This methods return the value of an attribute- Parameters:
attribute- the attribute we want to get- Returns:
- the value of the attribute
-
getInt
This methods return the value of an attribute- Parameters:
attribute- the attribute we want to get- Returns:
- the value of the attribute
-
getLong
This methods returns the long integer value of an attribute.- Parameters:
attribute- The attribute we want to get- Returns:
- The value of the attribute
-
getBool
This methods return the value of an attribute- Parameters:
attribute- the attribute we want to get- Returns:
- the value of the attribute
-
getDouble
This methods return the value of an attribute- Parameters:
attribute- the attribute we want to get- Returns:
- the value of the attribute
-
getList
This methods return the value of an attribute- Parameters:
attribute- the attribute we want to get- Returns:
- the value of the attribute
-
remove
This methods remove the attribute from the container- Parameters:
attribute- the attribute we want to remove- Returns:
- the value of the attribute
-
equals
This method returns true of both object are equal. -
hashCode
public int hashCode() -
toString
This method returns a String that represent the object -
toAttributeString
This method returns a String that represent the attributes- Returns:
- a string representing the object.
-
iterator
returns an iterator over the attribute names -
writeObject
This method serialize the object with the default level of detail, that removes private and hidden attributes- Specified by:
writeObjectin interfaceSerializable- Parameters:
out- the output serializer- Throws:
IOException- in case of an IO-error
-
writeObject
This method serialize the object with the given level of detail.- Parameters:
out- the output serializerlevel- the level of Detail- Throws:
IOException- in case of an IO error
-
writeToJson
This method serialize the object with the given level of detail.- Parameters:
out- the output bufferlevel- the level of Detail
-
readObject
Fills this object with the data that has been serialized.- Specified by:
readObjectin interfaceSerializable- Parameters:
in- the input serializer- Throws:
IOException- in case of unexpected attributes
-
readFromMap
Fills this object with the data that has been serialized into a map.- Parameters:
in- the input map- Throws:
IOException- in case of unexpected attributes
-
clearVisible
public void clearVisible(boolean sync)Removes all the visible attributes- Parameters:
sync- ignored
-
resetAddedAndDeletedAttributes
public void resetAddedAndDeletedAttributes()Reset the Delta^2 information of the attribute. -
setAddedAttributes
Fills this attribute with the added infomation of the Delta^2.- Parameters:
attr- the object whose added attributes we are going to copy.
-
setDeletedAttributes
Fills this attribute with the deleted infomation of the Delta^2.- Parameters:
attr- the object whose deleted attributes we are going to copy.
-
applyDifferences
applies the added and deleted changes from the paramters to the current objects- Parameters:
addedChanges- attributes added or modifieddeletedChanges- attributes deleted
-