Collector.java
1.47 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
package se.lil.om;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
class Collector {
ArrayList<LongDelta> list = new ArrayList<LongDelta>();
public void update(ResultSet rset) throws Throwable {
while(rset.next()) {
updateValue(rset.getTimestamp(1), rset.getString(2), rset.getLong(3));
}
rset.close();
}
public void updateValue(Timestamp ts, String name, Long value) {
LongDelta myDelta = null;
for(int x = 0; x<list.size() && myDelta == null; x++) {
if(name.equals(list.get(x).name)) {
myDelta = list.get(x);
}
}
if(myDelta != null) {
myDelta.lastFetch = myDelta.curFetch;
myDelta.curFetch = ts;
myDelta.lastValue = myDelta.curValue;
myDelta.curValue = value;
} else {
myDelta = new LongDelta();
myDelta.curFetch = ts;
myDelta.curValue = value;
myDelta.name = name;
list.add(myDelta);
}
}
public long getCurrentValue(String name) throws Throwable {
LongDelta myDelta = null;
for(int x = 0; x<list.size() && myDelta == null; x++) {
if(name.equals(list.get(x).name)) {
myDelta = list.get(x);
}
}
if(myDelta != null)
return myDelta.getCurrentValue();
else
return 0;
}
public long getPerSecValue(String name) throws Throwable {
LongDelta myDelta = null;
for(int x = 0; x<list.size() && myDelta == null; x++) {
if(name.equals(list.get(x).name)) {
myDelta = list.get(x);
}
}
if(myDelta != null)
return myDelta.getPerSecondValue();
else
return 0;
}
}