-
Notifications
You must be signed in to change notification settings - Fork 1
/
ClientList.java
72 lines (65 loc) · 1.71 KB
/
ClientList.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
62
63
64
65
66
67
68
69
70
71
72
import java.io.IOException;
import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class ClientList implements Serializable {
private static final long serialVersionUID = 1L;
private List <Client> clients = new LinkedList<Client>();
private static ClientList clientList;
private ClientList() {
}
public Iterator getClients(){
return clients.iterator();
}
public static ClientList instance() {
if (clientList == null) {
return (clientList = new ClientList());
} else {
return clientList;
}
}
public boolean insertClient(Client client) {
clients.add(client);
return true;
}
public String toString() {
return clients.toString();
}
private void writeObject(java.io.ObjectOutputStream output) {
try {
output.defaultWriteObject();
output.writeObject(clientList);
} catch(IOException ioe) {
ioe.printStackTrace();
}
}
private void readObject(java.io.ObjectInputStream input) {
try {
if (clientList != null) {
return;
} else {
input.defaultReadObject();
if (clientList == null) {
clientList = (ClientList) input.readObject();
} else {
input.readObject();
}
}
} catch(IOException ioe) {
ioe.printStackTrace();
} catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
public Client searchClient(String clientID) {
Iterator clients = clientList.getClients();
while (clients.hasNext()){
Client client = (Client)(clients.next());
if (client.getId().equals(clientID)){
return client;
}
}
return null;
}
}