Interface IValueBuilderConfigurator
-
public interface IValueBuilderConfiguratorConfigurator for a set ofIValueBuilderOptions, for use with thebuilderobtained from aIValueDescriptor. Use methods fromValueBuilderOptionsto 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
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description IValueBuilderConfiguratoracceptanceCriteria(IValueAcceptanceCriteria criteria)Sets the acceptance criteria that the created value must satisfy.IValueBuilderOptionscreate()Creates a new value builder with the currently configured options.default IValueBuilderConfiguratorimmutable()Sets that the created value should be immutable.default IValueBuilderConfiguratormutable()Sets that the created value should be mutable.IValueBuilderConfiguratormutable(boolean mutable)Sets whether the created value should be mutable.
-
-
-
Method Detail
-
acceptanceCriteria
IValueBuilderConfigurator acceptanceCriteria(IValueAcceptanceCriteria criteria)
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
default IValueBuilderConfigurator 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
default IValueBuilderConfigurator 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
IValueBuilderConfigurator mutable(boolean 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.
-
-