-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvoiceList.java
More file actions
60 lines (52 loc) · 1.63 KB
/
Copy pathInvoiceList.java
File metadata and controls
60 lines (52 loc) · 1.63 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
import java.util.*;
import java.io.*;
public class InvoiceList implements Serializable {
private static final long serialVersionUID = 1L;
private List<Invoice> invoices = new LinkedList<Invoice>(); // Linked list of invoices
private static InvoiceList InvoiceList;
private InvoiceList() {
}
public static InvoiceList instance() { // check if an instance exists (singleton)
if (InvoiceList == null) {
return (InvoiceList = new InvoiceList());
} else {
return InvoiceList;
}
}
public boolean insertInvoice(Invoice invoice) {
invoices.add(invoice);
return true;
}
public Iterator<Invoice> getInvoices() {
return invoices.iterator();
}
private void writeObject(java.io.ObjectOutputStream output) {
try {
output.defaultWriteObject();
output.writeObject(InvoiceList);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
private void readObject(java.io.ObjectInputStream input) {
try {
if (InvoiceList != null) {
return;
} else {
input.defaultReadObject();
if (InvoiceList == null) {
InvoiceList = (InvoiceList) input.readObject();
} else {
input.readObject();
}
}
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
public String toString() {
return invoices.toString();
}
}