Interface Expression

All Known Implementing Classes:
And, Constant, Not, Or, Variable

public interface Expression
Represents an expression in a simple boolean grammar for the Interpreter design pattern.

Implementations of this interface define how to interpret the expression given a context of variable bindings. This allows for the evaluation of logical expressions such as AND, OR, NOT, constants, and variables.

Example usage:

     Expression expr = new And(new Variable("x"), new Not(new Variable("y")));
     boolean result = expr.interpret(Map.of("x", true, "y", false));
 
Since:
1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Interprets this expression under the provided context of variable bindings.
  • Method Details

    • interpret

      boolean interpret(Map<String,Boolean> ctx)
      Interprets this expression under the provided context of variable bindings.
      Parameters:
      ctx - a map containing variable names as keys and their boolean values as values
      Returns:
      the boolean result of evaluating this expression with the given context
      Throws:
      IllegalStateException - if a required variable is not present in the context