-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShowList.java
156 lines (136 loc) · 3 KB
/
ShowList.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
* The collection class for Show objects
*
* @author Matt Carlson, Jamison Czech, Slava Makharovich, Prashant Shrestha
*/
public class ShowList implements Serializable {
private static ShowList showList;
private List shows = new LinkedList();
/*
* Private constructor to create singleton
*/
private ShowList() {
}
/**
* ShowList singleton
* @return the ShowList singleton object
*/
public static ShowList instance() {
if (showList == null) {
return (showList = new ShowList());
}
else {
return showList;
}
}
/**
* Adds a Show to the collection
* @param newShow
* @return a boolean indicating successful addition to collection
*/
public boolean insertShow(Show newShow) {
shows.add(newShow);
return true;
}
/**
* searches for a show in the collection
* @param showName
* @return a show if found or null if not found
*/
public Show search(String showName) {
for (Iterator iterator = shows.iterator(); iterator.hasNext(); ) {
Show show = (Show) iterator.next();
if (show.getShowName().equals(showName)) {
return show;
}
}
return null;
}
/**
* removes a show with the given showName from the collection
* @param showName
* @return true if Show exists in the collection, or false otherwise
*/
public boolean removeShow(String showName) {
Show showSearch = search(showName);
if (showSearch == null) {
return false;
}
else {
return shows.remove(showName);
}
}
/**
*
* @param startDate
* @param endDate
* @return
*/
public boolean checkDate(Calendar startDate, Calendar endDate){
return true;
}
/**
* return a list of show
*/
public void getShowList(){
Iterator result = shows.iterator();
System.out.println("The List of show: ");
while(result.hasNext()) {
System.out.println(result.next());
}
}
/**
* write objects for serialization
* @param output stream
*/
private void writeObject(ObjectOutputStream output) {
try {
//output.defaultWriteObject();
output.writeObject(showList);
}
catch(IOException ioe) {
System.out.println(ioe);
}
}
/**
* read serialized object
* @param input stream
*/
private void readObject(ObjectInputStream input) {
try {
if (showList != null) {
return;
}
else {
//input.defaultReadObject();
if (showList == null) {
showList = (ShowList) input.readObject();
}
else {
input.readObject();
}
}
}
catch(IOException ioe) {
System.out.println("in ShowList readObject \n" + ioe);
}
catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
}
/**
* String of the show
*/
@Override
public String toString() {
return shows.toString();
}
}