forked from serenapascual/cs151-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
139 lines (126 loc) · 2.96 KB
/
Event.java
File metadata and controls
139 lines (126 loc) · 2.96 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
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
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
*
* @author Himanshu Mehta, Serena Pascual and Cherie Sew
*
*/
public class Event implements Comparable<Event>{
private String title;
private int year;
private int month;
private int day;
private String startTime;
private String endTime;
private Calendar start = new GregorianCalendar();
private Calendar end = new GregorianCalendar();
private String dayOfWeek;
/**
* Creates an event in calendar
* @param title - title of event
* @param year - year of event
* @param month - month of event
* @param day - day of event
* @param startTime - start time of event
* @param endTime - end time of event
*/
public Event(String title, int year, int month, int day, String startTime, String endTime) {
this.title = title;
this.year = year;
this.month = month;
this.day = day;
this.startTime = startTime;
this.endTime = endTime;
setTime();
EventModel model = new EventModel();
dayOfWeek = model.getWeekDay(year, month, day);
}
/**
* Set the time of an event
*/
public void setTime() {
Calendar temp = new GregorianCalendar(year, month - 1, day, Integer.parseInt(startTime),00);
@SuppressWarnings("deprecation")
Date startDate= temp.getTime();
temp.set(year, month - 1, day, Integer.parseInt(endTime),00);
@SuppressWarnings("deprecation")
Date endDate = temp.getTime();
start.setTime(startDate);
end.setTime(endDate);
}
/**
* Get name of the event
* @return title of event
*/
public String getTitle() {
return title;
}
/**
* Get year of the event
* @return year of event
*/
public int getYear() {
return year;
}
/**
* Get month of the event
* @return month of event
*/
public int getMonth() {
return month;
}
/**
* Get week of the event
* @return week of event
*/
public int getWeek() {
return this.start.get(Calendar.WEEK_OF_MONTH);
}
/**
* Get day of event
* @return day of event
*/
public int getDay() {
return day;
}
/**
* Get start time of event
* @return start time of event
*/
public Calendar getStart() {
return start;
}
/**
* Get end time of event
* @return end time of event
*/
public Calendar getEnd() {
return end;
}
/**
* Compares event times
* @param e - events to compare to
* @return -1 Event e is scheduled later
* @return 1 Event e is scheduler before
* @return 0 Scheduled at the same time
*/
public int compareTo(Event e) {
if(e.start.before(this.start) && e.end.before(this.start)) {
return 1;
}else if(e.start.after(this.end) && e.end.after(this.end)) {
return -1;
}else {
return 0;
}
}
/**
* Creates String with all event information
* @return event in the format of title; year; month; dayOfWeek; startTime; endTime
*/
public String toString() {
return title +";"+ year +";"+ month +";"+ dayOfWeek +";"+ startTime +";"+ endTime;
}
}