Collector.java
1.1 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
package se.lil.jm;
import java.util.ArrayList;
class Collector {
ArrayList<LongDelta> listLong = new ArrayList<LongDelta>();
public void updateValue(Long ts, String name, Long value) {
LongDelta myDelta = null;
for(int x = 0; x<listLong.size() && myDelta == null; x++) {
if(name.equals(listLong.get(x).name)) {
myDelta = listLong.get(x);
}
}
if(myDelta != null) {
myDelta.update(ts, value);
} else {
myDelta = new LongDelta(ts, value);
listLong.add(myDelta);
}
}
public long getCurrentValue(String name) {
LongDelta myDelta = null;
for(int x = 0; x<listLong.size() && myDelta == null; x++) {
if(name.equals(listLong.get(x).name)) {
myDelta = listLong.get(x);
}
}
if(myDelta != null)
return myDelta.getCurrentValue();
else
return 0;
}
public double getPerSecValue(String name) throws Throwable {
LongDelta myDelta = null;
for(int x = 0; x<listLong.size() && myDelta == null; x++) {
if(name.equals(listLong.get(x).name)) {
myDelta = listLong.get(x);
}
}
if(myDelta != null)
return myDelta.getPerSecondValue();
else
return 0;
}
}