Package com.tnsai.context.decision
Class DecisionOutcome
java.lang.Object
com.tnsai.context.decision.DecisionOutcome
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();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for DecisionOutcome.static final recordRepresents an error in the outcome.static enumStatus of the decision outcome. -
Method Summary
Modifier and TypeMethodDescriptionstatic DecisionOutcome.Builderbuilder()Creates a new builder.static DecisionOutcome.Builderfailure()Creates a builder for a failed outcome.getError()Gets a metric value.<T> Optional<T> Gets a typed metric value.booleanReturns true if there are any effects.booleanhasError()Returns true if there was an error.booleanisFailed()Returns true if the outcome failed.booleanReturns true if the outcome was successful.static DecisionOutcome.Builderpartial()Creates a builder for a partial success.static DecisionOutcome.Builderpending()Creates a builder for a pending outcome.static DecisionOutcome.Buildersuccess()Creates a builder for a successful outcome.toString()
-
Method Details
-
success
Creates a builder for a successful outcome. -
failure
Creates a builder for a failed outcome. -
partial
Creates a builder for a partial success. -
pending
Creates a builder for a pending outcome. -
builder
Creates a new builder. -
getStatus
-
getResult
-
getEffects
-
getError
-
getMetrics
-
getCompletedAt
-
getExecutionTime
-
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
Gets a metric value.- Parameters:
key- metric key- Returns:
- Optional containing the value if present
-
getMetric
Gets a typed metric value.- Parameters:
key- metric keytype- expected type- Returns:
- Optional containing the typed value if present and castable
-
toString
-