-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPeriod.java
More file actions
163 lines (109 loc) · 4.08 KB
/
Copy pathPeriod.java
File metadata and controls
163 lines (109 loc) · 4.08 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//Dylan Barrett
//Description
//10/21/24
public class Period implements Comparable {
public static String LUNCH_STRING = "L";
public static String AFTER_SCHOOL = "9";
public static String P0 = "0";
public static int AFTER_SCHOOL_NUM = 9;
public static int P0_NUM = 0;
public static int LUNCH_NUM = -2;
public static Period LUNCH = new Period("L");
private String period;
public Period(String period) {
this.period = period;
}
public Period(int period) {
this.period = period +"";
}
public Period(Period period) {
this.period = period.getPeriod();
}
/**
* Makes a period based off the Monday schedule and the day the period is on
* @param period the period on a monday schedule
* @param day the day of the week the period is on
*/
public Period(int period, String day) {
if(day.equals("M")) this.period = period + "";
else if(period == -2) this.period = "L";
else if(day.length() > 1) this.period = period + "";
else {
String schedule = BigDuty.schedule.get(day+"_SCHEDULE");
if(schedule.indexOf(period + "") == 8) this.period = AFTER_SCHOOL;
else {
this.period = schedule.indexOf(period + "") + "";
}
}
}
public Period(String period, String day) {
this(period.equals("L") ? -2 : Integer.parseInt(period), day);
}
public String getPeriod() {
return period;
}
public int getValue() {
if(period.equals("L")) return -2;
return Integer.parseInt(period);
}
public boolean isLunch() {
return period.equals("L");
}
/**
* Returns the value of what the increment would be when adding the current period and the specified number, does not modify the period
* @param increment the amount to increment the period by, can be positive or negative
* @return what the value of the period would be
*/
public int increment(int increment, String day) {
if(this.isLunch()) {
if(increment > 0) {
if(4 + increment > Integer.parseInt(Assignment.AFTER_SCHOOL)) return AFTER_SCHOOL_NUM;
return 4 + increment;
}
if(5 + increment < Integer.parseInt(Assignment.P0)) return P0_NUM;
return 5 + increment;
}
if(getValue() + increment > AFTER_SCHOOL_NUM) return AFTER_SCHOOL_NUM;
if(getValue() + increment < P0_NUM) return P0_NUM;
if(getValue() + increment == 4 && !day.equals("M")) return LUNCH_NUM;
if(getValue() + increment == 4 && day.equals("M") && increment < 0) return LUNCH_NUM;
if(getValue() + increment == 5 && day.equals("M") && increment > 0) return LUNCH_NUM;
if(getValue() + increment == 8 && !day.equals("M")) return AFTER_SCHOOL_NUM;
return getValue() + increment;
}
public boolean greaterThan(Period period) {
if(equals(period)) return false;
if(period.isLunch()) return getValue() > 4;
if(isLunch()) return period.getValue() < 5;
return getValue() > period.getValue();
}
public boolean greaterThan(int period) {
return greaterThan(new Period(period));
}
public boolean greaterThan(String period) {
return greaterThan(new Period(period));
}
public boolean equals(Period period) {
return getValue() == period.getValue();
}
public void setPeriod(int period) {
this.period = period + "";
}
public void setPeriod(String period) {
this.period = period;
}
public boolean isLastPeriod(String day) {
return getValue() == 7 && !day.equals("M") || getValue() == 8 && day.equals("M");
}
@Override
public int compareTo(Object o) {
Period p = (Period) o;
if(isLunch() && p.isLunch()) return 0;
if(isLunch()) return (int) (4.5 - p.getValue());
if(p.isLunch()) return (int) (p.getValue() - 4.5);
return getValue() - p.getValue();
}
public String toString() {
return getPeriod();
}
}