/*
***************************************************************************************
* Copyright (C) 2006 EsperTech, Inc. All rights reserved. *
* http://www.espertech.com/esper *
* http://www.espertech.com *
* ---------------------------------------------------------------------------------- *
* The software in this package is published under the terms of the GPL license *
* a copy of which has been included with this distribution in the license.txt file. *
***************************************************************************************
*/
package com.espertech.esper.supportunit.epl;
import com.espertech.esper.client.EventBean;
import com.espertech.esper.epl.expression.core.*;
import java.io.StringWriter;
public class SupportExprNode extends ExprNodeBase implements ExprEvaluator {
private static int validateCount;
private Class type;
private Object value;
private int validateCountSnapshot;
public static void setValidateCount(int validateCount) {
SupportExprNode.validateCount = validateCount;
}
public SupportExprNode(Class type) {
this.type = type;
this.value = null;
}
public SupportExprNode(Object value) {
this.type = value.getClass();
this.value = value;
}
public SupportExprNode(Object value, Class type) {
this.value = value;
this.type = type;
}
public ExprEvaluator getExprEvaluator() {
return this;
}
public ExprNode validate(ExprValidationContext validationContext) throws ExprValidationException {
// Keep a count for if and when this was validated
validateCount++;
validateCountSnapshot = validateCount;
return null;
}
public boolean isConstantResult() {
return false;
}
public Class getType() {
return type;
}
public int getValidateCountSnapshot() {
return validateCountSnapshot;
}
public Object evaluate(EventBean[] eventsPerStream, boolean isNewData, ExprEvaluatorContext context) {
return value;
}
public void setValue(Object value) {
this.value = value;
}
public void toPrecedenceFreeEPL(StringWriter writer) {
if (value instanceof String) {
writer.append("\"" + value + "\"");
} else {
if (value == null) {
writer.append("null");
} else {
writer.append(value.toString());
}
}
}
public ExprPrecedenceEnum getPrecedence() {
return ExprPrecedenceEnum.UNARY;
}
public boolean equalsNode(ExprNode node, boolean ignoreStreamPrefix) {
if (!(node instanceof SupportExprNode)) {
return false;
}
SupportExprNode other = (SupportExprNode) node;
return value.equals(other.value);
}
}