|
@@ -2,27 +2,55 @@ package rocks.zipcode.io.quiz3.collections;
|
2
|
2
|
|
3
|
3
|
import rocks.zipcode.io.quiz3.objectorientation.enums.LabStatus;
|
4
|
4
|
|
|
5
|
+import java.util.HashMap;
|
5
|
6
|
import java.util.Map;
|
|
7
|
+import java.util.TreeMap;
|
6
|
8
|
|
7
|
9
|
/**
|
8
|
10
|
* @author leon on 10/12/2018.
|
9
|
11
|
*/
|
10
|
12
|
public class Student {
|
|
13
|
+
|
|
14
|
+ Map<Lab, LabStatus> map;
|
|
15
|
+
|
11
|
16
|
public Student() {
|
12
|
|
- this(null);
|
|
17
|
+ this(new TreeMap<>());
|
13
|
18
|
}
|
14
|
19
|
|
15
|
20
|
public Student(Map<Lab, LabStatus> map) {
|
|
21
|
+ this.map = map;
|
16
|
22
|
}
|
17
|
23
|
|
18
|
24
|
public void setLabStatus(Lab lab, LabStatus labStatus) {
|
|
25
|
+ if (map.containsKey(lab) && map.get(lab).equals(LabStatus.PENDING)) {
|
|
26
|
+ lab.setLabStatus(labStatus.getLabStatusName());
|
|
27
|
+ map.put(lab, labStatus);
|
|
28
|
+ }
|
|
29
|
+ else throw new UnsupportedOperationException();
|
19
|
30
|
}
|
20
|
31
|
|
21
|
32
|
|
22
|
33
|
public void forkLab(Lab lab) {
|
|
34
|
+ map.put(lab,LabStatus.PENDING);
|
23
|
35
|
}
|
24
|
36
|
|
25
|
37
|
public LabStatus getLabStatus(String labName) {
|
26
|
|
- throw new UnsupportedOperationException("Method not yet implemented");
|
|
38
|
+ try {
|
|
39
|
+ for (Lab l : map.keySet())
|
|
40
|
+ if (l.getName().equals(labName))
|
|
41
|
+ return map.get(l);
|
|
42
|
+ } catch (Exception e) {
|
|
43
|
+ throw new UnsupportedOperationException();
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ return null;
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ @Override
|
|
50
|
+ public String toString() {
|
|
51
|
+ StringBuilder sb = new StringBuilder();
|
|
52
|
+ for (Lab l : map.keySet())
|
|
53
|
+ sb.append(l.getName()).append(" > ").append(l.getLabStatus()).append("\n");
|
|
54
|
+ return sb.toString().trim();
|
27
|
55
|
}
|
28
|
56
|
}
|