-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClientList.java
More file actions
96 lines (89 loc) · 2.89 KB
/
ClientList.java
File metadata and controls
96 lines (89 loc) · 2.89 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.company;
import java.util.*;
import java.io.*;
public class ClientList implements Serializable {
private static final long serialVersionUID = 1L;
private List<Client> clients = new LinkedList<Client>();
private static ClientList clientList;
private WaitlistList waitlists = new WaitlistList();
ProductList productList = ProductList.instance();
private ClientList() { }
public static ClientList instance() {
if (clientList == null) {
return (clientList = new ClientList());
} else {
return clientList;
}
}
public boolean insertMember(Client client) {
clients.add(client);
return true;
}
public Iterator<Client> getClients(){
return clients.iterator();
}
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 String toString() {
return clients.toString();
}
public void GenerateOrder(Client client)
{
for (int i = 0; i < client.userCart.shoppingCart.size(); i++)
{
Product cartP = client.userCart.shoppingCart.get(i);
int pos = productList.IDcheck(cartP.getId());
Product baseP = productList.get_listed_obj(pos) ;
if(baseP.getQuantity() < cartP.getQuantity())
{
waitlists.AddWaitList(client,cartP,cartP.getQuantity());
}
}
client.newInvoice();
}
public void PrintWaitList(Client client)
{
waitlists.PrintWaitList(client);
}
public int IDcheck (int ID) {
for (int i=0; i < clients.size(); i++) {
Client temp = clients.get(i);
if (ID == temp.getId()) {
System.out.println("ID found");
return i;
}
}
System.out.println("ERROR: ID is not in database");
return -1;
}
public Client get_listed_obj (int position) {
return clients.get(position);
}
public void set_listed_obj (int position, Client update) {
clients.set(position, update);
}
}