Methods Summary |
---|
public void | addRoom(Room room)
if (availableRooms.containsKey(room.getName())) {
throw new ChatException("room ["+room.getName()+"] is already available", ChatException.ErrorType.valueOf("ROOM_ALREADY_EXISTS"));
}
availableRooms.put(room.getName(), room);
|
public void | enterRoom(User user, java.lang.String roomName)
assert(roomName != null);
assert(roomName.trim().length() > 0);
if (! availableRooms.containsKey(roomName)) {
throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
}
Room room = availableRooms.get(roomName);
room.memberEnter(user);
|
public void | exitRoom(java.lang.String userName, java.lang.String roomName)
assert(roomName != null);
assert(roomName.trim().length()> 0);
if (availableRooms.containsKey(roomName)) {
Room room = availableRooms.get(roomName);
room.memberExit(userName);
}
|
public java.util.List | getAvailableRooms()
return new ArrayList<Room>(availableRooms.values());
|
public java.util.List | getAvailableUsers()
return new ArrayList<User>(availableUsers.values());
|
public java.util.List | getMessagesInRoom(java.lang.String roomName)
assert(roomName != null);
assert(roomName.trim().length() > 0);
if (! availableRooms.containsKey(roomName)) {
throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
}
Room room = availableRooms.get(roomName);
return room.getChatMessages();
|
public java.util.List | getUsersAvailableInRoom(java.lang.String roomName)
assert(roomName != null);
if (! availableRooms.containsKey(roomName)) {
throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
}
Room room = availableRooms.get(roomName);
return room.getMembers();
|
public void | login(User user)
assert(user != null);
if (availableUsers.containsKey(user.getName())) {
throw new ChatException("User ["+user.getName()+"] already exists", ChatException.ErrorType.valueOf("USER_ALREADY_EXISTS"));
}
availableUsers.put(user.getName(), user);
|
public void | logout(java.lang.String name)
assert(name != null);
assert(name.trim().length() > 0);
availableUsers.remove(name);
for (Room room : availableRooms.values()) {
if (room.hasMember(name)) {
room.memberExit(name);
}
}
|
public void | sendMessageToRoom(java.lang.String roomName, User user, java.lang.String message)
assert(roomName != null);
if (! availableRooms.containsKey(roomName)) {
throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
}
Room room = availableRooms.get(roomName);
room.addMessage(new ChatMessage(message, user));
|