Class RoomImpl

java.lang.Object
com.tenio.core.entity.implement.RoomImpl
All Implemented Interfaces:
Room

public class RoomImpl extends Object implements Room
An implemented class is for a room using in the server.
  • Constructor Details

    • RoomImpl

      public RoomImpl()
      Constructor.
  • Method Details

    • newInstance

      public static Room newInstance()
      Create a new instance.
      Returns:
      a new instance
    • getId

      public long getId()
      Description copied from interface: Room
      Retrieves the room's unique ID in the management list, on the server.
      Specified by:
      getId in interface Room
      Returns:
      the room's unique ID (long value)
    • getName

      public String getName()
      Description copied from interface: Room
      Retrieves the room's name.
      Specified by:
      getName in interface Room
      Returns:
      a String value for room's name
    • setName

      public void setName(String name)
      Description copied from interface: Room
      Sets the room's name.
      Specified by:
      setName in interface Room
      Parameters:
      name - a String value for the room's name
      See Also:
    • getPassword

      public String getPassword()
      Description copied from interface: Room
      Retrieves the room's password.
      Specified by:
      getPassword in interface Room
      Returns:
      a String value for room's password
      See Also:
    • setPassword

      public void setPassword(String password)
      Description copied from interface: Room
      Sets the room's password.
      Specified by:
      setPassword in interface Room
      Parameters:
      password - a String value for the room's password
    • getState

      public RoomState getState()
      Description copied from interface: Room
      Retrieves the current room's state.
      Specified by:
      getState in interface Room
      Returns:
      the current RoomState
    • setState

      public void setState(RoomState state)
      Description copied from interface: Room
      Sets a new state for the room.
      Specified by:
      setState in interface Room
      Parameters:
      state - the new RoomState value
    • isPublic

      public boolean isPublic()
      Description copied from interface: Room
      Determines whether the room is public which means it does not contain any credential and allowed to freely get in.
      Specified by:
      isPublic in interface Room
      Returns:
      true if the room is public, otherwise returns false
    • getMaxParticipants

      public int getMaxParticipants()
      Description copied from interface: Room
      Retrieves the maximum number of participants allowing in the room.
      Specified by:
      getMaxParticipants in interface Room
      Returns:
      the maximum number of participants (integer value)
    • setMaxParticipants

      public void setMaxParticipants(int maxParticipants)
      Description copied from interface: Room
      Sets the maximum number of participants allowing in the room.
      Specified by:
      setMaxParticipants in interface Room
      Parameters:
      maxParticipants - the maximum number of participants (integer value)
    • getMaxSpectators

      public int getMaxSpectators()
      Description copied from interface: Room
      Retrieves the maximum number of spectators allowing in the room.
      Specified by:
      getMaxSpectators in interface Room
      Returns:
      the maximum number of spectators (integer value)
    • setMaxSpectators

      public void setMaxSpectators(int maxSpectators)
      Description copied from interface: Room
      Sets the maximum number of spectators allowing in the room.
      Specified by:
      setMaxSpectators in interface Room
      Parameters:
      maxSpectators - the maximum number of spectators (integer value)
    • getOwner

      public Optional<Player> getOwner()
      Description copied from interface: Room
      Retrieves the room's owner.
      Specified by:
      getOwner in interface Room
      Returns:
      the optional Player as the room's owner
      See Also:
    • setOwner

      public void setOwner(Player owner)
      Description copied from interface: Room
      Updates the room's owner.
      Specified by:
      setOwner in interface Room
      Parameters:
      owner - a Player is set to be the room's owner
    • getPlayerManager

      public PlayerManager getPlayerManager()
      Description copied from interface: Room
      Retrieves a player manager for the room.
      Specified by:
      getPlayerManager in interface Room
      Returns:
      a PlayerManager instance
    • setPlayerManager

      public void setPlayerManager(PlayerManager playerManager)
      Description copied from interface: Room
      Sets a new player manager for the room.
      Specified by:
      setPlayerManager in interface Room
      Parameters:
      playerManager - a PlayerManager instance
    • isActivated

      public boolean isActivated()
      Description copied from interface: Room
      Determines whether the room is activated.
      Specified by:
      isActivated in interface Room
      Returns:
      true when the room is active, otherwise returns false
    • setActivated

      public void setActivated(boolean activated)
      Description copied from interface: Room
      Updates the active state for the room.
      Specified by:
      setActivated in interface Room
      Parameters:
      activated - sets the value to true to activate the room, otherwise false
    • getRoomRemoveMode

      public RoomRemoveMode getRoomRemoveMode()
      Description copied from interface: Room
      Retrieves the rule applied to room to remove it.
      Specified by:
      getRoomRemoveMode in interface Room
      Returns:
      the current RoomRemoveMode of room
    • setRoomRemoveMode

      public void setRoomRemoveMode(RoomRemoveMode roomRemoveMode)
      Description copied from interface: Room
      Sets the rule applied to room to remove it.
      Specified by:
      setRoomRemoveMode in interface Room
      Parameters:
      roomRemoveMode - the new RoomRemoveMode of room
    • getProperty

      public Object getProperty(String key)
      Description copied from interface: Room
      Retrieves a property belongs to the room.
      Specified by:
      getProperty in interface Room
      Parameters:
      key - the String key to fetch data
      Returns:
      an Object value if present, otherwise null
    • setProperty

      public void setProperty(String key, Object value)
      Description copied from interface: Room
      Sets a property belongs to the room.
      Specified by:
      setProperty in interface Room
      Parameters:
      key - the String key
      value - an instance Object of property's value
    • containsProperty

      public boolean containsProperty(String key)
      Description copied from interface: Room
      Determines whether a property is available for the room.
      Specified by:
      containsProperty in interface Room
      Parameters:
      key - a String key used for searching the corresponding property
      Returns:
      true if the property is available, otherwise returns false
    • removeProperty

      public void removeProperty(String key)
      Description copied from interface: Room
      Removes a property which belongs to the room.
      Specified by:
      removeProperty in interface Room
      Parameters:
      key - the String key
    • clearProperties

      public void clearProperties()
      Description copied from interface: Room
      Removes all properties of the room.
      Specified by:
      clearProperties in interface Room
    • getCapacity

      public int getCapacity()
      Description copied from interface: Room
      Retrieves the total number of entities allowed to be in the room (participants and spectators).
      Specified by:
      getCapacity in interface Room
      Returns:
      the total number of entities (integer value)
    • setCapacity

      public void setCapacity(int maxParticipants, int maxSpectators)
      Description copied from interface: Room
      Sets the limitation values for participants and spectators.
      Specified by:
      setCapacity in interface Room
      Parameters:
      maxParticipants - the maximum number of participants (integer value)
      maxSpectators - the maximum number of spectators (integer value)
    • getParticipantCount

      public int getParticipantCount()
      Description copied from interface: Room
      Retrieves the current number of participants in the room.
      Specified by:
      getParticipantCount in interface Room
      Returns:
      the current number of participants (integer value)
    • getSpectatorCount

      public int getSpectatorCount()
      Description copied from interface: Room
      Retrieves the current number of spectators in the room.
      Specified by:
      getSpectatorCount in interface Room
      Returns:
      the current number of spectators (integer value)
    • containsPlayerName

      public boolean containsPlayerName(String playerName)
      Description copied from interface: Room
      Determines whether a player is present in the room.
      Specified by:
      containsPlayerName in interface Room
      Parameters:
      playerName - a unique String player name in the room's player management list
      Returns:
      true when a player can be found, otherwise returns false
    • getPlayerByName

      public Optional<Player> getPlayerByName(String playerName)
      Description copied from interface: Room
      Retrieves a player by using its name.
      Specified by:
      getPlayerByName in interface Room
      Parameters:
      playerName - a unique String name of player on the server
      Returns:
      an instance of optional Player
      See Also:
    • getPlayerIterator

      public Iterator<Player> getPlayerIterator()
      Description copied from interface: Room
      Retrieves an iterator for a player management list. This method should be used to prevent the "escape references" issue.
      Specified by:
      getPlayerIterator in interface Room
      Returns:
      an iterator of Player management list
      See Also:
    • getReadonlyPlayersList

      public List<Player> getReadonlyPlayersList()
      Description copied from interface: Room
      Retrieves a read-only player management list. This method should be used to prevent the "escape references" issue.
      Specified by:
      getReadonlyPlayersList in interface Room
      Returns:
      a list of all Players in the management list
      See Also:
    • getReadonlyParticipantsList

      public List<Player> getReadonlyParticipantsList()
      Description copied from interface: Room
      Retrieves a read-only list of participants in a player management list. This method should be used to prevent the "escape references" issue.
      Specified by:
      getReadonlyParticipantsList in interface Room
      Returns:
      a list of participants in a player management list
      See Also:
    • getReadonlySpectatorsList

      public List<Player> getReadonlySpectatorsList()
      Description copied from interface: Room
      Retrieves a read-only list of spectators in a player management list. This method should be used to prevent the "escape references" issue.
      Specified by:
      getReadonlySpectatorsList in interface Room
      Returns:
      a list of spectators in a player management list
      See Also:
    • addPlayer

      public void addPlayer(Player player, String password, boolean asSpectator, int targetSlot)
      Description copied from interface: Room
      Adds a player to the room.
      Specified by:
      addPlayer in interface Room
      Parameters:
      player - a joining Player
      password - the password value assigned for the room
      asSpectator - sets to true if the player joins room as a "spectator", otherwise returns false
      targetSlot - when the player join the room as role of "participants", then it can occupy a slot position (integer value)
    • removePlayer

      public void removePlayer(Player player)
      Description copied from interface: Room
      Removes a player from its current room.
      Specified by:
      removePlayer in interface Room
      Parameters:
      player - the leaving Player
    • switchParticipantToSpectator

      public void switchParticipantToSpectator(Player player)
      Description copied from interface: Room
      Changes a player's role from "participant" to "spectator" in the room.
      Specified by:
      switchParticipantToSpectator in interface Room
      Parameters:
      player - the changing Player
    • switchSpectatorToParticipant

      public void switchSpectatorToParticipant(Player player, int targetSlot)
      Description copied from interface: Room
      Changes a player's role from "spectator" to "participant" in the room.
      Specified by:
      switchSpectatorToParticipant in interface Room
      Parameters:
      player - the changing Player
      targetSlot - a new slot position (integer value) set to the player in the room
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Room
      Determines whether the room is empty.
      Specified by:
      isEmpty in interface Room
      Returns:
      true if there is no entity in the room, otherwise returns false
    • isFull

      public boolean isFull()
      Description copied from interface: Room
      Determines whether the room is full.
      Specified by:
      isFull in interface Room
      Returns:
      true if the number of entities reached the limitation in the room, otherwise returns false
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getPlayerSlotGeneratedStrategy

      public RoomPlayerSlotGeneratedStrategy getPlayerSlotGeneratedStrategy()
      Description copied from interface: Room
      Retrieves a strategy to generate slot positions in the room.
      Specified by:
      getPlayerSlotGeneratedStrategy in interface Room
      Returns:
      an implementation of RoomPlayerSlotGeneratedStrategy, in case this value is null, then the default implementation will be used
      See Also:
    • setPlayerSlotGeneratedStrategy

      public void setPlayerSlotGeneratedStrategy(RoomPlayerSlotGeneratedStrategy roomPlayerSlotGeneratedStrategy)
      Description copied from interface: Room
      Sets a strategy to generate slot positions in the room.
      Specified by:
      setPlayerSlotGeneratedStrategy in interface Room
      Parameters:
      roomPlayerSlotGeneratedStrategy - an implementation of RoomPlayerSlotGeneratedStrategy
    • getRoomCredentialValidatedStrategy

      public RoomCredentialValidatedStrategy getRoomCredentialValidatedStrategy()
      Description copied from interface: Room
      Retrieves a strategy to validate credentials used to allow players get in the room.
      Specified by:
      getRoomCredentialValidatedStrategy in interface Room
      Returns:
      an implementation of RoomCredentialValidatedStrategy, in case this value is null, then the default implementation will be used
      See Also:
    • setRoomCredentialValidatedStrategy

      public void setRoomCredentialValidatedStrategy(RoomCredentialValidatedStrategy roomCredentialValidatedStrategy)
      Description copied from interface: Room
      Sets a strategy to validate credentials used to allow players get in the room.
      Specified by:
      setRoomCredentialValidatedStrategy in interface Room
      Parameters:
      roomCredentialValidatedStrategy - an implementation of RoomCredentialValidatedStrategy