-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.java
61 lines (50 loc) · 2.35 KB
/
router.java
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
import java.util.ArrayList;
public class router {
private weatherHub weatherHub;
public router(weatherHub weatherHub) {
this.weatherHub = weatherHub;
}
// create a list of weather stations and add the function to add a weather
// station to the list
private ArrayList<WeatherStation> weatherStations = new ArrayList<WeatherStation>();
private double[][][][] TransmissionHistory = new double[1000][24][6][1]; // this is the history of all the data that
// has been sent to the weather hub
private double[][][][] receiveData = new double[1000][24][6][1]; // this is the data that is being sent to the
// weather hub
public int getDayFromData(double[][][][] data) {
double day = 0;
for (double i = 0; i < data.length; i++) {
if (data[(int) i][0][0][0] != 0) {
day = i;
}
}
return (int) day;
}
public void receiveDataFromStation(double[][][][] data, String name, String location) {
// this function receives data from a weather station and adds it to the history
// of data that has been sent to the weather hub
// it also sends the data to the weather hub
int day = getDayFromData(data);
for (int i = 0; i < 24; i++) {
for (int j = 0; j < 6; j++) {
TransmissionHistory[day][i][j][0] = data[day][i][j][0];
}
}
weatherHub.receiveData(data, name, location);
}
public void sendAllDataToHub(double[][][][] data, String name, String location) {
// send the whole array of data to the weather hub
weatherHub.receiveData(data, name, location);
// set the data in the transmission history to the data that was sent,
// overwriting the old data because all the data has been sent
for (int i = 0; i < 24; i++) {
for (int j = 0; j < 6; j++) {
TransmissionHistory[getDayFromData(data)][i][j][0] = data[getDayFromData(data)][i][j][0];
}
}
}
public void addWeatherStation(WeatherStation weatherStation) {
weatherStations.add(weatherStation);
weatherHub.setupWeatherStation(weatherStation.name, weatherStation.location);
}
}