This repository was archived by the owner on Jul 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathVDef.java
More file actions
57 lines (46 loc) · 1.64 KB
/
VDef.java
File metadata and controls
57 lines (46 loc) · 1.64 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
package com.wavefront.labs.convert.converter.rrd.models;
import com.wavefront.labs.convert.converter.rrd.RRDContext;
import com.wavefront.labs.convert.converter.rrd.rpn.NotSupported;
import com.wavefront.labs.convert.converter.rrd.rpn.Variables;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.function.Function;
public class VDef extends Definition {
private static HashMap<String, Function<Deque<String>, String>> functionMap = new HashMap();
static {
functionMap.put("MAXIMUM", NotSupported::warning);
functionMap.put("MINIMUM", NotSupported::warning);
functionMap.put("AVERAGE", NotSupported::warning);
functionMap.put("STDEV", NotSupported::warning);
functionMap.put("LAST", Variables::last);
functionMap.put("FIRST", Variables::first);
functionMap.put("TOTAL", Variables::total);
functionMap.put("PERCENT", NotSupported::warning);
functionMap.put("PERCENTNAN", NotSupported::warning);
functionMap.put("LSLSLOPE", NotSupported::warning);
functionMap.put("LSLINT", NotSupported::warning);
functionMap.put("LSLCORREL", NotSupported::warning);
}
public VDef(String line) {
super(line);
}
@Override
public String calculate(RRDContext context) {
Deque<String> queue = new ArrayDeque();
String[] parts = expression.split(",");
for (String part : parts) {
if (functionMap.containsKey(part)) {
String warning = functionMap.get(part).apply(queue);
if (warning != null) {
warnings.add(part + ": " + warning);
}
} else if (context.hasVariable(part)) {
queue.push(context.getVariable(part));
} else {
queue.push(part);
}
}
return queue.pop();
}
}