DecisionResponse

@ApiStatus.Experimental
class DecisionResponse

The answers a model gave to a decision spec, one per question, in spec order.

A response can be read without the spec. Look an answer up by name with answer, or pass a question to the typed answer to get its outcome with the right result type. The typed lookup checks that the answer has the question's name and kind, and that its options or levels equal the question's. A question rebuilt with the same definition works. To check a whole response against a spec, for example one read back from storage, call requireMatches.

PropositionResult urgency = response.answer(urgent);
ClassificationResult team = response.answer(department);
RatingResult anger = response.answer(frustration);

Build a response with builder, or record a failed request with failed. Two responses are equal when their request failures and answers are equal.

Reading a response from JSON runs the same checks as building one, answer by answer. It does not compare the response with any spec.

Types

Link copied to clipboard
@ApiStatus.Experimental
class Builder

Collects one answer per question of a spec. Get one from DecisionResponse.builder. Answers can be added in any order, and the built response lists them in spec order. A builder is not safe for use from several threads at once.

Link copied to clipboard
object Companion

Creates decision responses.

Properties

Link copied to clipboard

The answers in spec order, one per question. The list cannot be modified.

Link copied to clipboard

Why the whole request failed, or null when it did not. When it is set, every answer's outcome is a failure with this same reason.

Functions

Link copied to clipboard
fun <R : Any> answer(question: Question<R>): R

Returns the outcome for the given question, typed by the question. The question does not have to be the same object that built the response. The answer must have the question's name and kind, and a choice answer's options or a rating answer's levels must equal the question's, ids and descriptions both.

Returns the answer with the given name. Use this when the name is only known at run time, then check the answer's class or DecisionAnswer.kind to read its outcome.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
@ApiStatus.Experimental
fun requireMatches(spec: DecisionSpec)

Checks that this response answers the given spec. There must be one answer per question, in the spec's order, and each answer must fit its question the way the typed answer lookup requires: same name and kind, and equal options or levels.

Link copied to clipboard
open override fun toString(): String