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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds value to a previously existing attribute or just put it if it doesn't exist.void
applyDifferences(Attributes addedChanges, Attributes deletedChanges)
applies the added and deleted changes from the paramters to the current objectsvoid
clearVisible(boolean sync)
Removes all the visible attributesclone()
boolean
This 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 attributeboolean
This methods return the value of an attributedouble
This methods return the value of an attributeint
This methods return the value of an attributeThis methods return the value of an attributelong
This methods returns the long integer value of an attribute.Returns the RPClass of the attributesboolean
This method returns true if the attribute existsint
hashCode()
boolean
instanceOf(RPClass baseclass)
This method returns true if this attributes is an instance of RPClass or any of its subclassesboolean
isEmpty()
Returns true if the attributes contains nothing.iterator()
returns an iterator over the attribute namesvoid
This method set the value of an attributevoid
This method set the value of an attributevoid
This method set the value of an attributevoid
This method set the value of an attributevoid
This method set the value of an attributevoid
readFromMap(Map<String,Object> in)
Fills this object with the data that has been serialized into a map.void
Fills this object with the data that has been serialized.This methods remove the attribute from the containervoid
Reset the Delta^2 information of the attribute.void
setAddedAttributes(Attributes attr)
Fills this attribute with the added infomation of the Delta^2.void
setDeletedAttributes(Attributes attr)
Fills this attribute with the deleted infomation of the Delta^2.void
setRPClass(String rpclass)
This method sets the RPClass of this attributesvoid
setRPClass(RPClass rpclass)
This method sets the RPClass of this attributesint
size()
Returns the number of attributes contained.This method returns a String that represent the attributestoString()
This method returns a String that represent the objectvoid
writeObject(OutputSerializer out)
This method serialize the object with the default level of detail, that removes private and hidden attributesvoid
writeObject(OutputSerializer out, DetailLevel level)
This method serialize the object with the given level of detail.void
writeToJson(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, wait
Methods 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:
clone
in 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:
writeObject
in 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:
readObject
in 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
-