-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelMain.java
More file actions
89 lines (76 loc) · 2.7 KB
/
ModelMain.java
File metadata and controls
89 lines (76 loc) · 2.7 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
import java.util.Observable;
import java.util.Observer;
import java.time.LocalDate;
import java.util.ArrayList;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/**
* Main model for holding important values such as the start and end date.
*
* @author John Paul San Diego
* @author Jia Cheng Lim
* @author Argya Pramusakti
* @author Ahmed Almuallem
*/
public class ModelMain extends Observable {
// Singleton pattern
private static ModelMain instance;
// Important universally shared variables
private static LocalDate startDate;
private static LocalDate endDate;
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
private int index = 0;
private int statIndex = 0;
CovidDataLoader loader = new CovidDataLoader();
ArrayList<CovidData> records = loader.load();
public ModelMain() {}
public static ModelMain getInstance() {
if (instance == null) {
instance = new ModelMain();
}
return instance;
}
public void setStartDate(LocalDate newDate) {
this.startDate = newDate;
setChanged();
notifyObservers();
}
public void setEndDate(LocalDate newDate) {
this.endDate = newDate;
setChanged();
notifyObservers();
}
public LocalDate getStartDate() {return startDate;}
public LocalDate getEndDate() {return endDate;}
public int getIndex() {return index;}
public void setIndex(int num) {index = num;}
public void resetIndex() {index = 0;}
public void increaseIndex() {index++;}
public void decreaseIndex(){index--;}
public int getStatIndex() {return statIndex;}
public void setStatIndex(int num) {statIndex = num;}
public void resetStatIndex() {statIndex = 0;}
public void increaseStatIndex() {statIndex++;}
public void decreaseStatIndex(){statIndex--;}
// Method to load and display the selected panel
public LocalDate findMinDate() {
LocalDate minDate = null;
for (CovidData record : records) {
LocalDate date = LocalDate.parse(record.getDate(), FORMATTER);
if (minDate == null || date.isBefore(minDate)) {
minDate = date;
}
}
return minDate;
}
public LocalDate findMaxDate() {
LocalDate maxDate = null;
for (CovidData record : records) {
LocalDate date = LocalDate.parse(record.getDate(), FORMATTER);
if (maxDate == null || date.isAfter(maxDate)) {
maxDate = date;
}
}
return maxDate;
}
}