Class SFSBuddyManager
- java.lang.Object
-
- sfs2x.client.entities.managers.SFSBuddyManager
-
- All Implemented Interfaces:
IBuddyManager
public class SFSBuddyManager extends java.lang.Object implements IBuddyManager
The SFSBuddyManager class is the entity in charge of managing the current user's Buddy List system. It keeps track of all the user's buddies, their state and their Buddy Variables. It also provides utility methods to set the user's properties when he is part of the buddies list of other users.- See Also:
SmartFox.getBuddyManager()
-
-
Constructor Summary
Constructors Constructor Description SFSBuddyManager(ISmartFox sfs)
Creates a new SFSBuddyManager instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBuddy(Buddy buddy)
* API internal usage only *void
clearAll()
* API internal usage only *boolean
containsBuddy(java.lang.String name)
Indicates whether a buddy exists in user's buddies list or not.Buddy
getBuddyById(int id)
Retrieves a Buddy object from its id property.Buddy
getBuddyByName(java.lang.String name)
Retrieves a Buddy object from its name property.Buddy
getBuddyByNickName(java.lang.String nickName)
Retrieves a Buddy object from its nickName property (if set).java.util.List<Buddy>
getBuddyList()
Returns a list of Buddy objects representing all the buddies in the user's buddies list.java.util.List<java.lang.String>
getBuddyStates()
Returns a list of strings representing the available custom buddy states.java.lang.String
getMyNickName()
Returns the current user's nickname (if set).boolean
getMyOnlineState()
Returns the current user's online/offline state.java.lang.String
getMyState()
Returns the current user's custom state (if set).BuddyVariable
getMyVariable(java.lang.String varName)
Retrieves a Buddy Variable from its name.java.util.List<BuddyVariable>
getMyVariables()
Returns all the Buddy Variables associated with the current user.java.util.List<Buddy>
getOfflineBuddies()
Returns a list of Buddy objects representing all the offline buddies in the user's buddies list.java.util.List<Buddy>
getOnlineBuddies()
Returns a list of Buddy objects representing all the online buddies in the user's buddies list.boolean
isInited()
Indicates whether the client's Buddy List system is initialized or not.Buddy
removeBuddyById(int id)
* API internal usage only *Buddy
removeBuddyByName(java.lang.String name)
* API internal usage only *void
setBuddyStates(java.util.List<java.lang.String> states)
* API internal usage only *void
setInited(boolean inited)
* API internal usage only *void
setMyNickName(java.lang.String nickName)
* API internal usage only *void
setMyOnlineState(boolean isOnline)
* API internal usage only *void
setMyState(java.lang.String state)
* API internal usage only *void
setMyVariable(BuddyVariable bVar)
* API internal usage only *void
setMyVariables(java.util.List<BuddyVariable> variables)
* API internal usage only *
-
-
-
Constructor Detail
-
SFSBuddyManager
public SFSBuddyManager(ISmartFox sfs)
Creates a new SFSBuddyManager instance.NOTE: developers never instantiate a SFSBuddyManager manually: this is done by the SmartFoxServer 2X API internally. A reference to the existing instance can be retrieved using the SmartFox.getBuddyManager() method.
- Parameters:
sfs
- An instance of the SmartFoxServer 2X client API main SmartFox class.- See Also:
SmartFox.getBuddyManager()
-
-
Method Detail
-
isInited
public boolean isInited()
Description copied from interface:IBuddyManager
Indicates whether the client's Buddy List system is initialized or not. If not, an InitBuddyListRequest request should be sent to the server in order to retrieve the persistent Buddy List data.No Buddy List related operations are allowed until the system is initialized.
- Specified by:
isInited
in interfaceIBuddyManager
- See Also:
InitBuddyListRequest
-
setInited
public void setInited(boolean inited)
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
setInited
in interfaceIBuddyManager
-
addBuddy
public void addBuddy(Buddy buddy)
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
addBuddy
in interfaceIBuddyManager
-
removeBuddyById
public Buddy removeBuddyById(int id)
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
removeBuddyById
in interfaceIBuddyManager
-
removeBuddyByName
public Buddy removeBuddyByName(java.lang.String name)
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
removeBuddyByName
in interfaceIBuddyManager
-
containsBuddy
public boolean containsBuddy(java.lang.String name)
Description copied from interface:IBuddyManager
Indicates whether a buddy exists in user's buddies list or not.- Specified by:
containsBuddy
in interfaceIBuddyManager
- Parameters:
name
- The name of the buddy whose presence in the buddies list is to be tested.- Returns:
true
if the specified buddy exists in the buddies list.- See Also:
Buddy.getName()
-
getBuddyById
public Buddy getBuddyById(int id)
Description copied from interface:IBuddyManager
Retrieves a Buddy object from its id property.- Specified by:
getBuddyById
in interfaceIBuddyManager
- Parameters:
id
- The id of the buddy to be found.- Returns:
- The Buddy object representing the buddy, or
null
if no buddy with the passed id exists in the buddies list. - See Also:
Buddy.getId()
,IBuddyManager.getBuddyByName(java.lang.String)
,IBuddyManager.getBuddyByNickName(java.lang.String)
-
getBuddyByName
public Buddy getBuddyByName(java.lang.String name)
Description copied from interface:IBuddyManager
Retrieves a Buddy object from its name property.- Specified by:
getBuddyByName
in interfaceIBuddyManager
- Parameters:
name
- The name of the buddy to be found.- Returns:
- The Buddy object representing the buddy, or
null
if no buddy with the passed name exists in the buddies list. - See Also:
Buddy.getName()
,IBuddyManager.getBuddyById(int)
,IBuddyManager.getBuddyByNickName(java.lang.String)
-
getBuddyByNickName
public Buddy getBuddyByNickName(java.lang.String nickName)
Description copied from interface:IBuddyManager
Retrieves a Buddy object from its nickName property (if set).- Specified by:
getBuddyByNickName
in interfaceIBuddyManager
- Parameters:
nickName
- The nickName of the buddy to be found.- Returns:
- The Buddy object representing the buddy, or
null
if no buddy with the passed nickName exists in the buddies list. - See Also:
Buddy.getNickName()
,IBuddyManager.getBuddyById(int)
,IBuddyManager.getBuddyByName(java.lang.String)
-
getOfflineBuddies
public java.util.List<Buddy> getOfflineBuddies()
Description copied from interface:IBuddyManager
Returns a list of Buddy objects representing all the offline buddies in the user's buddies list.- Specified by:
getOfflineBuddies
in interfaceIBuddyManager
- See Also:
Buddy.isOnline()
-
getOnlineBuddies
public java.util.List<Buddy> getOnlineBuddies()
Description copied from interface:IBuddyManager
Returns a list of Buddy objects representing all the online buddies in the user's buddies list.- Specified by:
getOnlineBuddies
in interfaceIBuddyManager
- See Also:
Buddy.isOnline()
-
getBuddyList
public java.util.List<Buddy> getBuddyList()
Description copied from interface:IBuddyManager
Returns a list of Buddy objects representing all the buddies in the user's buddies list. The list isnull
if the Buddy List system is not initialized.- Specified by:
getBuddyList
in interfaceIBuddyManager
- See Also:
IBuddyManager.isInited()
-
getBuddyStates
public java.util.List<java.lang.String> getBuddyStates()
Description copied from interface:IBuddyManager
Returns a list of strings representing the available custom buddy states. The custom states are received by the client upon initialization of the Buddy List system. They can be configured by means of the SmartFoxServer 2X Administration Tool.- Specified by:
getBuddyStates
in interfaceIBuddyManager
- See Also:
Buddy.getState()
-
getMyVariable
public BuddyVariable getMyVariable(java.lang.String varName)
Description copied from interface:IBuddyManager
Retrieves a Buddy Variable from its name.- Specified by:
getMyVariable
in interfaceIBuddyManager
- Parameters:
varName
- The name of the Buddy Variable to be retrieved.- Returns:
- The BuddyVariable object representing the Buddy Variable, or
null
if no Buddy Variable with the passed name is associated with the current user. - See Also:
IBuddyManager.getMyVariables()
,SetBuddyVariablesRequest
-
getMyVariables
public java.util.List<BuddyVariable> getMyVariables()
Description copied from interface:IBuddyManager
Returns all the Buddy Variables associated with the current user.- Specified by:
getMyVariables
in interfaceIBuddyManager
- See Also:
BuddyVariable
,IBuddyManager.getMyVariable(String)
-
getMyOnlineState
public boolean getMyOnlineState()
Description copied from interface:IBuddyManager
Returns the current user's online/offline state. Iftrue
, the user appears to be online in the buddies list of other users who have him as a buddy.The online state of a user in a buddy list is handled by means of a reserved Buddy Variable (see ReservedBuddyVariables class); it can be changed using the dedicated GoOnlineRequest request.
- Specified by:
getMyOnlineState
in interfaceIBuddyManager
- See Also:
Buddy.isOnline()
,ReservedBuddyVariables
,GoOnlineRequest
-
getMyNickName
public java.lang.String getMyNickName()
Description copied from interface:IBuddyManager
Returns the current user's nickname (if set). If the nickname was never set before,null
is returned.As the nickname of a user in a buddy list is handled by means of a reserved Buddy Variable (see ReservedBuddyVariables class), it can be set using the SetBuddyVariablesRequest request.
- Specified by:
getMyNickName
in interfaceIBuddyManager
- See Also:
Buddy.getNickName()
,ReservedBuddyVariables
,SetBuddyVariablesRequest
-
getMyState
public java.lang.String getMyState()
Description copied from interface:IBuddyManager
Returns the current user's custom state (if set). Examples of custom states are "Available", "Busy", "Be right back", etc. If the custom state was never set before,null
is returned.As the custom state of a user in a buddy list is handled by means of a reserved Buddy Variable (see ReservedBuddyVariables class), it can be set using the SetBuddyVariablesRequest request.
- Specified by:
getMyState
in interfaceIBuddyManager
- See Also:
Buddy.getState()
,ReservedBuddyVariables
,SetBuddyVariablesRequest
-
setMyVariable
public void setMyVariable(BuddyVariable bVar)
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
setMyVariable
in interfaceIBuddyManager
-
setMyVariables
public void setMyVariables(java.util.List<BuddyVariable> variables)
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
setMyVariables
in interfaceIBuddyManager
-
setMyOnlineState
public void setMyOnlineState(boolean isOnline) throws com.smartfoxserver.v2.exceptions.SFSException
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
setMyOnlineState
in interfaceIBuddyManager
- Throws:
com.smartfoxserver.v2.exceptions.SFSException
-
setMyNickName
public void setMyNickName(java.lang.String nickName) throws com.smartfoxserver.v2.exceptions.SFSException
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
setMyNickName
in interfaceIBuddyManager
- Throws:
com.smartfoxserver.v2.exceptions.SFSException
-
setMyState
public void setMyState(java.lang.String state) throws com.smartfoxserver.v2.exceptions.SFSException
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
setMyState
in interfaceIBuddyManager
- Throws:
com.smartfoxserver.v2.exceptions.SFSException
-
setBuddyStates
public void setBuddyStates(java.util.List<java.lang.String> states)
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
setBuddyStates
in interfaceIBuddyManager
-
clearAll
public void clearAll()
Description copied from interface:IBuddyManager
* API internal usage only *- Specified by:
clearAll
in interfaceIBuddyManager
-
-