# Interface Optimization.OnFilter<R>

Type Parameters:
  `R` - the type of resources to filter.

All Superinterfaces:
  `Filter<R>`, `Predicate<R>`

Enclosing class:
  `Optimization`

public static interface Optimization.OnFilter<R> extends Filter<R>
Filter that can be optimized. Each filter 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.

Since:
  1.1

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default Predicate<R>`
  `and(Predicate<? super R> other)`
  Returns the `AND` logical operation between this filter and the given predicate.
  `default Predicate<R>`
  `negate()`
  Returns the logical negation of this filter.
  `default Filter<R>`
  `optimize(Optimization optimization)`
  Tries to optimize this filter.
  `default Predicate<R>`
  `or(Predicate<? super R> other)`
  Returns the `OR` logical operation between this filter and the given predicate.
  `default Filter<R>`
  `recreate(Expression<R,?>[] effective)`
  Creates a new filter of the same type and parameters than this filter, except for the expressions.

  ### Methods inherited from interface Filter

  `getExpressions, getOperatorType, getResourceClass, test`

- ## Method Details

  - ### optimize

    default Filter<R> optimize(Optimization optimization)
    Tries to optimize this filter. The default implementation performs the following steps:
    - If all expressions are literals, evaluate this filter immediately.
    - Otherwise if at least one child expression can be optimized, recreate the filter.
    - Otherwise returns `this`.
    Parameters:
      `optimization` - the simplifications or optimizations to apply on this filter.
    Returns:
      the simplified or optimized filter, or `this` if no optimization has been applied.

  - ### recreate

    default Filter<R> recreate(Expression<R,?>[] effective)
    Creates a new filter of the same type and parameters than this filter, except for the expressions. The expressions given to this method shall be equivalent to the expressions used by this filter, potentially more efficient.

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

    Parameters:
      `effective` - the expressions to use as a replacement of this filter expressions.
    Returns:
      the new filter, or `this` if unsupported.

  - ### and

    default Predicate<R> and(Predicate<? super R> other)
    Returns the `AND` logical operation between this filter and the given predicate. If the given predicate is an instance of `Filter<R>`, then the returned predicate is also an instance of `Filter<R>`.
    Specified by:
      `and` in interface `Predicate<R>`
    Parameters:
      `other` - the other predicate.
    Returns:
      the `AND` logical operation between this filter and the given predicate.
    See Also:
      - `DefaultFilterFactory​.and(Filter, Filter)`

  - ### or

    default Predicate<R> or(Predicate<? super R> other)
    Returns the `OR` logical operation between this filter and the given predicate. If the given predicate is an instance of `Filter<R>`, then the returned predicate is also an instance of `Filter<R>`.
    Specified by:
      `or` in interface `Predicate<R>`
    Parameters:
      `other` - the other predicate.
    Returns:
      the `OR` logical operation between this filter and the given predicate.
    See Also:
      - `DefaultFilterFactory​.or(Filter, Filter)`

  - ### negate

    default Predicate<R> negate()
    Returns the logical negation of this filter. The returned predicate is an instance of `Optimization​.OnFilter`.
    Specified by:
      `negate` in interface `Predicate<R>`
    Returns:
      the logical negation of this filter.