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 theProperty
to build.B
- type of thevalidator builder
forwithValidator()
.SELF
- type of thisPropertyBuilder
itself.
- 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 aBuilder
to create instances of a particular type ofProperty
.
As aProperty
typically has only one single required parameter that is also the most specific parameter, it is provided to thebuild-method
. ThereforeProcessBuilder
does not implementBuilder
and does not follow the default builder-pattern providing a non-argbuild()
method.
For a specificProperty
type the builder should carry the same name with the suffixBuilder
. Example:BooleanProperty
is build byBooleanPropertyBuilder
.- Since:
- 1.0.0
-
-
Field Summary
Fields Modifier and Type Field Description protected Supplier<? extends V>
expression
protected V
value
-
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()
P
build(String name)
protected P
build(String name, boolean ignoreExtensions)
protected abstract P
build(String name, PropertyMetadata<V> newMetadata)
protected <T extends PropertyBuilder<?,?,?,?>>
Tbuilder(T builder)
protected abstract B
createValidatorBuilder()
SELF
factory(Function<String,P> function)
SELF
metadata(String metadataKey, Object metadataValue)
SELF
metadataFactory(PropertyMetadataFactory propertyMetadataFactory)
SELF
registry(Consumer<? super P> consumer)
protected SELF
self()
SELF
value(V initialValue)
SELF
valueExpression(Supplier<? extends V> propertyValueExpression)
B
withValidator()
-
-
-
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
- theFunction
optionallyproviding
theProperty
tobuild
. If it returns a result other thannull
this 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
- thePropertyMetadataFactory
used tocreate
instances 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 value
of theProperty
to 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
ObjectValidatorBuilder
corresponding to this type of builder.
-
withValidator
public B withValidator()
-
build
public final P build(String name)
- Parameters:
name
- theproperty name
of theProperty
to build.- Returns:
- the
Property
to build.
-
build
protected final P build(String name, boolean ignoreExtensions)
- Parameters:
name
- theproperty name
of theProperty
to build.ignoreExtensions
- -true
to ignore a potentialregistry(Consumer)
andfactory(Function)
,false
otherwise.- Returns:
- the
Property
to build.
-
build
protected abstract P build(String name, PropertyMetadata<V> newMetadata)
- Parameters:
name
- theproperty name
of theProperty
to build.newMetadata
- thePropertyMetadata
.- Returns:
- the
Property
tobuild
.
-
asList
public ListPropertyBuilder<V> asList()
- Returns:
- a
ListPropertyBuilder
usingthis property configuration
for its elements.
-
asSet
public SetPropertyBuilder<V> asSet()
- Returns:
- a
SetPropertyBuilder
usingthis property configuration
for its elements.
-
asMap
public MapPropertyBuilder<String,V> asMap()
- Returns:
- a
MapPropertyBuilder
usingthis property configuration
for its values andString
as 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
MapPropertyBuilder
usingthis property configuration
for its values andString
as keys.
-
-