Class ChatClientsHashMap

java.lang.Object
com.example.server.client.ChatClientsHashMap
All Implemented Interfaces:
ChatInterface

public class ChatClientsHashMap extends Object implements ChatInterface
Class - collection for working with a list of chat users via ConcurrentHashMap.
  • Constructor Details

    • ChatClientsHashMap

      public ChatClientsHashMap()
  • Method Details

    • addUser

      public void addUser(ChatClient client)
      Add new user to the chat
      Specified by:
      addUser in interface ChatInterface
      Parameters:
      client - new client
    • removeUser

      public void removeUser(String nickname)
      Remove user from thw current chat
      Specified by:
      removeUser in interface ChatInterface
      Parameters:
      nickname - of client in chat
    • containsUser

      public boolean containsUser(String nickname)
      Check if there is such client in chat
      Specified by:
      containsUser in interface ChatInterface
      Parameters:
      nickname - of client in chat
      Returns:
      true if needed client is present
    • getUser

      public ChatClient getUser(String nickname)
      Search user by his name
      Specified by:
      getUser in interface ChatInterface
      Parameters:
      nickname - of client
      Returns:
      instance of ChatClient class
    • getAllUsers

      public Collection<ChatClient> getAllUsers()
      Get list of all clients in the chat
      Specified by:
      getAllUsers in interface ChatInterface
      Returns:
      collection of all users
    • countUsers

      public int countUsers()
      Get the number of users in the chat
      Specified by:
      countUsers in interface ChatInterface
      Returns:
      number of users
    • clear

      public void clear()
      Clear all the collection of clients in the chat
      Specified by:
      clear in interface ChatInterface