java.lang.Object
io.github.brantunger.unruly.api.language.ActionResult

public final class ActionResult extends Object
What an action did: changed the output object itself (done()), or produced properties for the engine to set on it (set(Map)). A language whose expressions compute values without side effects returns properties.

The engine sets the properties in the order of the map, after the action returns, with the engine's OutputWriter. By default that is put on a Map output, and on any other output the public setter whose parameter accepts the value, such as setInterestRate for interestRate, converting it only as Java widens a primitive, when no setter takes it as it is, such as an Integer for a setter taking a long; when no setter takes it so either, the rule's language is asked to convert it for each setter's type, with ExpressionCompiler.convertOutput(Object, Class), so a language whose numbers are doubles can set a setter taking an int with a whole Double. A property the writer can't set fails the rule with a RuleExecutionException, which listeners receive in onError. In a run of an engine that fires every match, each firing rule's properties are set in turn, so a later rule can overwrite an earlier one's.

  • Method Details

    • done

      public static ActionResult done()
      Returns the result of an action that changed the output object itself, or changed nothing.
      Returns:
      The result, with no properties
    • set

      public static ActionResult set(Map<String,? extends @Nullable Object> properties)
      Returns the result of an action that produced properties for the engine to set on the output object.
      Parameters:
      properties - The values by property name, in the order to set them; copied. Values can be null.
      Returns:
      The result
      Throws:
      NullPointerException - if properties or one of its names is null
      IllegalArgumentException - if a name is empty
    • properties

      public Map<String,@Nullable Object> properties()
      Returns the properties to set on the output object.
      Returns:
      The values by property name, in the order they're set; empty for done(); unmodifiable
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object