private Condition toCondition(Filter filter) {
if (Filter.BINARY_OPERATORS.contains(filter.operator)) {
if (filter.operand == null)
throw new IllegalArgumentException("Operand of a condition cannot be null.");
return new Condition()
.withComparisonOperator(sOperatorMap.get(filter.operator))
.withAttributeValueList(valueToAttr(filter.field, filter.operand));
}
if (Filter.UNARY_OPERATORS.contains(filter.operator)) {
return new Condition()
.withComparisonOperator(sOperatorMap.get(filter.operator));
}
if (Filter.TRINARY_OPERATORS.contains(filter.operator)) {
if (filter.operand == null || filter.operand2 == null)
throw new IllegalArgumentException("Operand of a condition cannot be null.");
return new Condition()
.withComparisonOperator(sOperatorMap.get(filter.operator))
.withAttributeValueList(valueToAttr(filter.field, filter.operand),
valueToAttr(filter.field, filter.operand2));
}
if (Filter.LIST_OPERATORS.contains(filter.operator)) {
Condition cond = new Condition()
.withComparisonOperator(sOperatorMap.get(filter.operator));
List<AttributeValue> attrs = new ArrayList<AttributeValue>();
for (Object valueObj : filter.operands) {
attrs.add(valueToAttr(filter.field, valueObj));
}
cond.setAttributeValueList(attrs);
return cond;
}
throw new UnsupportedOperationException("Condition operator " + filter.operator + " is not supported.");
}