/**
     * Creates a new {@link SpelExpressionOutput} for the given field, SpEL expression and
     * parameters.
     *
     * @param expression must not be {@literal null} or empty.
     * @param parameters must not be {@literal null}.
     */
    public SpelExpressionOutput(String expression, Object[] parameters) {

      super(Fields.field(expression));

      Assert.hasText(expression, "Expression must not be null!");
      Assert.notNull(parameters, "Parameters must not be null!");

      this.expression = expression;
      this.params = parameters.clone();
    }
    /**
     * Creates a new {@link Output} for the given field.
     *
     * @param operation the actual operation key, must not be {@literal null} or empty.
     * @param values the values to pass into the operation, must not be {@literal null}.
     */
    public OperationOutput(String operation, Collection<? extends Object> values) {

      super(Fields.field(operation));

      Assert.hasText(operation, "Operation must not be null or empty!");
      Assert.notNull(values, "Values must not be null!");

      this.operation = operation;
      this.values = new ArrayList<Object>(values);
    }
Ejemplo n.º 3
0
  @Override
  public final void fromArray(Object[] array, Field<?>... f) {
    Fields accept = new Fields(f);
    int size = fields.size();

    for (int i = 0; i < size && i < array.length; i++) {
      Field field = fields.field(i);

      if (accept.field(field) != null) {
        Utils.setValue(this, field, array[i]);
      }
    }
  }
    /**
     * Returns the finally to be applied {@link BucketOperation} with the given alias.
     *
     * @param alias will never be {@literal null} or empty.
     * @return
     */
    public T as(String alias) {

      if (value instanceof OperationOutput) {
        return this.operation.andOutput(((OperationOutput) this.value).withAlias(alias));
      }

      if (value instanceof Field) {
        throw new IllegalStateException(
            "Cannot add a field as top-level output. Use accumulator expressions.");
      }

      return this.operation.andOutput(
          new AggregationExpressionOutput(Fields.field(alias), (AggregationExpression) value));
    }
    /**
     * Creates a new instance of this {@link OperationOutput} with the given alias.
     *
     * @param alias the alias to set
     * @return
     */
    public OperationOutput withAlias(String alias) {

      final Field aliasedField = Fields.field(alias);
      return new OperationOutput(aliasedField, this) {

        @Override
        protected Field getField() {
          return aliasedField;
        }

        @Override
        protected List<Object> getOperationArguments(AggregationOperationContext context) {

          // We have to make sure that we use the arguments from the "previous" OperationOutput that
          // we replace
          // with this new instance.
          return OperationOutput.this.getOperationArguments(context);
        }
      };
    }
Ejemplo n.º 6
0
 @Override
 public final Field<?> field(int index) {
   return fields.field(index);
 }
Ejemplo n.º 7
0
 @Override
 public final Field<?> field(String name) {
   return fields.field(name);
 }
Ejemplo n.º 8
0
 @Override
 public final <T> Field<T> field(Field<T> field) {
   return fields.field(field);
 }