Newer
Older
IrisServer / src / main / java / com / ntlab / irisserver / models / RoomManager.java
  1. package com.ntlab.irisserver.models;
  2. import com.ntlab.irisserver.entities.Room;
  3. import org.springframework.stereotype.Component;
  4.  
  5. import javax.ws.rs.*;
  6. import java.util.*;
  7.  
  8. @Component
  9. public class RoomManager {
  10. private static RoomManager theInstance = null;
  11. private Map<String, Room> rooms = new HashMap<String, Room>();
  12.  
  13. public static RoomManager getInstance() {
  14. if(theInstance == null) {
  15. theInstance = new RoomManager();
  16. }
  17. return theInstance;
  18. }
  19.  
  20.  
  21.  
  22. public Room createRoom(String owner) {
  23. UUID uuid = UUID.randomUUID();
  24. String rid = uuid.toString(); //uuid型からstring型に変換
  25. Room r = new Room(rid, owner);
  26. rooms.put(rid, r);
  27. return r;
  28. }
  29.  
  30. public Room getRoom(String rid) {
  31. Room r = rooms.get(rid);
  32. return r;
  33. }
  34.  
  35. public List<Room> getRooms() {
  36. List<Room> roomlist = new ArrayList<>(rooms.values());
  37. return roomlist;
  38. }
  39.  
  40. public void deleteRoom(String rid) {
  41. rooms.remove(rid);
  42. }
  43.  
  44. //--------------------------------テスト用--------------------------------------
  45.  
  46. public void createTestRoom() {
  47. //お絵描きテスト用
  48. Room dr = new Room("drawtest", "draw");
  49. rooms.put("drawtest", dr);
  50. //ゲームテスト用
  51. Room gr = new Room("gametest", "game");
  52. rooms.put("gametest", gr);
  53. }
  54.  
  55.  
  56. }