Package io.github.mmm.property.builder
Class PropertyBuilder<V,P extends Property<V>,B extends ObjectValidatorBuilder<V,? extends PropertyBuilder<V,P,B,SELF>,?>,SELF extends PropertyBuilder<V,P,B,SELF>>
- java.lang.Object
-
- io.github.mmm.property.builder.PropertyBuilder<V,P,B,SELF>
-
- Type Parameters:
V- type of theproperty value.P- type of thePropertyto build.B- type of thevalidator builderforwithValidator().SELF- type of thisPropertyBuilderitself.
- Direct Known Subclasses:
BeanPropertyBuilder,BooleanPropertyBuilder,ComparablePropertyBuilder,IdPropertyBuilder,LinkPropertyBuilder,ListPropertyBuilder,MapPropertyBuilder,RangePropertyBuilder,SetPropertyBuilder
public abstract class PropertyBuilder<V,P extends Property<V>,B extends ObjectValidatorBuilder<V,? extends PropertyBuilder<V,P,B,SELF>,?>,SELF extends PropertyBuilder<V,P,B,SELF>> extends Object
Abstract base class for aBuilderto create instances of a particular type ofProperty.
As aPropertytypically has only one single required parameter that is also the most specific parameter, it is provided to thebuild-method. ThereforeProcessBuilderdoes not implementBuilderand does not follow the default builder-pattern providing a non-argbuild()method.
For a specificPropertytype the builder should carry the same name with the suffixBuilder. Example:BooleanPropertyis build byBooleanPropertyBuilder.- Since:
- 1.0.0
-
-
Field Summary
Fields Modifier and Type Field Description protected Supplier<? extends V>expressionprotected Vvalue
-
Constructor Summary
Constructors Constructor Description PropertyBuilder()The constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description ListPropertyBuilder<V>asList()MapPropertyBuilder<String,V>asMap()<K> MapPropertyBuilder<K,V>asMap(SimpleProperty<K> keyProperty)SetPropertyBuilder<V>asSet()Pbuild(String name)protected Pbuild(String name, boolean ignoreExtensions)protected abstract Pbuild(String name, PropertyMetadata<V> newMetadata)protected <T extends PropertyBuilder<?,?,?,?>>
Tbuilder(T builder)protected abstract BcreateValidatorBuilder()SELFfactory(Function<String,P> function)SELFmetadata(String metadataKey, Object metadataValue)SELFmetadataFactory(PropertyMetadataFactory propertyMetadataFactory)SELFregistry(Consumer<? super P> consumer)protected SELFself()SELFvalue(V initialValue)SELFvalueExpression(Supplier<? extends V> propertyValueExpression)BwithValidator()
-
-
-
Field Detail
-
expression
protected Supplier<? extends V> expression
- See Also:
valueExpression(Supplier)
-
value
protected V value
- See Also:
value(Object)
-
-
Method Detail
-
self
protected SELF self()
- Returns:
- this object itself (
this) for fluent API calls.
-
factory
public SELF factory(Function<String,P> function)
- Parameters:
function- theFunctionoptionallyprovidingthePropertytobuild. If it returns a result other thannullthis will be used instead and the actual building is entirely replaced. This is a very specific feature provided for internal usage (to receive read-only view of already existing property).- Returns:
- this builder itself (
this) for fluent API calls.
-
metadataFactory
public SELF metadataFactory(PropertyMetadataFactory propertyMetadataFactory)
- Parameters:
propertyMetadataFactory- thePropertyMetadataFactoryused tocreateinstances ofPropertyMetadata.- Returns:
- this builder itself (
this) for fluent API calls.
-
valueExpression
public SELF valueExpression(Supplier<? extends V> propertyValueExpression)
- Parameters:
propertyValueExpression- theproperty value expression.- Returns:
- this builder itself (
this) for fluent API calls.
-
value
public SELF value(V initialValue)
- Parameters:
initialValue- theinitial valueof thePropertyto build.- Returns:
- this builder itself (
this) for fluent API calls.
-
metadata
public SELF metadata(String metadataKey, Object metadataValue)
- Parameters:
metadataKey- themetadata key.metadataValue- themetadata value.- Returns:
- this builder itself (
this) for fluent API calls.
-
createValidatorBuilder
protected abstract B createValidatorBuilder()
- Returns:
- the
ObjectValidatorBuildercorresponding to this type of builder.
-
withValidator
public B withValidator()
-
build
public final P build(String name)
- Parameters:
name- theproperty nameof thePropertyto build.- Returns:
- the
Propertyto build.
-
build
protected final P build(String name, boolean ignoreExtensions)
- Parameters:
name- theproperty nameof thePropertyto build.ignoreExtensions- -trueto ignore a potentialregistry(Consumer)andfactory(Function),falseotherwise.- Returns:
- the
Propertyto build.
-
build
protected abstract P build(String name, PropertyMetadata<V> newMetadata)
- Parameters:
name- theproperty nameof thePropertyto build.newMetadata- thePropertyMetadata.- Returns:
- the
Propertytobuild.
-
asList
public ListPropertyBuilder<V> asList()
- Returns:
- a
ListPropertyBuilderusingthis property configurationfor its elements.
-
asSet
public SetPropertyBuilder<V> asSet()
- Returns:
- a
SetPropertyBuilderusingthis property configurationfor its elements.
-
asMap
public MapPropertyBuilder<String,V> asMap()
- Returns:
- a
MapPropertyBuilderusingthis property configurationfor its values andStringas keys.
-
builder
protected <T extends PropertyBuilder<?,?,?,?>> T builder(T builder)
- Type Parameters:
T- type of thePropertyBuilder.- Parameters:
builder- thePropertyBuilder.- Returns:
- the configured
builder.
-
asMap
public <K> MapPropertyBuilder<K,V> asMap(SimpleProperty<K> keyProperty)
- Type Parameters:
K- type of thekeys.- Parameters:
keyProperty- thekey property.- Returns:
- a
MapPropertyBuilderusingthis property configurationfor its values andStringas keys.
-
-