-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathExercise.java
More file actions
273 lines (210 loc) · 6.42 KB
/
Exercise.java
File metadata and controls
273 lines (210 loc) · 6.42 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package fi.helsinki.cs.tmc.data;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.Date;
public class Exercise implements Serializable {
private int id;
private String name;
private String courseName;
/**
* The URL this exercise can be downloaded from.
*/
@SerializedName("zip_url")
private String downloadUrl;
/**
* The URL the solution can be downloaded from (admins only).
*/
@SerializedName("solution_zip_url")
private String solutionDownloadUrl;
/**
* The URL where this exercise should be posted for review.
*/
@SerializedName("return_url")
private String returnUrl;
private boolean locked;
@SerializedName("deadline_description")
private String deadlineDescription;
private Date deadline;
private boolean returnable;
@SerializedName("requires_review")
private boolean requiresReview;
private boolean attempted;
private boolean completed;
private boolean reviewed;
@SerializedName("all_review_points_given")
private boolean allReviewPointsGiven;
private String checksum;
@SerializedName("memory_limit")
private Integer memoryLimit;
@SerializedName("runtime_params")
private String[] runtimeParams;
@SerializedName("valgrind_strategy")
private ValgrindStrategy valgrindStrategy = ValgrindStrategy.FAIL;
public enum ValgrindStrategy {
@SerializedName("")
NONE,
@SerializedName("fail")
FAIL
}
public Exercise() {
}
public Exercise(String name) {
this(name, "unknown-course");
}
public Exercise(String name, String courseName) {
this.name = name;
this.courseName = courseName;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
if (name == null) {
throw new NullPointerException("name was null at Exercise.setName");
}
if (name.isEmpty()) {
throw new IllegalArgumentException("Name cannot be empty at Exercise.setName");
}
this.name = name;
}
public boolean isLocked() {
return locked;
}
public void setLocked(boolean locked) {
this.locked = locked;
}
public String getDeadlineDescription() {
return deadlineDescription;
}
public void setDeadlineDescription(String deadlineDescription) {
this.deadlineDescription = deadlineDescription;
}
public boolean hasDeadlinePassed() {
return hasDeadlinePassedAt(new Date());
}
public boolean hasDeadlinePassedAt(Date time) {
if (time == null) {
throw new NullPointerException("Given time was null at Exercise.isDeadlineEnded");
}
if (deadline != null) {
return deadline.getTime() < time.getTime();
} else {
return false;
}
}
public ExerciseKey getKey() {
return new ExerciseKey(courseName, name);
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String getDownloadUrl() {
return this.downloadUrl;
}
public void setDownloadUrl(String downloadAddress) {
if (downloadAddress == null) {
throw new NullPointerException("downloadAddress was null at Exercise.setDownloadAddress");
}
if (downloadAddress.isEmpty()) {
throw new IllegalArgumentException("downloadAddress cannot be empty at Exercise.setDownloadAddress");
}
this.downloadUrl = downloadAddress;
}
public String getReturnUrl() {
return this.returnUrl;
}
public void setSolutionDownloadUrl(String solutionDownloadUrl) {
this.solutionDownloadUrl = solutionDownloadUrl;
}
public String getSolutionDownloadUrl() {
return solutionDownloadUrl;
}
public void setReturnUrl(String returnAddress) {
if (returnAddress == null) {
throw new NullPointerException("returnAddress was null at Exercise.setReturnAddress");
}
if (returnAddress.isEmpty()) {
throw new IllegalArgumentException("downloadAddress cannot be empty at Exercise.setReturnAddress");
}
this.returnUrl = returnAddress;
}
public Date getDeadline() {
return deadline;
}
public void setDeadline(Date deadline) {
this.deadline = deadline;
}
public boolean isReturnable() {
return returnable && !hasDeadlinePassed();
}
public void setReturnable(boolean returnable) {
this.returnable = returnable;
}
public boolean getReturnable() {
return this.returnable;
}
public boolean requiresReview() {
return requiresReview;
}
public void setRequiresReview(boolean requiresReview) {
this.requiresReview = requiresReview;
}
public boolean isAttempted() {
return attempted;
}
public void setAttempted(boolean attempted) {
this.attempted = attempted;
}
public boolean isCompleted() {
return completed;
}
public void setCompleted(boolean completed) {
this.completed = completed;
}
public boolean isReviewed() {
return reviewed;
}
public void setReviewed(boolean reviewed) {
this.reviewed = reviewed;
}
public boolean isAllReviewPointsGiven() {
return allReviewPointsGiven;
}
public void setAllReviewPointsGiven(boolean allReviewPointsGiven) {
this.allReviewPointsGiven = allReviewPointsGiven;
}
public String getChecksum() {
return checksum;
}
public void setChecksum(String checksum) {
this.checksum = checksum;
}
public Integer getMemoryLimit() {
return memoryLimit;
}
public void setMemoryLimit(Integer memoryLimit) {
this.memoryLimit = memoryLimit;
}
public String[] getRuntimeParams() {
return runtimeParams != null ? runtimeParams : new String[0];
}
public void setRuntimeParams(String[] runtimeParams) {
this.runtimeParams = runtimeParams;
}
public ValgrindStrategy getValgrindStrategy() {
return valgrindStrategy;
}
@Override
public String toString() {
return name;
}
}