Class Reducer


  • public final class Reducer
    extends java.lang.Object
    Reducer provides methods to reduce expressions to a value. Reduction is performed with the help of the calculator that evaluates specific subexpressions.
    • Constructor Detail

      • Reducer

        public Reducer()
    • Method Detail

      • reduce

        public static Node reduce​(CalculatorEngine engine,
                                  ValueProvider valueProvider,
                                  ReduceOptions options,
                                  Node expression)
        Attempts to reduce the specified expression including to a value. Reduction is performed with the help of the calculator object that performs specific operations with specific data types.

        The operation may be totally reduced (or, so to speak, reduced to a value), partially reduced or left unchanged. In the last case, the method returns a reference to the current operation (this).

        Parameters:
        engine - Calculator engine (if null, the default engine to be used).
        valueProvider - Provider of variable values to be used for expression reduction.
        options - Option flags to tune the reduction strategy.
        expression - Expression to be reduced.
        Returns:
        Reduced expression (value or another operation expression with minimal subexpressions) or the initial expression if it is impossible to reduce it.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
      • reduce

        public static Node reduce​(ReduceOptions options,
                                  Node expression)
        Attempts to reduce the specified expression including to a value. Uses default engine.
        Parameters:
        options - Option flags to tune the reduction strategy.
        expression - Expression to be reduced.
        Returns:
        Reduced expression.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.
        See Also:
        reduce(CalculatorEngine, ReduceOptions, Node)
      • reduce

        public static Node reduce​(CalculatorEngine engine,
                                  ReduceOptions options,
                                  Node expression)
        Attempts to reduce the specified expression including to a value. Reduction is performed with the help of the calculator object that performs specific operations with specific data types.

        The operation may be totally reduced (or, so to speak, reduced to a value), partially reduced or left unchanged. In the last case, the method returns a reference to the current operation (this).

        Parameters:
        engine - Calculator engine (if null, the default engine to be used).
        options - Option flags to tune the reduction strategy.
        expression - Expression to be reduced.
        Returns:
        Reduced expression (value or another operation expression with minimal subexpressions) or the initial expression if it is impossible to reduce it.
        Throws:
        java.lang.IllegalArgumentException - if any of the parameters is null.