Esempio n. 1
0
 private SerializablePredicate<HString> generate(Expression e) {
   if (e.isInstance(ValueExpression.class)) {
     return s -> s.contains(e.as(ValueExpression.class).value);
   } else if (e.isInstance(PrefixExpression.class)) {
     PrefixExpression pe = e.as(PrefixExpression.class);
     if (pe.operator.getType().isInstance(Types.NOT)) {
       return negate(generate(pe.right));
     } else if (pe.operator.getType().isInstance(Types.FIELD)) {
       final AttributeType attributeType =
           com.davidbracewell.hermes.Types.attribute(
               pe.operator.getText().substring(1, pe.operator.getText().length() - 2));
       final SerializablePredicate<HString> predicate = generate(pe.right);
       return hString ->
           hString.document().contains(attributeType)
               && predicate.test(
                   Fragments.string(hString.document().get(attributeType).asString()));
     }
     return generate(pe.right);
   }
   BinaryOperatorExpression boe = e.as(BinaryOperatorExpression.class);
   SerializablePredicate<HString> left = generate(boe.left);
   SerializablePredicate<HString> right = generate(boe.right);
   return boe.operator.getType().isInstance(Operator.AND) ? and(left, right) : or(left, right);
 }
Esempio n. 2
0
 SerializablePredicate<HString> or(
     SerializablePredicate<HString> l, SerializablePredicate<HString> r) {
   return (hString -> l.test(hString) || r.test(hString));
 }
Esempio n. 3
0
 SerializablePredicate<HString> and(
     SerializablePredicate<HString> l, SerializablePredicate<HString> r) {
   return (hString -> l.test(hString) && r.test(hString));
 }
Esempio n. 4
0
 SerializablePredicate<HString> negate(SerializablePredicate<HString> p) {
   return (hString -> !p.test(hString));
 }