// 二级lazy的优先顺序保证
Collections.sort(entryKeys);
for (String entryId : entryKeys) {
ReportEntry entry = entryPool
.get(entryId);
if (entry.isLazy())
{
if (result.get(entryId) == null)
result.put(entryId, new HashMap<String, Object>());
SimpleCalculator c = (SimpleCalculator)entry.getCalculator();
if (c.getBindingStack() != null
&& c.getBindingStack().size() > 0) {
List<Object> _bindingStack = c.getBindingStack();
int size = _bindingStack.size();
String leftEntryId = (String) _bindingStack.get(0);
Map<String, Object> leftMap = result.get(leftEntryId);
if (leftMap == null
|| (leftMap != null && leftMap.size() <= 0)) {
continue;
}
Iterator<String> iter = leftMap.keySet().iterator();
java.util.Map<String, Double> cacheMap = new java.util.HashMap<String, Double>();
while (iter.hasNext()) {
try {
String nodekey = iter.next();
Object nodevalue = result.get(leftEntryId).get(
nodekey);
Object rightvalue = null;
for (int i = 0; i < size - 1; i++) {
String rightkey = (String) _bindingStack
.get(i + 1);
if (rightkey.startsWith("sum:")) {
rightkey = rightkey.substring(rightkey
.indexOf("sum:") + "sum:".length());
double sumValue = 0;
if (cacheMap.get(rightkey) != null) {
sumValue = cacheMap.get(rightkey);
} else {
Iterator<Object> rValues = result
.get(rightkey).values()
.iterator();
while (rValues.hasNext()) {
Object rv = rValues.next();
if (rv != null) {
if (rv instanceof String)
sumValue += Double
.valueOf((String) rv);
else {
sumValue += (Double) rv;
}
}
}
cacheMap.put(rightkey, sumValue);
}
rightvalue = sumValue;
} else {
// 简单实现只支持两位计算,同时是+或者-
if (rightkey
.indexOf(AnalysisConstants.OPERATE_PLUS_CHAR) > 0
|| rightkey
.indexOf(AnalysisConstants.OPERATE_MINUS_CHAR) > 0) {
String l;
String r;
if (rightkey
.indexOf(AnalysisConstants.OPERATE_PLUS_CHAR) > 0) {
l = rightkey
.substring(
0,
rightkey.indexOf(AnalysisConstants.OPERATE_PLUS_CHAR))
.trim();
r = rightkey
.substring(
rightkey.indexOf(AnalysisConstants.OPERATE_PLUS_CHAR) + 1)
.trim();
if (result.get(l) == null
|| result.get(r) == null
|| (result.get(l) != null && result
.get(l)
.get(nodekey) == null)
|| (result.get(r) != null && result
.get(r)
.get(nodekey) == null))
continue;
rightvalue = Double.valueOf(result
.get(l).get(nodekey)
.toString())
+ Double.valueOf(result
.get(r)
.get(nodekey)
.toString());
} else {
l = rightkey
.substring(
0,
rightkey.indexOf(AnalysisConstants.OPERATE_MINUS_CHAR))
.trim();
r = rightkey
.substring(
rightkey.indexOf(AnalysisConstants.OPERATE_MINUS_CHAR) + 1)
.trim();
if (result.get(l) == null
|| result.get(r) == null
|| (result.get(l) != null && result
.get(l)
.get(nodekey) == null)
|| (result.get(r) != null && result
.get(r)
.get(nodekey) == null))
continue;
rightvalue = Double.valueOf(result
.get(l).get(nodekey)
.toString())
- Double.valueOf(result
.get(r)
.get(nodekey)
.toString());
}
}
else {
try {
rightvalue = result.get(rightkey).get(nodekey);
}
catch (Throwable e) {
if(!threshold.sholdBlock())
logger.error("resultkey is null" + rightkey, e);
}
}
}
if (rightvalue != null) {
if (nodevalue != null) {
if (c.getOperatorStack().get(i) == AnalysisConstants.OPERATE_PLUS) {
if (nodevalue instanceof Double
|| rightvalue instanceof Double)
nodevalue = Double
.valueOf(nodevalue
.toString())
+ Double.valueOf(rightvalue
.toString());
else
nodevalue = (Long) nodevalue
+ (Long) rightvalue;
continue;
}
if (c.getOperatorStack().get(i) == AnalysisConstants.OPERATE_MINUS) {
if (nodevalue instanceof Double
|| rightvalue instanceof Double)
nodevalue = Double
.valueOf(nodevalue
.toString())
- Double.valueOf(rightvalue
.toString());
else
nodevalue = (Long) nodevalue
- (Long) rightvalue;
continue;
}
if (c.getOperatorStack().get(i) == AnalysisConstants.OPERATE_RIDE) {
if (nodevalue instanceof Double
|| rightvalue instanceof Double)
nodevalue = Double
.valueOf(nodevalue
.toString())
* Double.valueOf(rightvalue
.toString());
else
nodevalue = (Long) nodevalue
* (Long) rightvalue;
continue;
}
if (c.getOperatorStack().get(i) == AnalysisConstants.OPERATE_DIVIDE) {
nodevalue = Double
.valueOf(nodevalue
.toString())
/ Double.valueOf(rightvalue
.toString());
continue;
}
} else {
// nodevalue=rightvalue;
}
}
}
result.get(entryId).put(nodekey, nodevalue);
} catch (Exception ex) {
logger.error(
new StringBuilder("entry : ").append(
entry.getName()).append(
" lazy process error!"), ex);
continue;
}
}
cacheMap.clear();
}
}
else
//处理average的情况
if (entry.getGroupFunction() instanceof AvgFunction)
{
Map<String,Object> av = result.get(entryId);
Map<String,Object> tv = new HashMap<String,Object>();
if (av != null)