Interface Optimization.OnExpression<R,V>

Type Parameters:
R - the type of resources used as inputs.
V - the type of values computed by the expression.
All Superinterfaces:
Expression<R,V>, Function<R,V>
Enclosing class:

public static interface Optimization.OnExpression<R,V> extends Expression<R,V>
Expression that can be optimized. Each expression implementation knows which rules can be applied. For that reason, the optimization algorithms are kept in each implementation class. This interface allows Optimization to invoke that code.

Implementations need to override only one of the 2 methods defined in this interface.

  • Method Details

    • optimize

      default Expression<? super R,? extends V> optimize(Optimization optimization)
      Tries to optimize this expression. The default implementation performs the following steps:
      • If all expressions are literals, evaluate this expression immediately.
      • Otherwise if at least one parameter can be optimized, recreate the expression.
      • Otherwise returns this.
      optimization - the simplifications or optimizations to apply on this expression.
      the simplified or optimized expression, or this if no optimization has been applied.
    • recreate

      default Expression<R,V> recreate(Expression<? super R,?>[] effective)
      Creates a new expression of the same type than this expression, but with optimized parameters. The expressions given to this method shall be equivalent to the expressions used by this instance, potentially more efficient.

      This method is used by the default implementation of optimize(Optimization) and can be ignored if above method is overridden.

      effective - the expressions to use as a replacement of this expression parameters.
      the new expression, or this if unsupported.