-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProductList.java
More file actions
58 lines (53 loc) · 1.56 KB
/
Copy pathProductList.java
File metadata and controls
58 lines (53 loc) · 1.56 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
import java.util.*;
// import java.lang.*;
import java.io.*;
public class ProductList implements Serializable {
private static final long serialVersionUID = 1L;
private List<Product> products = new LinkedList<Product>();
private static ProductList productlist;
private ProductList() {
}
public static ProductList instance() {
if (productlist == null) {
return (productlist = new ProductList());
} else {
return productlist;
}
}
public boolean insertProduct(Product product) {
products.add(product);
return true;
}
public Iterator<Product> getProducts() {
return products.iterator();
}
private void writeObject(java.io.ObjectOutputStream output) {
try {
output.defaultWriteObject();
output.writeObject(productlist);
} catch(IOException ioe) {
System.out.println(ioe);
}
}
private void readObject(java.io.ObjectInputStream input) {
try {
if (productlist != null) {
return;
} else {
input.defaultReadObject();
if (productlist == null) {
productlist = (ProductList) input.readObject();
} else {
input.readObject();
}
}
} catch(IOException ioe) {
System.out.println("in Catalog readObject \n" + ioe);
} catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
public String toString() {
return products.toString();
}
}