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

public final class ConditionResult extends Object
What evaluating a condition returned, and, from a language that can explain it, why: the value, which must be a Boolean, and a detail. When the value is a Boolean, the engine records the detail on the rule's evaluation in the run's result, unless the run stops first; any other value fails the run, and the detail is dropped.

The detail is the language's own, such as the operands a comparison read or a trace of the subexpressions it evaluated. The engine doesn't read it, only keeps it, so a caller can read it after the run. That's after the run's session has gone back to the engine, to be used by another run or closed, so the detail must not be the Session or hold it, nor anything that reads from it later.

A result without a detail for true or false is one of two shared instances, so returning one allocates nothing.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ConditionResult
    The result of a condition that was false, without a detail.
    static final ConditionResult
    The result of a condition that was true, without a detail.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable Object
    Returns why the condition evaluated to its value, in the language's own terms.
    boolean
    equals(@Nullable Object other)
    Compares the value and the detail, each with its own equals, so a detail that is an array is compared by identity, as ActionResult compares the values of its properties.
    int
     
    of(@Nullable Object value)
    Returns the result of a condition without a detail: TRUE or FALSE for a Boolean.
    of(@Nullable Object value, @Nullable Object detail)
    Returns the result of a condition with the detail that explains it.
     
    @Nullable Object
    Returns what the condition evaluated to.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • TRUE

      public static final ConditionResult TRUE
      The result of a condition that was true, without a detail.
    • FALSE

      public static final ConditionResult FALSE
      The result of a condition that was false, without a detail.
  • Method Details

    • of

      public static ConditionResult of(@Nullable Object value)
      Returns the result of a condition without a detail: TRUE or FALSE for a Boolean.
      Parameters:
      value - What the condition evaluated to. Anything but a Boolean, including null, fails the rule.
      Returns:
      The result
    • of

      public static ConditionResult of(@Nullable Object value, @Nullable Object detail)
      Returns the result of a condition with the detail that explains it. With a null detail, it's of(Object).
      Parameters:
      value - What the condition evaluated to. Anything but a Boolean, including null, fails the rule.
      detail - Why, in the language's own terms, or null for no detail. It must not be the Session or hold it.
      Returns:
      The result
    • value

      public @Nullable Object value()
      Returns what the condition evaluated to.
      Returns:
      The value, which fails the rule unless it's a Boolean
    • detail

      public @Nullable Object detail()
      Returns why the condition evaluated to its value, in the language's own terms.
      Returns:
      The detail, or null if the language gave none
    • equals

      public boolean equals(@Nullable Object other)
      Compares the value and the detail, each with its own equals, so a detail that is an array is compared by identity, as ActionResult compares the values of its properties.
      Overrides:
      equals in class Object
      Parameters:
      other - The object to compare with
      Returns:
      Whether other is a result with an equal value and an equal detail
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object