public FilterBuilder getFilter(Condition<?> condition, KeyInformation.StoreRetriever informations) {
if (condition instanceof PredicateCondition) {
PredicateCondition<String, ?> atom = (PredicateCondition) condition;
Object value = atom.getValue();
String key = atom.getKey();
TitanPredicate titanPredicate = atom.getPredicate();
if (value instanceof Number) {
Preconditions.checkArgument(titanPredicate instanceof Cmp, "Relation not supported on numeric types: " + titanPredicate);
Cmp numRel = (Cmp) titanPredicate;
Preconditions.checkArgument(value instanceof Number);
switch (numRel) {
case EQUAL:
return FilterBuilders.inFilter(key, value);
case NOT_EQUAL:
return FilterBuilders.notFilter(FilterBuilders.inFilter(key, value));
case LESS_THAN:
return FilterBuilders.rangeFilter(key).lt(value);
case LESS_THAN_EQUAL:
return FilterBuilders.rangeFilter(key).lte(value);
case GREATER_THAN:
return FilterBuilders.rangeFilter(key).gt(value);
case GREATER_THAN_EQUAL:
return FilterBuilders.rangeFilter(key).gte(value);
default:
throw new IllegalArgumentException("Unexpected relation: " + numRel);
}
} else if (value instanceof String) {
Mapping map = Mapping.getMapping(informations.get(key));
if ((map==Mapping.DEFAULT || map==Mapping.TEXT) && !titanPredicate.toString().startsWith("CONTAINS"))
throw new IllegalArgumentException("Text mapped string values only support CONTAINS queries and not: " + titanPredicate);
if (map==Mapping.STRING && titanPredicate.toString().startsWith("CONTAINS"))
throw new IllegalArgumentException("String mapped string values do not support CONTAINS queries: " + titanPredicate);
if (titanPredicate == Text.CONTAINS) {
value = ((String) value).toLowerCase();
return FilterBuilders.termFilter(key, (String) value);