-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatusList.java
More file actions
81 lines (70 loc) · 2.6 KB
/
Copy pathStatusList.java
File metadata and controls
81 lines (70 loc) · 2.6 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
import java.util.ArrayList;
/**
* StatusList
*/
public class StatusList {
ArrayList<Status> localyKnownStatus;
String standort;
public StatusList() {
this.localyKnownStatus = new ArrayList<Status>();
}
public StatusList(String standort) {
this.standort = standort;
this.localyKnownStatus = new ArrayList<Status>();
localyKnownStatus.add(new Status(standort));
}
public void addStatus(Status newStatus) {
localyKnownStatus.add(newStatus);
}
//updates the calling object with an external list of statuses
public void update(StatusList externalyKnownStatus) {
for (Status extStatus : externalyKnownStatus.getLocalyKnownStatus()) {
Boolean found = false;
for (Status locStatus : localyKnownStatus) {
//more recent status for a known standort overwrites the local record
if (locStatus.getStandort().equals(extStatus.getStandort())) {
found = true;
if (locStatus.getTimestamp().isBefore(extStatus.getTimestamp())) {
locStatus = extStatus;
}
}
}
//unknown status is appended to the local record
if (!found) {
localyKnownStatus.add(extStatus);
}
}
}
public ArrayList<Status> getLocalyKnownStatus() {
return localyKnownStatus;
}
//generates structured representation of the list of Status using the structured representation defined for Status, representations are delimited by |
public String toStructuredString() {
String out = "";
for (Status status : localyKnownStatus) {
out += status.toStructuredString() + "|";
}
return out;
}
//generates readable representation of the list of statuses
public String toString() {
String out = "Bekannte Messwerte bei " + standort +"\n";
for (Status status : localyKnownStatus) {
out += status + "\n\n";
}
return out;
}
//parses structured String representation of list of status to StatusList object
public static StatusList parse(String formattedIn) throws IncorrectStatusStringRepresentation{
String[] formattedStatus = formattedIn.split("\\|");
try {
StatusList out = new StatusList();
for (String status : formattedStatus) {
out.addStatus(Status.parse(status));
}
return out;
} catch (IncorrectStatusStringRepresentation e) {
throw e;
}
}
}