package kr.syeyoung.dungeonsguide.dungeon.roomfinder; import kr.syeyoung.dungeonsguide.dungeon.data.DungeonRoomInfo; import java.util.*; public class DungeonRoomInfoRegistry { private static List registered = new ArrayList(); private static Map> shapeMap = new HashMap>(); private static Map uuidMap = new HashMap(); public static void register(DungeonRoomInfo dungeonRoomInfo) { if (dungeonRoomInfo == null) throw new NullPointerException("what the fak parameter is noll?"); dungeonRoomInfo.setRegistered(true); registered.add(dungeonRoomInfo); uuidMap.put(dungeonRoomInfo.getUuid(), dungeonRoomInfo); List roomInfos = shapeMap.get(dungeonRoomInfo.getShape()); if (roomInfos == null) roomInfos = new ArrayList(); roomInfos.add(dungeonRoomInfo); shapeMap.put(dungeonRoomInfo.getShape(), roomInfos); } public static List getByShape(Short shape) { List dungeonRoomInfos = shapeMap.get(shape); return dungeonRoomInfos == null ? Collections.emptyList() : dungeonRoomInfos; } public static DungeonRoomInfo getByUUID(UUID uid) { return uuidMap.get(uid); } public static void unregister(DungeonRoomInfo dungeonRoomInfo) { if (!dungeonRoomInfo.isRegistered()) throw new IllegalStateException("what tha fak? that is not registered one"); if (!uuidMap.containsKey(dungeonRoomInfo.getUuid())) throw new IllegalStateException("what tha fak? that is not registered one, but you desperately wanted to trick this program"); dungeonRoomInfo.setRegistered(false); registered.remove(dungeonRoomInfo); shapeMap.get(dungeonRoomInfo.getShape()).remove(dungeonRoomInfo); uuidMap.remove(dungeonRoomInfo.getUuid()); } }