Class Attributes

java.lang.Object
marauroa.common.game.Attributes
All Implemented Interfaces:
Cloneable, Iterable<String>, Serializable
Direct Known Subclasses:
RPAction, SlotOwner

public class Attributes extends Object implements Serializable, Iterable<String>, Cloneable
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 Details

    • Attributes

      public Attributes(RPClass rpclass)
      Constructor
      Parameters:
      rpclass - class that this attribute belongs too.
  • Method Details

    • fill

      public Object fill(Attributes attr)
      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

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • setRPClass

      public void setRPClass(RPClass rpclass)
      This method sets the RPClass of this attributes
      Parameters:
      rpclass - the rp class
    • setRPClass

      public void setRPClass(String rpclass)
      This method sets the RPClass of this attributes
      Parameters:
      rpclass - the rp class
    • getRPClass

      public RPClass getRPClass()
      Returns the RPClass of the attributes
      Returns:
      the object RPClass
    • instanceOf

      public boolean instanceOf(RPClass baseclass)
      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

      public boolean has(String attribute)
      This method returns true if the attribute exists
      Parameters:
      attribute - the attribute name to check
      Returns:
      true if it exist or false otherwise
    • put

      public void put(String attribute, String value)
      This method set the value of an attribute
      Parameters:
      attribute - the attribute to be set.
      value - the value we want to set.
    • add

      public void add(String attribute, int value)
      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

      public void put(String attribute, int value)
      This method set the value of an attribute
      Parameters:
      attribute - the attribute to be set.
      value - the value we want to set.
    • put

      public void put(String attribute, long value)
      This method set the value of an attribute
      Parameters:
      attribute - the attribute to be set.
      value - the value we want to set.
    • put

      public void put(String attribute, double value)
      This method set the value of an attribute
      Parameters:
      attribute - the attribute to be set.
      value - the value we want to set.
    • put

      public void put(String attribute, List<String> value)
      This method set the value of an attribute
      Parameters:
      attribute - the attribute to be set.
      value - the value we want to set.
    • get

      public String get(String attribute)
      This methods return the value of an attribute
      Parameters:
      attribute - the attribute we want to get
      Returns:
      the value of the attribute
    • getInt

      public int getInt(String attribute)
      This methods return the value of an attribute
      Parameters:
      attribute - the attribute we want to get
      Returns:
      the value of the attribute
    • getLong

      public long getLong(String attribute)
      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

      public boolean getBool(String attribute)
      This methods return the value of an attribute
      Parameters:
      attribute - the attribute we want to get
      Returns:
      the value of the attribute
    • getDouble

      public double getDouble(String attribute)
      This methods return the value of an attribute
      Parameters:
      attribute - the attribute we want to get
      Returns:
      the value of the attribute
    • getList

      public List<String> getList(String attribute)
      This methods return the value of an attribute
      Parameters:
      attribute - the attribute we want to get
      Returns:
      the value of the attribute
    • remove

      public String remove(String attribute)
      This methods remove the attribute from the container
      Parameters:
      attribute - the attribute we want to remove
      Returns:
      the value of the attribute
    • equals

      public boolean equals(Object attr)
      This method returns true of both object are equal.
      Overrides:
      equals in class Object
      Parameters:
      attr - another Attributes object
      Returns:
      true if they are equal, or false otherwise.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      This method returns a String that represent the object
      Overrides:
      toString in class Object
      Returns:
      a string representing the object.
    • toAttributeString

      public String toAttributeString()
      This method returns a String that represent the attributes
      Returns:
      a string representing the object.
    • iterator

      public Iterator<String> iterator()
      returns an iterator over the attribute names
      Specified by:
      iterator in interface Iterable<String>
      Returns:
      Iterator
    • writeObject

      public void writeObject(OutputSerializer out) throws IOException
      This method serialize the object with the default level of detail, that removes private and hidden attributes
      Specified by:
      writeObject in interface Serializable
      Parameters:
      out - the output serializer
      Throws:
      IOException - in case of an IO-error
    • writeObject

      public void writeObject(OutputSerializer out, DetailLevel level) throws IOException
      This method serialize the object with the given level of detail.
      Parameters:
      out - the output serializer
      level - the level of Detail
      Throws:
      IOException - in case of an IO error
    • writeToJson

      public void writeToJson(StringBuilder out, DetailLevel level)
      This method serialize the object with the given level of detail.
      Parameters:
      out - the output buffer
      level - the level of Detail
    • readObject

      public void readObject(InputSerializer in) throws IOException
      Fills this object with the data that has been serialized.
      Specified by:
      readObject in interface Serializable
      Parameters:
      in - the input serializer
      Throws:
      IOException - in case of unexpected attributes
    • readFromMap

      public void readFromMap(Map<String,​Object> in) throws IOException
      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

      public void setAddedAttributes(Attributes attr)
      Fills this attribute with the added infomation of the Delta^2.
      Parameters:
      attr - the object whose added attributes we are going to copy.
    • setDeletedAttributes

      public void setDeletedAttributes(Attributes attr)
      Fills this attribute with the deleted infomation of the Delta^2.
      Parameters:
      attr - the object whose deleted attributes we are going to copy.
    • applyDifferences

      public void applyDifferences(Attributes addedChanges, Attributes deletedChanges)
      applies the added and deleted changes from the paramters to the current objects
      Parameters:
      addedChanges - attributes added or modified
      deletedChanges - attributes deleted