swpchat.server
Class NickNameCollection
java.lang.Object
|
+--swpchat.server.NickNameCollection
- public class NickNameCollection
- extends java.lang.Object
Field Summary |
private static java.lang.String |
CLS
|
private java.util.HashMap |
sessionHash
|
Method Summary |
boolean |
containsNickname(java.lang.String newNickname)
checks if a userinfo with the given nickname already exists |
boolean |
containsSessionKey(java.lang.String sessionKey)
|
java.lang.String |
getIPAddress(java.lang.String sessionKey)
looks up in sessionHash the value that maps to the specific key and returns a part of the value |
java.lang.String |
getNick(java.lang.String sessionKey)
|
java.lang.String |
getSessionKeyByNick(java.lang.String nickname)
returns the sessionKey that (gehört zu) nickname |
UserInfo |
getUserInfo(java.lang.String sessionKey)
|
UserInfo |
getUserInfoByNick(java.lang.String nickname)
returns the userInfo that contains the given nickname |
void |
removeSession(java.lang.String sessionKey)
Remove the session identified by its sessionKey from the
collection. |
void |
setIPAddress(java.lang.String sessionKey,
java.lang.String ipAddress)
looks up in sessionHash the value that maps to the specific key and adds a new info to the value object |
boolean |
tryToAddSession(java.lang.String sessionKey,
java.lang.String nickname)
Method tries to add session to hashtable and is threadsave |
boolean |
tryToChangeSessionNick(java.lang.String sessionKey,
java.lang.String newNickname)
Change the nickname of a session. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
CLS
private static final java.lang.String CLS
sessionHash
private java.util.HashMap sessionHash
NickNameCollection
public NickNameCollection()
tryToAddSession
public boolean tryToAddSession(java.lang.String sessionKey,
java.lang.String nickname)
- Method tries to add session to hashtable and is threadsave
- Parameters:
sessionKey
- nickname
- - Returns:
- true iff nick could be added to collection
tryToChangeSessionNick
public boolean tryToChangeSessionNick(java.lang.String sessionKey,
java.lang.String newNickname)
throws NoSuchMemberException
- Change the nickname of a session.
- Parameters:
sessionKey,
- newNickname- Returns:
- false iff the newNickname was not allowed in the
collection.
- Throws:
NoSuchMemberException
- if there is no session
with the sessionKey in the collection.
containsNickname
public boolean containsNickname(java.lang.String newNickname)
- checks if a userinfo with the given nickname already exists
removeSession
public void removeSession(java.lang.String sessionKey)
throws NoSuchMemberException
- Remove the session identified by its sessionKey from the
collection.
- Parameters:
sessionKey
- - Throws:
NoSuchMemberException
- if there is no session
with the sessionKey in the collection.
containsSessionKey
public boolean containsSessionKey(java.lang.String sessionKey)
getNick
public java.lang.String getNick(java.lang.String sessionKey)
getUserInfo
public UserInfo getUserInfo(java.lang.String sessionKey)
- Parameters:
sessionKey
- the key of the desired userInfo- Returns:
- matching userInfo
getUserInfoByNick
public UserInfo getUserInfoByNick(java.lang.String nickname)
- returns the userInfo that contains the given nickname
- Parameters:
nickname
- the nickname- Returns:
- UserInfo object
getSessionKeyByNick
public java.lang.String getSessionKeyByNick(java.lang.String nickname)
- returns the sessionKey that (gehört zu) nickname
- Parameters:
nickname,
- the nick- Returns:
- sessionKey, the requested sessionKey
getIPAddress
public java.lang.String getIPAddress(java.lang.String sessionKey)
throws NoSuchMemberException
- looks up in sessionHash the value that maps to the specific key and returns a part of the value
- Parameters:
sessionKey,
- the key that identyfies the requested user and its IPAddress- Returns:
- String, the IPAddress of the user with the requested sessionKey
setIPAddress
public void setIPAddress(java.lang.String sessionKey,
java.lang.String ipAddress)
throws NoSuchMemberException
- looks up in sessionHash the value that maps to the specific key and adds a new info to the value object
- Parameters:
sessionKey,
- the key that identyfies the requested user and its IPAddress- Returns:
- ipAddress, the IPAddress of the user with this sessionKey