Class SFSObject

java.lang.Object
com.smartfoxserver.entities.data.SFSObject
All Implemented Interfaces:
ISFSObject, Serializable
Direct Known Subclasses:
SFSObjectLite

public class SFSObject extends Object implements ISFSObject, Serializable
See Also:
  • Constructor Details

    • SFSObject

      public SFSObject()
  • Method Details

    • newFromBinaryData

      public static SFSObject newFromBinaryData(byte[] bytes)
      Rebuild an SFSObject form its binary form
      Parameters:
      bytes - the binary data
      Returns:
      the original SFSObject
      Throws:
      IllegalStateException - if there's any problem with decoding the binary data
    • newFromBinaryData

      public static SFSObject newFromBinaryData(ByteBuffer buff)
      Internal
    • newFromJsonData

      public static ISFSObject newFromJsonData(String jsonStr)
      Internal
    • newFromResultSet

      public static SFSObject newFromResultSet(ResultSet rset) throws SQLException
      Throws:
      SQLException
      Internal
    • newInstance

      public static SFSObject newInstance()
      Static constructor, similar to new SFSObject();
      Returns:
      a new SFSObject
    • iterator

      public Iterator<Map.Entry<String,SFSDataWrapper>> iterator()
      Description copied from interface: ISFSObject
      Return an Iterator to loop through the collection of values

      NOTE: SFSObject is not thread safe. Use synchronization if you need to iterate and write from different threads

      Specified by:
      iterator in interface ISFSObject
      Returns:
      the SFSObject iterator
    • containsKey

      public boolean containsKey(String key)
      Description copied from interface: ISFSObject
      Looks for a specific key in the object
      Specified by:
      containsKey in interface ISFSObject
      Returns:
      true if the element exists
    • removeElement

      public boolean removeElement(String key)
      Description copied from interface: ISFSObject
      Remove an element in the object
      Specified by:
      removeElement in interface ISFSObject
      Parameters:
      key - the element name
      Returns:
      true if the element was really present in the object
    • size

      public int size()
      Description copied from interface: ISFSObject
      Get the size of the SFSObject
      Specified by:
      size in interface ISFSObject
      Returns:
      the number of elements contained in the SFSObject
    • toBinary

      public byte[] toBinary()
      Description copied from interface: ISFSObject
      Serialize the SFSObject to a byte[]
      Specified by:
      toBinary in interface ISFSObject
      Returns:
      the serialized form of the SFSObject
    • toJson

      public String toJson()
      Specified by:
      toJson in interface ISFSObject
    • getDump

      public String getDump()
      Description copied from interface: ISFSObject
      Get a detailed dump of the SFSObject structure
      Specified by:
      getDump in interface ISFSObject
      Returns:
      a detailed dump of the SFSObject structure
    • getDump

      public String getDump(boolean noFormat)
      Description copied from interface: ISFSObject
      Get a detailed dump of the SFSObject structure
      Specified by:
      getDump in interface ISFSObject
      Parameters:
      noFormat - if true the dump will not be pretty-printed
      Returns:
      a detailed dump of the SFSObject structure
    • getHexDump

      public String getHexDump()
      Description copied from interface: ISFSObject
      Get a pretty-printed hex-dump of the object
      Specified by:
      getHexDump in interface ISFSObject
      Returns:
      a pretty-printed hex-dump of the object
    • isNull

      public boolean isNull(String key)
      Description copied from interface: ISFSObject
      Checks if a specific element is of SFSDataType.NULL.
      Specified by:
      isNull in interface ISFSObject
      Parameters:
      key - the property name
      Returns:
      true if the item is null
    • get

      public SFSDataWrapper get(String key)
      Specified by:
      get in interface ISFSObject
    • getBool

      public Boolean getBool(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as Boolean. It can be null if no element exists for the specified key
      Specified by:
      getBool in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getBoolArray

      public Collection<Boolean> getBoolArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of Booleans. It can be null if no element exists for the specified key
      Specified by:
      getBoolArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getByte

      public Byte getByte(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as Byte (signed 8 bit). It can be null if no element exists for the specified key
      Specified by:
      getByte in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getByteArray

      public byte[] getByteArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of Byte. It can be null if no element exists for the specified key

      NOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.

      Specified by:
      getByteArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getDouble

      public Double getDouble(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as Double (signed decimal 64 bit). It can be null if no element exists for the specified key
      Specified by:
      getDouble in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getDoubleArray

      public Collection<Double> getDoubleArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of Double. It can be null if no element exists for the specified key
      Specified by:
      getDoubleArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getFloat

      public Float getFloat(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as Float (signed decimal 32 bit). It can be null if no element exists for the specified key
      Specified by:
      getFloat in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getFloatArray

      public Collection<Float> getFloatArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of Float. It can be null if no element exists for the specified key
      Specified by:
      getFloatArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getInt

      public Integer getInt(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as Integer (signed 32 bit). It can be null if no element exists for the specified key
      Specified by:
      getInt in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getIntArray

      public Collection<Integer> getIntArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of Integer. It can be null if no element exists for the specified key
      Specified by:
      getIntArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getKeys

      public Set<String> getKeys()
      Description copied from interface: ISFSObject
      Get a set of all keys
      Specified by:
      getKeys in interface ISFSObject
      Returns:
      all the keys
    • getLong

      public Long getLong(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as Long (signed 64 bit). It can be null if no element exists for the specified key
      Specified by:
      getLong in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getLongArray

      public Collection<Long> getLongArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of Long. It can be null if no element exists for the specified key
      Specified by:
      getLongArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getSFSArray

      public ISFSArray getSFSArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as ISFSArray. It can be null if no element exists for the specified key
      Specified by:
      getSFSArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
      See Also:
    • getSFSObject

      public ISFSObject getSFSObject(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as ISFSObject. It can be null if no element exists for the specified key
      Specified by:
      getSFSObject in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getShort

      public Short getShort(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as Short (signed 16 bit). It can be null if no element exists for the specified key
      Specified by:
      getShort in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getShortArray

      public Collection<Short> getShortArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of Short. It can be null if no element exists for the specified key
      Specified by:
      getShortArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getUnsignedByteArray

      public Collection<Integer> getUnsignedByteArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of unsigned Byte. It can be null if no element exists for the specified key
      Specified by:
      getUnsignedByteArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getString

      public String getString(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as String using UTF-8 encoding. It can be null if no element exists for the specified key.

      (The string is limited to 32768 characters)

      Specified by:
      getString in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getShortString

      public String getShortString(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as String using UTF-8 encoding. It can be null if no element exists for the specified key.

      (a ShortString is limited to 255 characters)

      Specified by:
      getShortString in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getText

      public String getText(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as String using UTF-8 encoding. It can be null if no element exists for the specified key.

      The string is limited to 2 GBytes

      Specified by:
      getText in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getVector2

      public SFSVector2 getVector2(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as SFSVector2. It can be null if no element exists for the specified key
      Specified by:
      getVector2 in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getVector3

      public SFSVector3 getVector3(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as SFSVector3. It can be null if no element exists for the specified key
      Specified by:
      getVector3 in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getStringArray

      public Collection<String> getStringArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of Strings. It can be null if no element exists for the specified key Each string is limited to 32768 bytes
      Specified by:
      getStringArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getShortStringArray

      public Collection<String> getShortStringArray(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of Strings. It can be null if no element exists for the specified key Each string is limited to 255 bytes
      Specified by:
      getShortStringArray in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getVector2Array

      public Collection<SFSVector2> getVector2Array(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of SFSVector2. It can be null if no element exists for the specified key
      Specified by:
      getVector2Array in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • getVector3Array

      public Collection<SFSVector3> getVector3Array(String key)
      Description copied from interface: ISFSObject
      Get the element for the specified key as a Collection of SFSVector3. It can be null if no element exists for the specified key
      Specified by:
      getVector3Array in interface ISFSObject
      Parameters:
      key -
      Returns:
      the element, or null
    • putBool

      public void putBool(String key, boolean value)
      Description copied from interface: ISFSObject
      Add a boolean
      Specified by:
      putBool in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putBoolArray

      public void putBoolArray(String key, Collection<Boolean> value)
      Description copied from interface: ISFSObject
      Add a Collection of boolean
      Specified by:
      putBoolArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putByte

      public void putByte(String key, byte value)
      Description copied from interface: ISFSObject
      Add a byte (signed 8-bit)
      Specified by:
      putByte in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putByteArray

      public void putByteArray(String key, byte[] value)
      Description copied from interface: ISFSObject
      Add an array of bytes

      NOTE: This is not supported for HTML5 / Websocket clients, which includes Unity WebGL exports.

      Specified by:
      putByteArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putDouble

      public void putDouble(String key, double value)
      Description copied from interface: ISFSObject
      Add a double value (signed 64-bit)
      Specified by:
      putDouble in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putDoubleArray

      public void putDoubleArray(String key, Collection<Double> value)
      Description copied from interface: ISFSObject
      Add a Collection of double
      Specified by:
      putDoubleArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putFloat

      public void putFloat(String key, float value)
      Description copied from interface: ISFSObject
      Add a float value (signed 32-bit)
      Specified by:
      putFloat in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putFloatArray

      public void putFloatArray(String key, Collection<Float> value)
      Description copied from interface: ISFSObject
      Add a Collection of float
      Specified by:
      putFloatArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putInt

      public void putInt(String key, int value)
      Description copied from interface: ISFSObject
      Add a short value (signed 32-bit)
      Specified by:
      putInt in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putIntArray

      public void putIntArray(String key, Collection<Integer> value)
      Description copied from interface: ISFSObject
      Add a Collection of int
      Specified by:
      putIntArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putLong

      public void putLong(String key, long value)
      Description copied from interface: ISFSObject
      Add a long value (signed 64-bit)
      Specified by:
      putLong in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putLongArray

      public void putLongArray(String key, Collection<Long> value)
      Description copied from interface: ISFSObject
      Add a Collection of long
      Specified by:
      putLongArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putNull

      public void putNull(String key)
      Description copied from interface: ISFSObject
      Add a null field to the Object. Normally we recommend that null values are simply not sent. On the other end of the application you can simply check if a specific key exists or not to detect a null.

      This method will effectively add the key and a byte id to describe the Null value, thus "bloating" the message

      Specified by:
      putNull in interface ISFSObject
      Parameters:
      key - the property name
    • putSFSArray

      public void putSFSArray(String key, ISFSArray value)
      Description copied from interface: ISFSObject
      Add a nested ISFSArray
      Specified by:
      putSFSArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
      See Also:
    • putSFSObject

      public void putSFSObject(String key, ISFSObject value)
      Description copied from interface: ISFSObject
      Add a nested SFSObject
      Specified by:
      putSFSObject in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putShort

      public void putShort(String key, short value)
      Description copied from interface: ISFSObject
      Add a short value (signed 16-bit)
      Specified by:
      putShort in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putShortArray

      public void putShortArray(String key, Collection<Short> value)
      Description copied from interface: ISFSObject
      Add a Collection of short
      Specified by:
      putShortArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putString

      public void putString(String key, String value)
      Description copied from interface: ISFSObject
      Add a string value (encoded in UTF-8), with a limit of 32768 bytes.
      Specified by:
      putString in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
      See Also:
    • putShortString

      public void putShortString(String key, String value)
      Description copied from interface: ISFSObject
      Add a short string value (UTF encoded), with a limit of 255 bytes
      Specified by:
      putShortString in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putText

      public void putText(String key, String value)
      Description copied from interface: ISFSObject
      Add a string value (UTF encoded), with a limit of 2 GBytes
      Specified by:
      putText in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putVector2

      public void putVector2(String key, SFSVector2 value)
      Description copied from interface: ISFSObject
      Add a SFSVector2
      Specified by:
      putVector2 in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putVector3

      public void putVector3(String key, SFSVector3 value)
      Description copied from interface: ISFSObject
      Add a SFSVector3
      Specified by:
      putVector3 in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putStringArray

      public void putStringArray(String key, Collection<String> value)
      Description copied from interface: ISFSObject
      Add a collection of strings (each string limited to 32768 bytes) The collection is also limited to a max of 32768 strings
      Specified by:
      putStringArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putShortStringArray

      public void putShortStringArray(String key, Collection<String> value)
      Description copied from interface: ISFSObject
      Add a collection of short strings (each string limited to 255 bytes) The collection is also limited to a max of 32768 short strings
      Specified by:
      putShortStringArray in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putVector2Array

      public void putVector2Array(String key, Collection<SFSVector2> value)
      Description copied from interface: ISFSObject
      Add a collection of SFSVector2
      Specified by:
      putVector2Array in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • putVector3Array

      public void putVector3Array(String key, Collection<SFSVector3> value)
      Description copied from interface: ISFSObject
      Add a collection of SFSVector3
      Specified by:
      putVector3Array in interface ISFSObject
      Parameters:
      key - the property name
      value - the value
    • put

      public void put(String key, SFSDataWrapper wrappedObject)
      Specified by:
      put in interface ISFSObject
    • toString

      public String toString()
      Overrides:
      toString in class Object