Class MicroRooms<Room extends MicroRoom>

java.lang.Object
com.iohao.net.common.kit.micro.room.MicroRooms<Room>

public class MicroRooms<Room extends MicroRoom> extends Object
Thread-safe room registry that manages MicroRoom instances by ID.
Author:
渔民小镇
date:
2023-07-12
  • Constructor Details

    • MicroRooms

      public MicroRooms()
  • Method Details

    • contains

      public boolean contains(long id)
      Check if a room with the given ID exists.
      Parameters:
      id - the room ID
      Returns:
      true if the room exists
    • remove

      public Room remove(long id)
      Remove the room with the given ID.
      Parameters:
      id - the room ID
      Returns:
      the removed room, or null if not found
    • getRoom

      public Room getRoom(long id)
      Get the room with the given ID.
      Parameters:
      id - the room ID
      Returns:
      the room, or null if not found
    • add

      public Room add(Room room)
      Add a room to the registry. If a room with the same ID already exists, the existing room is returned instead.
      Parameters:
      room - the room to add
      Returns:
      the room now associated with the ID
    • optionalRoom

      public Optional<Room> optionalRoom(long id)
      Get the room with the given ID as an Optional.
      Parameters:
      id - the room ID
      Returns:
      an Optional containing the room, or empty if not found
    • ofRoom

      public Room ofRoom(long id)
      Get the room by ID, creating it if absent.
      Parameters:
      id - roomId
      Returns:
      the room instance
    • stream

      public Stream<Room> stream()
      Return a stream of all rooms in the registry.
      Returns:
      a stream of rooms
    • getRoomMap

      public Map<Long,Room> getRoomMap()
    • setRoomSupplier

      public void setRoomSupplier(Supplier<Room> roomSupplier)