-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWaitList.java
More file actions
87 lines (79 loc) · 2.36 KB
/
WaitList.java
File metadata and controls
87 lines (79 loc) · 2.36 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
import java.util.*;
import java.io.*;
import java.lang.*;
public class WaitList implements Serializable {
private LinkedList<Wait> waits = new LinkedList<Wait>();
private static WaitList waitList;
private WaitList() {}
public static WaitList instance() {
if (waitList == null) {
return (waitList = new WaitList());
}
else {
return waitList;
}
}
public boolean insertWait(Wait wait) {
waits.add(wait);
return true;
}
public Iterator<Wait> getWaits() {
return waits.iterator();
}
private void writeObject(java.io.ObjectOutputStream output) {
try {
output.defaultWriteObject();
output.writeObject(waitList);
}
catch(IOException ioe) {
System.out.println(ioe);
}
}
private void readObject(java.io.ObjectInputStream input) {
try {
if (waitList != null) {
return;
}
else {
input.defaultReadObject();
if (waitList == null) {
waitList = (WaitList) input.readObject();
}
else {
input.readObject();
}
}
}
catch(IOException ioe) {
System.out.println("in WaitList readObject \n" + ioe);
}
catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
public String toString() {
return waits.toString();
}
//adding a function for going through the linked list finding a specfic ID
//takes a int, returns a int (both are to be supplier IDs)
public int IDcheck (int ID) {
for (int i=0; i < waits.size(); i++) {
Wait temp = waits.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 Wait get_listed_obj (int position) {
return waits.get(position);
}
public void delete_listed_obj (Wait position) {
waits.remove(position);
}
public void set_listed_obj (int position, Wait update) {
waits.set(position, update);
}
}