-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent.java
More file actions
133 lines (121 loc) · 2.95 KB
/
Event.java
File metadata and controls
133 lines (121 loc) · 2.95 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
package cs3500.pa05.model;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
/**
* Represents an Event
*/
public class Event {
private String name;
private String description;
private DayType dayOfWeek;
private String startTime;
private String duration;
/**
* Instantiates an Event
*
* @param name name
* @param description description
* @param startTime start time (HH:MM)
* @param duration duration (in hours)
* @param dayOfWeek day of week
*/
public Event(String name, String description, String startTime, String duration,
DayType dayOfWeek) {
this.name = name;
this.description = description;
this.startTime = startTime;
this.duration = duration;
this.dayOfWeek = dayOfWeek;
}
/**
* Gets name.
*
* @return name
*/
public String nameProperty() {
return name;
}
/**
* Gets description.
*
* @return description
*/
public String descriptionProperty() {
return description;
}
/**
* Gets day of week.
*
* @return day
*/
public DayType dayOfWeekProperty() {
return dayOfWeek;
}
/**
* Gets start time.
*
* @return start time
*/
public String startTimeProperty() {
return startTime;
}
/**
* Ensures that the given string is in format HH:MM.
*
* @param startTime string time
* @return formatted string
*/
public String setStartTime(String startTime) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
LocalTime time = LocalTime.parse(startTime, formatter);
return time.toString();
}
/**
* Gets duration.
*
* @return duration
*/
public String durationProperty() {
return duration;
}
/**
* Converts this event to string format.
*
* @return event string
*/
public String eventToString() {
if (description.isEmpty()) {
return "Event: " + name + "\nDay: "
+ dayOfWeek.getDay() + "\nTime: " + setStartTime(startTime)
+ "\nDuration: " + duration;
} else {
if (isUrl(description)) {
return "Event: " + name + "\nDay: " + dayOfWeek.getDay()
+ "\nTime: " + setStartTime(startTime)
+ "\nDuration: " + duration;
} else {
return "Event: " + name + "\nDay: " + dayOfWeek.getDay()
+ "\nDescription: " + description
+ "\nTime: " + setStartTime(startTime)
+ "\nDuration: " + duration;
}
}
}
/**
* Determines if the string is a url.
*
* @param possiblyUrl the url to check
* @return true if it is a url
*/
public boolean isUrl(String possiblyUrl) {
URL url;
try {
url = new URL(possiblyUrl);
return true;
} catch (MalformedURLException e) {
return false;
}
}
}