-
Notifications
You must be signed in to change notification settings - Fork 0
/
MudPerson.java
61 lines (60 loc) · 1.66 KB
/
MudPerson.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package UP12;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Objects;
public class MudPerson extends UnicastRemoteObject implements Mud.MailClientInterface{
private String name;
private PrintWriter out;
private final BufferedReader in;
private ArrayList<String> letters;
MudPerson(String name, PrintWriter out, BufferedReader in) throws RemoteException {
this.name = name;
this.out = out;
this.in = in;
letters = new ArrayList<>();
}
@Override
public ArrayList<String> getLetters() throws RemoteException {
return letters;
}
@Override
public String getName() throws RemoteException {
return name;
}
@Override
public String showMessage() throws RemoteException{
String res=(name+"'s messages:\n");
for(String i:letters){
res+=i+"\n";
}
cleanLetters();
return res;
}
@Override
public void talk(String text)throws RemoteException {
out.print(text);
out.flush();
}
@Override
public void addLetter(String letter) throws RemoteException {
letters.add(letter);
}
@Override
public void cleanLetters() throws RemoteException {
letters.clear();
}
@Override
public String print() throws RemoteException {
return toString();
}
@Override
public String toString() {
return "{" + name + "}";
}
@Override
public void sendMessage(Mud.MailClientInterface name, String message) throws RemoteException{
}
}