This repository was archived by the owner on Oct 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAverageDelayAccumulator.java
More file actions
62 lines (54 loc) · 1.71 KB
/
AverageDelayAccumulator.java
File metadata and controls
62 lines (54 loc) · 1.71 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
package utility.accumulators;
import java.util.Date;
import java.util.HashMap;
/**
* Scope: Global - Query 1
* Accumulator used on time windows for average delay statistics by neighbourhood evaluation
*/
@SuppressWarnings("unused")
public class AverageDelayAccumulator {
// map of [neighbourhood - statistics] couples
private HashMap<String, AverageDelayStatistics> boroMap;
/**
* Scope: Kafka Streams' serdes - needed due to nested class serialization (AverageDelayStatistics)
* Default constructor
* @param boroMap neighbourhood statistics hash map
*/
public AverageDelayAccumulator(HashMap<String, AverageDelayStatistics> boroMap) {
this.boroMap = boroMap;
}
/**
* No arguments constructor
*/
public AverageDelayAccumulator() {
// create the neighbourhood map
this.boroMap = new HashMap<>();
}
/**
* Adds new info to the current neighbourhood map
* @param boro neighbourhood of the info to add
* @param total total delay
* @param counter delay's occurrences number
*/
public void add(String boro, Double total, Long counter) {
// get current elem
AverageDelayStatistics elem = this.boroMap.get(boro);
// if the element was not in the map add it
if (elem == null) {
this.boroMap.put(boro, new AverageDelayStatistics(total, counter));
} else {
// if the element was in the map replace it with a new element containing merged info
this.boroMap.put(boro, new AverageDelayStatistics(elem.getTotal() + total,
elem.getCounter() + counter));
}
}
public HashMap<String, AverageDelayStatistics> getBoroMap() {
return boroMap;
}
/**
* Scope: Kafka Streams' serdes
*/
public void setBoroMap(HashMap<String, AverageDelayStatistics> boroMap) {
this.boroMap = boroMap;
}
}