Class DecisionOutcome

java.lang.Object
com.tnsai.context.decision.DecisionOutcome

public final class DecisionOutcome extends Object
Represents the outcome of a decision and its effects.

DecisionOutcome captures what happened as a result of the decision: whether it succeeded, any errors, and observable effects. This enables learning from past decisions and improving future ones.

Usage Example


 DecisionOutcome outcome = DecisionOutcome.success()
     .result("Discount approved and applied")
     .effect("Customer notified via email")
     .effect("Order total reduced by $300")
     .metric("processingTime", 1250)
     .metric("discountAmount", 300.00)
     .build();

 // Or for failure
 DecisionOutcome failure = DecisionOutcome.failure()
     .error("InsufficientInventory", "Requested quantity not available")
     .effect("Customer waitlisted")
     .build();
 
  • Method Details

    • success

      public static DecisionOutcome.Builder success()
      Creates a builder for a successful outcome.
    • failure

      public static DecisionOutcome.Builder failure()
      Creates a builder for a failed outcome.
    • partial

      public static DecisionOutcome.Builder partial()
      Creates a builder for a partial success.
    • pending

      public static DecisionOutcome.Builder pending()
      Creates a builder for a pending outcome.
    • builder

      public static DecisionOutcome.Builder builder()
      Creates a new builder.
    • getStatus

      public DecisionOutcome.OutcomeStatus getStatus()
    • getResult

      public String getResult()
    • getEffects

      public List<String> getEffects()
    • getError

    • getMetrics

      public Map<String,Object> getMetrics()
    • getCompletedAt

      public Instant getCompletedAt()
    • getExecutionTime

      public Optional<Duration> getExecutionTime()
    • getFeedback

      public Optional<String> getFeedback()
    • isSuccess

      public boolean isSuccess()
      Returns true if the outcome was successful.
    • isFailed

      public boolean isFailed()
      Returns true if the outcome failed.
    • hasError

      public boolean hasError()
      Returns true if there was an error.
    • hasEffects

      public boolean hasEffects()
      Returns true if there are any effects.
    • getMetric

      public Optional<Object> getMetric(String key)
      Gets a metric value.
      Parameters:
      key - metric key
      Returns:
      Optional containing the value if present
    • getMetric

      public <T> Optional<T> getMetric(String key, Class<T> type)
      Gets a typed metric value.
      Parameters:
      key - metric key
      type - expected type
      Returns:
      Optional containing the typed value if present and castable
    • toString

      public String toString()
      Overrides:
      toString in class Object