}
else if (left instanceof Slice && right instanceof Slice) {
return !left.equals(right);
}
return new ComparisonExpression(node.getType(), toExpression(left), toExpression(right));
}
Object left = process(node.getLeft(), context);
if (left == null) {
return null;
}
Object right = process(node.getRight(), context);
if (right == null) {
return null;
}
if (left instanceof Long && right instanceof Long) {
switch (node.getType()) {
case EQUAL:
return ((Number) left).longValue() == ((Number) right).longValue();
case NOT_EQUAL:
return ((Number) left).longValue() != ((Number) right).longValue();
case LESS_THAN:
return ((Number) left).longValue() < ((Number) right).longValue();
case LESS_THAN_OR_EQUAL:
return ((Number) left).longValue() <= ((Number) right).longValue();
case GREATER_THAN:
return ((Number) left).longValue() > ((Number) right).longValue();
case GREATER_THAN_OR_EQUAL:
return ((Number) left).longValue() >= ((Number) right).longValue();
}
throw new UnsupportedOperationException("unhandled type: " + node.getType());
}
if (left instanceof Number && right instanceof Number) {
switch (node.getType()) {
case EQUAL:
return ((Number) left).doubleValue() == ((Number) right).doubleValue();
case NOT_EQUAL:
return ((Number) left).doubleValue() != ((Number) right).doubleValue();
case LESS_THAN:
return ((Number) left).doubleValue() < ((Number) right).doubleValue();
case LESS_THAN_OR_EQUAL:
return ((Number) left).doubleValue() <= ((Number) right).doubleValue();
case GREATER_THAN:
return ((Number) left).doubleValue() > ((Number) right).doubleValue();
case GREATER_THAN_OR_EQUAL:
return ((Number) left).doubleValue() >= ((Number) right).doubleValue();
}
throw new UnsupportedOperationException("unhandled type: " + node.getType());
}
if (left instanceof Slice && right instanceof Slice) {
switch (node.getType()) {
case EQUAL:
return left.equals(right);
case NOT_EQUAL:
return !left.equals(right);
case LESS_THAN:
return ((Slice) left).compareTo((Slice) right) < 0;
case LESS_THAN_OR_EQUAL:
return ((Slice) left).compareTo((Slice) right) <= 0;
case GREATER_THAN:
return ((Slice) left).compareTo((Slice) right) > 0;
case GREATER_THAN_OR_EQUAL:
return ((Slice) left).compareTo((Slice) right) >= 0;
}
throw new UnsupportedOperationException("unhandled type: " + node.getType());
}
if (left instanceof Boolean && right instanceof Boolean) {
switch (node.getType()) {
case EQUAL:
return left.equals(right);
case NOT_EQUAL:
return !left.equals(right);
}
throw new UnsupportedOperationException("unhandled type: " + node.getType());
}
return new ComparisonExpression(node.getType(), toExpression(left), toExpression(right));
}