-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevice.java
More file actions
46 lines (40 loc) · 1.11 KB
/
Copy pathDevice.java
File metadata and controls
46 lines (40 loc) · 1.11 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
package com.adrianargint;
import java.util.*;
/**
* Object device which stores data
*/
public class Device{
private String deviceName;
private ArrayList<HourlyInterval> list;
/**
* @param deviceName each device has a name so it is required to pass a name
*/
public Device(String deviceName) {
this.deviceName = deviceName;
this.list = new ArrayList<>();
for (int i = 0; i < 24; i++){
list.add(new HourlyInterval());
}
}
public String getDeviceName() {
return deviceName;
}
public ArrayList<HourlyInterval> getList() {
return list;
}
/**
* add data to device
* @param data object of type Data(timestamp, value)
* @param refferingTime present time
*/
public void add(Data data, int refferingTime){
int interval = (refferingTime - data.getTimeStamp()) / 3600;
ArrayList<Data> list = this.list.get(interval).getList();
for (Data myData : list){
if(myData.getValue() == data.getValue()){
return;
}
}
list.add(data);
}
}