Interface GuardrailService.Builder
- Enclosing interface:
GuardrailService
public static interface GuardrailService.Builder
Builder class for building
GuardrailService instances-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns an instance ofGuardrailService.default <I extends InputGuardrail>
GuardrailService.BuilderinputGuardrailClasses(Class<? extends I>... guardrailClasses) Configures the classes of input guardrails for the Builder.<I extends InputGuardrail>
GuardrailService.BuilderinputGuardrailClasses(List<Class<? extends I>> guardrailClasses) Configures the classes of input guardrails for the Builder.default <I extends InputGuardrail>
GuardrailService.BuilderinputGuardrails(I... guardrails) Configures the input guardrails for the Builder.<I extends InputGuardrail>
GuardrailService.BuilderinputGuardrails(List<I> guardrails) Sets the input guardrails for the Builder.Configures the input guardrails for the builder.default <O extends OutputGuardrail>
GuardrailService.BuilderoutputGuardrailClasses(Class<? extends O>... guardrailClasses) Configures the classes of output guardrails for the Builder.<O extends OutputGuardrail>
GuardrailService.BuilderoutputGuardrailClasses(List<Class<? extends O>> guardrailClasses) Configures the classes of output guardrails for the Builder.<O extends OutputGuardrail>
GuardrailService.BuilderoutputGuardrails(List<O> guardrails) Sets the output guardrails for the Builder.default <O extends OutputGuardrail>
GuardrailService.BuilderoutputGuardrails(O... guardrails) Configures the output guardrails for the Builder.Configures the output guardrails for the Builder.
-
Method Details
-
inputGuardrailsConfig
Configures the input guardrails for the builder.- Parameters:
config- The configuration for input guardrails. Must not be null.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining. - Throws:
IllegalArgumentException- ifconfigis null.
-
outputGuardrailsConfig
Configures the output guardrails for the Builder.- Parameters:
config- The configuration for output guardrails. Must not be null.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining. - Throws:
IllegalArgumentException- ifconfigis null.
-
inputGuardrailClasses
<I extends InputGuardrail> GuardrailService.Builder inputGuardrailClasses(List<Class<? extends I>> guardrailClasses) Configures the classes of input guardrails for the Builder. Existing input guardrail classes will be cleared.- Type Parameters:
I- The type ofInputGuardrail- Parameters:
guardrailClasses- A list of classes implementing theInputGuardrailinterface to be used as input guardrails. May benull.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining.
-
inputGuardrailClasses
default <I extends InputGuardrail> GuardrailService.Builder inputGuardrailClasses(Class<? extends I>... guardrailClasses) Configures the classes of input guardrails for the Builder. Existing input guardrail classes will be cleared.- Type Parameters:
I- The type ofInputGuardrail- Parameters:
guardrailClasses- An array of classes implementing theInputGuardrailinterface to be used as input guardrails. May benull.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining.
-
outputGuardrailClasses
<O extends OutputGuardrail> GuardrailService.Builder outputGuardrailClasses(List<Class<? extends O>> guardrailClasses) Configures the classes of output guardrails for the Builder. Existing output guardrail classes will be cleared.- Type Parameters:
O- The type ofOutputGuardrail- Parameters:
guardrailClasses- A list of classes implementing theOutputGuardrailinterface to be used as output guardrails. May benull.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining.
-
outputGuardrailClasses
default <O extends OutputGuardrail> GuardrailService.Builder outputGuardrailClasses(Class<? extends O>... guardrailClasses) Configures the classes of output guardrails for the Builder. Existing output guardrail classes will be cleared.- Type Parameters:
O- The type ofOutputGuardrail- Parameters:
guardrailClasses- An array of classes implementing theOutputGuardrailinterface to be used as output guardrails. May benull.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining.
-
inputGuardrails
Sets the input guardrails for the Builder. Existing input guardrails will be cleared, and the provided input guardrails will be added.- Parameters:
guardrails- A list of input guardrails implementing theInputGuardrailinterface. Can benull, in which case no guardrails will be added.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining.
-
inputGuardrails
Configures the input guardrails for the Builder.- Parameters:
guardrails- An array of input guardrails implementing theInputGuardrailinterface. May benull, in which case no guardrails will be added.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining.
-
outputGuardrails
Sets the output guardrails for the Builder. Existing output guardrails will be cleared, and the provided output guardrails will be added.- Parameters:
guardrails- A list of output guardrails implementing theOutputGuardrailinterface. Can benull, in which case no guardrails will be added.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining.
-
outputGuardrails
Configures the output guardrails for the Builder.- Parameters:
guardrails- An array of output guardrails implementing theOutputGuardrailinterface. May benull, in which case no guardrails will be added.- Returns:
- The current instance of
GuardrailService.Builderfor method chaining.
-
build
GuardrailService build()Builds and returns an instance ofGuardrailService. This method configures input and output guardrails for each method of the service. Guardrails set in the builder take precedence. If none are set, it uses the method-level annotations, and if those are absent, the class-level annotations.The guardrails and their configuration are resolved independently of each other, and separately for input and output guardrails. Only the first source found is used: guardrails set in the builder, on the method and on the class are not combined. Guardrails set in the builder count only when there is at least one:
nullor an empty list does not disable the guardrails declared in annotations. Guardrail instances and guardrail classes set in the builder are both used: the instances first, then the classes.- Returns:
- an instance of
GuardrailServiceconfigured with appropriate input and output guardrails.
-