com.evuv.expressions.SimplePropertyExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of evuv-exp-parser Show documentation
Show all versions of evuv-exp-parser Show documentation
Boolean expression parser and evaluator
The newest version!
package com.evuv.expressions;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.evuv.EventProperty;
import com.evuv.GenericNumber;
import com.evuv.exceptions.EventBindingException;
public class SimplePropertyExpression> implements ComparableExpression, BindedExpression {
private EventProperty ev;
public SimplePropertyExpression(EventProperty ev) {
this.ev = ev;
}
@Override
public T getValue() {
return ev.getPropertyValue();
}
@Override
public int compareTo(T o) {
return ev.getPropertyValue().compareTo(o);
}
@SuppressWarnings("rawtypes")
@Override
public Expression getLeft() {
return null;
}
@SuppressWarnings("rawtypes")
@Override
public void setLeft(Expression left) {
}
@SuppressWarnings("rawtypes")
@Override
public Expression getRight() {
return null;
}
@SuppressWarnings("rawtypes")
@Override
public void setRight(Expression right) {
}
public List toFlatExression() {
return Collections.emptyList();
}
@Override
public String toString() {
return ev.getPropertyName();
}
@SuppressWarnings("unchecked")
@Override
public SimplePropertyExpression bind(Map event) throws EventBindingException {
Object value = event.get(ev.getPropertyName());
EventProperty newEv = new EventProperty<>();
newEv.setPropertyName(ev.getPropertyName());
if ( value == null ) {
// support missing value
newEv.setPropertyValue(null);
} else if (value instanceof Number) {
newEv.setPropertyValue((T) new GenericNumber(value));
} else if (value instanceof String ) {
newEv.setPropertyValue((T) value);
} else {
throw new EventBindingException (String.format("cannot bind %s to value %s", ev.getPropertyName(), value));
}
return new SimplePropertyExpression<>(newEv);
}
}