Package com.example.server.client
Class ChatClientsHashMap
java.lang.Object
com.example.server.client.ChatClientsHashMap
- All Implemented Interfaces:
ChatInterface
Class - collection for working with a list of chat users via ConcurrentHashMap.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addUser
(ChatClient client) Add new user to the chatvoid
clear()
Clear all the collection of clients in the chatboolean
containsUser
(String nickname) Check if there is such client in chatint
Get the number of users in the chatGet list of all clients in the chatSearch user by his namevoid
removeUser
(String nickname) Remove user from thw current chat
-
Constructor Details
-
ChatClientsHashMap
public ChatClientsHashMap()
-
-
Method Details
-
addUser
Add new user to the chat- Specified by:
addUser
in interfaceChatInterface
- Parameters:
client
- new client
-
removeUser
Remove user from thw current chat- Specified by:
removeUser
in interfaceChatInterface
- Parameters:
nickname
- of client in chat
-
containsUser
Check if there is such client in chat- Specified by:
containsUser
in interfaceChatInterface
- Parameters:
nickname
- of client in chat- Returns:
- true if needed client is present
-
getUser
Search user by his name- Specified by:
getUser
in interfaceChatInterface
- Parameters:
nickname
- of client- Returns:
- instance of ChatClient class
-
getAllUsers
Get list of all clients in the chat- Specified by:
getAllUsers
in interfaceChatInterface
- Returns:
- collection of all users
-
countUsers
public int countUsers()Get the number of users in the chat- Specified by:
countUsers
in interfaceChatInterface
- Returns:
- number of users
-
clear
public void clear()Clear all the collection of clients in the chat- Specified by:
clear
in interfaceChatInterface
-