Class ExpressionEvaluator

java.lang.Object
dev.vanengine.core.ExpressionEvaluator

public class ExpressionEvaluator extends Object
Evaluates JavaScript-like expressions against a Java data model. Supports property access (Map/record/POJO/Collection.length), comparison, logical, ternary, arithmetic operators, and parentheses.

Thread-safe and stateless — create one instance and reuse.

  • Constructor Details

    • ExpressionEvaluator

      public ExpressionEvaluator()
  • Method Details

    • evaluate

      public Object evaluate(String expr, Map<String,?> scope)
      Evaluate an expression string against the given scope.
      Parameters:
      expr - the expression (e.g. ctx.packages.length > 0 && format === 'MAVEN')
      scope - the data scope (model map, may include loop variables)
      Returns:
      the result (Boolean, Number, String, null, or Object)
    • isTruthy

      public boolean isTruthy(String expr, Map<String,?> scope)
      Evaluate an expression and return its truthiness (matching JavaScript semantics).
    • isTruthy

      public static boolean isTruthy(Object value)
      Check truthiness of a value (JavaScript semantics). Falsy: null, false, 0, "", empty collection.
    • resolvePath

      public static Object resolvePath(String path, Map<String,?> scope)
      Resolve a dot-separated property path against a scope. Supports Map, record, POJO (getter), Collection.length/isEmpty, Array.length.