Ejemplo n.º 1
0
  @Override
  public QueryResult<String> evaluate(final Map<String, String> attributes) {
    final String subjectValue = subject.evaluate(attributes).getValue();
    if (subjectValue == null) {
      return new StringQueryResult(null);
    }
    final String searchValue = search.evaluate(attributes).getValue();
    final String replacementValue = replacement.evaluate(attributes).getValue();

    return new StringQueryResult(subjectValue.replaceFirst(searchValue, replacementValue));
  }
Ejemplo n.º 2
0
  @Override
  public QueryResult<Boolean> evaluate(final Map<String, String> attributes) {
    final String subjectValue = subject.evaluate(attributes).getValue();
    if (subjectValue == null) {
      return new BooleanQueryResult(false);
    }
    final Pattern pattern;
    if (compiledPattern == null) {
      pattern = Pattern.compile(search.evaluate(attributes).getValue());
    } else {
      pattern = compiledPattern;
    }

    final boolean found = pattern.matcher(subjectValue).find();

    return new BooleanQueryResult(found);
  }
Ejemplo n.º 3
0
  @Override
  public QueryResult<Number> evaluate(final Map<String, String> attributes) {
    final Number subjectValue = subject.evaluate(attributes).getValue();
    if (subjectValue == null) {
      return new NumberQueryResult(null);
    }

    final Number plus = plusValue.evaluate(attributes).getValue();
    if (plus == null) {
      return new NumberQueryResult(null);
    }

    final Number result;
    if (subjectValue instanceof Double || plus instanceof Double) {
      result = subjectValue.doubleValue() + plus.doubleValue();
    } else {
      result = subjectValue.longValue() + plus.longValue();
    }
    return new NumberQueryResult(result);
  }
Ejemplo n.º 4
0
  public FindEvaluator(final Evaluator<String> subject, final Evaluator<String> search) {
    this.subject = subject;
    this.search = search;

    // if the search string is a literal, we don't need to evaluate it each time; we can just
    // pre-compile it. Otherwise, it must be compiled every time.
    if (search instanceof StringLiteralEvaluator) {
      this.compiledPattern = Pattern.compile(search.evaluate(null).getValue());
    } else {
      this.compiledPattern = null;
    }
  }