Interface IValueBuilderConfigurator
public interface IValueBuilderConfigurator
Configurator for a set of
IValueBuilderOptions, for use with the
builder obtained from a IValueDescriptor. Use methods
from ValueBuilderOptions to obtain an instance of this interface. It lets you configure some details of how
the value will be created.- Since:
- 8.5.0
-
Method Summary
Modifier and TypeMethodDescriptionacceptanceCriteria(IValueAcceptanceCriteria criteria) Sets the acceptance criteria that the created value must satisfy.create()Creates a new value builder with the currently configured options.default IValueBuilderConfiguratorSets that the created value should be immutable.default IValueBuilderConfiguratormutable()Sets that the created value should be mutable.mutable(boolean mutable) Sets whether the created value should be mutable.
-
Method Details
-
acceptanceCriteria
Sets the acceptance criteria that the created value must satisfy. The builder will ensure that the value it produces will meet these criteria. Defaults to astrictset of acceptance criteria. There are use cases where you might want to relax these criteria. For example, a builder for arecord valuewill ignore all extraneous fields. If you want to preserve such fields, you canallow extraneousRecord fieldsin the acceptance criteria.// A simple descriptor that allows a single field "age" of type integer with default value 18. var f = ValueDescriptorFactory.getInstance(); var descriptor = f.recordBuilder().requiredProperty("age", f.integer(18)).build(); // We got a value from somewhere that has the wrong type for "age" and an extraneous field "name". // We want to ensure the known properties have the right type, but preserve extraneous fields. var originalValue = Map.of("age", "shouldBeAnInteger", "name", "extraneousField"); var criteria = ValueAcceptanceCriteria.builder().allowExtraneousRecordFields(true).build(); var options = ValueBuilderOptions.configurator().acceptanceCriteria(criteria).create(); var sanitizedValue = descriptor.builder(options).value(originalValue).build(); // sanitizedValue is now: // Map.of("a", 18, "b", "extraneousField")Note: It is highly discouraged to disable conformance flags such asenforceMapValueConformance. Doing so may lead to values being created that do not conform to the value descriptor at all, which may lead to runtime errors or aClassCastExceptionlater on.- Parameters:
criteria- The acceptance criteria that the created value must satisfy.- Returns:
- This configurator for method chaining.
-
create
IValueBuilderOptions create()Creates a new value builder with the currently configured options.- Returns:
- A new value builder.
-
immutable
Sets that the created value should be immutable. This is the default behavior. Note that not all value types support mutable values. In this case, the returned builder behaves as ifmutablewasfalse. In particular, the mutable flag is usually only supported for collection types (lists, maps, records).- Returns:
- This configurator for method chaining.
-
mutable
Sets that the created value should be mutable. Note that not all value types support mutable values. In this case, the returned builder behaves as ifmutablewasfalse. In particular, the mutable flag is usually only supported for collection types (lists, maps, records). The default isfalse, i.e. the created value is immutable.- Returns:
- This configurator for method chaining.
-
mutable
Sets whether the created value should be mutable. Note that not all value types support mutable values. In this case, the returned builder behaves as ifmutablewasfalse. In particular, the mutable flag is usually only supported for collection types (lists, maps, records). The default isfalse, i.e. the created value is immutable.- Parameters:
mutable- Whether the created value should be mutable.- Returns:
- This configurator for method chaining.
-