mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 11:43:53 +00:00
feat(Room): ajout des classes Room et RoomMap
This commit is contained in:
parent
ba6d3afe24
commit
d99405160d
2 changed files with 75 additions and 0 deletions
59
chat/src/main/java/rtgre/modeles/Room.java
Normal file
59
chat/src/main/java/rtgre/modeles/Room.java
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
package rtgre.modeles;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class Room {
|
||||||
|
protected String roomName;
|
||||||
|
protected HashSet<String> loginSet;
|
||||||
|
|
||||||
|
|
||||||
|
public String getRoomName() {
|
||||||
|
return roomName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<String> getLoginSet() {
|
||||||
|
return loginSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Room(String roomName) {
|
||||||
|
this.roomName = roomName;
|
||||||
|
this.loginSet = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String abbreviation() {
|
||||||
|
return this.roomName.split("#")[1].substring(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.roomName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
Room room = (Room) o;
|
||||||
|
return Objects.equals(roomName, room.roomName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(String login) {
|
||||||
|
if (loginSet == null) {
|
||||||
|
loginSet = new HashSet<>();
|
||||||
|
}
|
||||||
|
loginSet.add(login);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject toJsonObject() {
|
||||||
|
return new JSONObject()
|
||||||
|
.put("room", this.roomName)
|
||||||
|
.put("loginSet", this.loginSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toJson() {
|
||||||
|
return this.toJsonObject().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
chat/src/main/java/rtgre/modeles/RoomMap.java
Normal file
16
chat/src/main/java/rtgre/modeles/RoomMap.java
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
package rtgre.modeles;
|
||||||
|
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
public class RoomMap extends TreeMap<String, Room> {
|
||||||
|
public void add(Room room) {
|
||||||
|
this.put(room.roomName, room);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadDefaultRooms() {
|
||||||
|
this.add(new Room("#all"));
|
||||||
|
this.add(new Room("#juniors"));
|
||||||
|
this.add(new Room("#ducks"));
|
||||||
|
this.add(new Room("#mice"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue