Bindings
A Binding is a named, typed variable. A Bindings container holds multiple bindings and acts as the shared workspace for rules — conditions read from it, and actions write to it.
Creating Bindings
Section titled “Creating Bindings”// Create a standard bindings containerBindings bindings = Bindings.builder().standard();
// Simple bind (type is inferred)bindings.bind("name", "Alice");bindings.bind("age", 30);
// Typed bind (explicit type)bindings.bind("score", Integer.class, 95);
// Generic types using TypeReferencebindings.bind("tags", new TypeReference<List<String>>() {}, new ArrayList<>());Lambda Shorthand
Section titled “Lambda Shorthand”When running rules, you can pass bindings as lambdas. The parameter name becomes the binding name:
// These two are equivalent:
// ExplicitBindings b = Bindings.builder().standard();b.bind("name", "Alice");b.bind("age", 30);rule.run(b);
// Lambda shorthandrule.run(name -> "Alice", age -> 30);Reading Values
Section titled “Reading Values”// Get value (returns Object)Object val = bindings.getValue("name");
// Get the Binding object itselfBinding<String> binding = bindings.getBinding("name");String name = binding.getValue(); // "Alice"Updating Values
Section titled “Updating Values”// Update via the Binding objectBinding<Integer> ageBind = bindings.getBinding("age");ageBind.setValue(31);
// Or directly on the container — returns the previous valueInteger prev = bindings.setValue("age", 31); // prev == 30
// setValueOrBind: sets the value if the binding exists,// otherwise creates a new binding. Returns the previous value or null.Integer old = bindings.setValueOrBind("score", 100);Checking Bindings
Section titled “Checking Bindings”// Does a binding exist?boolean exists = bindings.contains("name"); // true
// How many bindings?int count = bindings.size();
// View as a Map (returns this — no copy made)Map<String, Object> map = bindings.asMap();Bindings as a Map
Section titled “Bindings as a Map”As of 1.2.0, Bindings directly implements java.util.Map<String, Object>. You can pass a Bindings instance anywhere a Map is expected — useful for scripting integration and interop with libraries that consume Map.
// Full Map contract — read operationsbindings.containsKey("name"); // truebindings.containsValue("Alice"); // truebindings.get("age"); // 30bindings.keySet(); // Set of binding namesbindings.values(); // Collection of valuesbindings.entrySet(); // Set of name-value entries
// Mutation via Map API uses bind/setValue semanticsbindings.put("status", "approved");
// remove() and clear() throw UnsupportedOperationExceptionScoped Bindings
Section titled “Scoped Bindings”Scoped bindings create a child scope that inherits from a parent. Changes in the child don’t affect the parent:
Bindings scoped = Bindings.builder().scoped();// Useful for isolating rule execution contexts