Class SFSUserVariable
- java.lang.Object
-
- sfs2x.client.entities.variables.BaseVariable
-
- sfs2x.client.entities.variables.SFSUserVariable
-
- All Implemented Interfaces:
UserVariable
,Variable
public class SFSUserVariable extends BaseVariable implements UserVariable
The SFSUserVariable object represents a SmartFoxServer User Variable entity on the client. It is a custom value attached to a User object that gets automatically synchronized between client and server on every change.User Variables are particularly useful to store custom user data that must be "visible" to the other users, such as a profile, a score, a status message, etc. User Variables can be set by means of the SetUserVariablesRequest request; they support the following data types (also nested): Boolean, int, Number, String, SFSObject, SFSArray. A User Variable can also be
null
.User Variables can be 'private' (starting from SFS2X v2.12 with client API v1.7): this flag allows to limit the visibility of variables to their owner only. In other words User Variables marked as private are not sent to other users, even if located in the same Room.
- See Also:
User
,SetUserVariablesRequest
,SFSObject
,SFSArray
-
-
Constructor Summary
Constructors Constructor Description SFSUserVariable(java.lang.String name, java.lang.Object val)
SFSUserVariable(java.lang.String name, java.lang.Object value, int type)
Creates a new SFSUserVariable instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static UserVariable
fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray sfsa)
* API internal usage only *boolean
isPrivate()
Indicates whether this User Variable is private or not.static SFSUserVariable
newPrivateVariable(java.lang.String name, java.lang.Object value)
Creates a new private User Variable.void
setPrivate(boolean value)
* API internal usage only *com.smartfoxserver.v2.entities.data.ISFSArray
toSFSArray()
Privatejava.lang.String
toString()
-
Methods inherited from class sfs2x.client.entities.variables.BaseVariable
getBoolValue, getDoubleValue, getIntValue, getName, getSFSArrayValue, getSFSObjectValue, getStringValue, getType, getValue, isNull
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface sfs2x.client.entities.variables.Variable
getBoolValue, getDoubleValue, getIntValue, getName, getSFSArrayValue, getSFSObjectValue, getStringValue, getType, getValue, isNull
-
-
-
-
Constructor Detail
-
SFSUserVariable
public SFSUserVariable(java.lang.String name, java.lang.Object val)
- See Also:
SFSUserVariable(String, Object, int)
-
SFSUserVariable
public SFSUserVariable(java.lang.String name, java.lang.Object value, int type)
Creates a new SFSUserVariable instance.- Parameters:
name
- The name of the User Variable.value
- The value of the User Variable; valid data types are: Boolean, int, Number, String, SFSObject, SFSArray. The value can also benull
.type
- The type of the User Variable among those available in the VariableType class. Usually it is not necessary to pass this parameter, as the type is auto-detected from the value.- See Also:
VariableType
-
-
Method Detail
-
fromSFSArray
public static UserVariable fromSFSArray(com.smartfoxserver.v2.entities.data.ISFSArray sfsa)
* API internal usage only *
-
newPrivateVariable
public static SFSUserVariable newPrivateVariable(java.lang.String name, java.lang.Object value)
Creates a new private User Variable.Private User Variables are not broadcast to other users: they are only visible on the server side and in the owner's client application.
- Parameters:
name
- The name of the User Variablevalue
- The value of the User Variable; valid data types are: Boolean, int, Number, String, SFSObject, SFSArray. The value can also benull
.
-
isPrivate
public boolean isPrivate()
Description copied from interface:UserVariable
Indicates whether this User Variable is private or not.A private User Variable is visible only to its owner; any changes made to the variable will be transmitted to the owner only.
NOTE: setting the private property manually on an existing User Variable returned by the API has no effect on the server and can disrupt the API functioning. This flag can be set when the User Variable object is created by the developer only (using the new keyword).
- Specified by:
isPrivate
in interfaceUserVariable
- Returns:
- whether or not the variable is private
-
setPrivate
public void setPrivate(boolean value)
Description copied from interface:UserVariable
* API internal usage only *- Specified by:
setPrivate
in interfaceUserVariable
-
toSFSArray
public com.smartfoxserver.v2.entities.data.ISFSArray toSFSArray()
Description copied from interface:Variable
Private- Specified by:
toSFSArray
in interfaceVariable
- Overrides:
toSFSArray
in classBaseVariable
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-