throw new ODataNotImplementedException();
}
case BINARY:
final BinaryExpression binaryExpression = (BinaryExpression) expression;
final EdmSimpleType type = (EdmSimpleType) binaryExpression.getLeftOperand().getEdmType();
final String left = evaluateExpression(data, binaryExpression.getLeftOperand());
final String right = evaluateExpression(data, binaryExpression.getRightOperand());
switch (binaryExpression.getOperator()) {
case ADD:
if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
|| binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
|| binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
return Double.toString(Double.valueOf(left) + Double.valueOf(right));
} else {
return Long.toString(Long.valueOf(left) + Long.valueOf(right));
}
case SUB:
if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
|| binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
|| binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
return Double.toString(Double.valueOf(left) - Double.valueOf(right));
} else {
return Long.toString(Long.valueOf(left) - Long.valueOf(right));
}
case MUL:
if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
|| binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
|| binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
return Double.toString(Double.valueOf(left) * Double.valueOf(right));
} else {
return Long.toString(Long.valueOf(left) * Long.valueOf(right));
}
case DIV:
final String number = Double.toString(Double.valueOf(left) / Double.valueOf(right));
return number.endsWith(".0") ? number.replace(".0", "") : number;
case MODULO:
if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
|| binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
|| binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
return Double.toString(Double.valueOf(left) % Double.valueOf(right));
} else {
return Long.toString(Long.valueOf(left) % Long.valueOf(right));
}
case AND:
return Boolean.toString(left.equals("true") && right.equals("true"));
case OR:
return Boolean.toString(left.equals("true") || right.equals("true"));
case EQ:
return Boolean.toString(left.equals(right));
case NE:
return Boolean.toString(!left.equals(right));
case LT:
if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
return Boolean.toString(left.compareTo(right) < 0);
} else {
return Boolean.toString(Double.valueOf(left) < Double.valueOf(right));
}
case LE:
if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
return Boolean.toString(left.compareTo(right) <= 0);
} else {
return Boolean.toString(Double.valueOf(left) <= Double.valueOf(right));
}
case GT:
if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
return Boolean.toString(left.compareTo(right) > 0);
} else {
return Boolean.toString(Double.valueOf(left) > Double.valueOf(right));
}
case GE:
if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
|| type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
return Boolean.toString(left.compareTo(right) >= 0);
} else {
return Boolean.toString(Double.valueOf(left) >= Double.valueOf(right));
}
case PROPERTY_ACCESS:
throw new ODataNotImplementedException();
default:
throw new ODataNotImplementedException();
}
case PROPERTY:
final EdmProperty property = (EdmProperty) ((PropertyExpression) expression).getEdmProperty();
final EdmSimpleType propertyType = (EdmSimpleType) property.getType();
return propertyType.valueToString(valueAccess.getPropertyValue(data, property), EdmLiteralKind.DEFAULT,
property.getFacets());
case MEMBER:
final MemberExpression memberExpression = (MemberExpression) expression;
final PropertyExpression propertyExpression = (PropertyExpression) memberExpression.getProperty();
final EdmProperty memberProperty = (EdmProperty) propertyExpression.getEdmProperty();
final EdmSimpleType memberType = (EdmSimpleType) memberExpression.getEdmType();
List<EdmProperty> propertyPath = new ArrayList<EdmProperty>();
CommonExpression currentExpression = memberExpression;
while (currentExpression != null) {
final PropertyExpression currentPropertyExpression =
(PropertyExpression) (currentExpression.getKind() == ExpressionKind.MEMBER ?
((MemberExpression) currentExpression).getProperty() : currentExpression);
final EdmTyped currentProperty = currentPropertyExpression.getEdmProperty();
final EdmTypeKind kind = currentProperty.getType().getKind();
if (kind == EdmTypeKind.SIMPLE || kind == EdmTypeKind.COMPLEX) {
propertyPath.add(0, (EdmProperty) currentProperty);
} else {
throw new ODataNotImplementedException();
}
currentExpression =
currentExpression.getKind() == ExpressionKind.MEMBER ? ((MemberExpression) currentExpression).getPath()
: null;
}
return memberType.valueToString(getPropertyValue(data, propertyPath), EdmLiteralKind.DEFAULT, memberProperty
.getFacets());
case LITERAL:
final LiteralExpression literal = (LiteralExpression) expression;
final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType();
return literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null,
literalType.getDefaultType()),
EdmLiteralKind.DEFAULT, null);
case METHOD:
final MethodExpression methodExpression = (MethodExpression) expression;
final String first = evaluateExpression(data, methodExpression.getParameters().get(0));