public interface PropertyBox extends PropertySet<Property>
Property values, provinding methods to get and set property values,
performing value validation and conversions according to property configurations.
The set of the properties managed by a PropertyBox is well defined through the PropertySet abstraction.
If the PropertySet to which the PropertyBox is bound provides a set of identifier
properties, the identifier property values are used by default to check PropertyBox objects equality and to
provide the object hash code. The default builder allows to provide a custom equals/hashCode logic using suitable
EqualsHandler and HashCodeProvider functions. See PropertyBox.Builder.equalsHandler(EqualsHandler) and
PropertyBox.Builder.hashCodeProvider(HashCodeProvider) methods for further details.
By default, property value validation is enabled, and when a property value is setted in the PropertyBox
using setValue(Property, Object) any property validator is invoked, throwing a Validator.ValidationException
if the value is not valid. Property value validation can be controlled using the setInvalidAllowed(boolean)
method. Property value validation can always be manually triggered using the validate() method.
PropertySet,
PropertySet.getIdentifiers()| Modifier and Type | Interface and Description |
|---|---|
static interface |
PropertyBox.Builder
Builder to build
PropertyBox instances. |
static interface |
PropertyBox.PropertyValue<T>
Represents a
Property value. |
CONTEXT_KEY, PROPERTY_CONFIGURATION_ATTRIBUTE| Modifier and Type | Method and Description |
|---|---|
static <P extends Property> |
builder(Iterable<P> properties)
Builder to create and populate a PropertyBox.
|
static <P extends Property> |
builder(P... properties)
Builder to create and populate a PropertyBox.
|
default PropertyBox |
cloneBox()
Clone this PropertyBox, i.e. create a new PropertyBox with same property set of this box and copy all the
property values from this box to the newly created box.
|
default PropertyBox |
cloneBox(Property<?>... propertySet)
Clone this PropertyBox using given
propertySet, i.e. create a new PropertyBox and copy all given set
property values from this box to the newly created box. |
default <P extends Property> |
cloneBox(PropertySet<P> propertySet)
Clone this PropertyBox using given
propertySet, i.e. create a new PropertyBox and copy all given set
property values from this box to the newly created box. |
<T> boolean |
containsValue(Property<T> property)
Check if this box contains given
property with a not null value. |
static <P extends Property> |
create(Iterable<P> properties)
Shorter method to create a PropertyBox with given
properties set. |
static <P extends Property> |
create(P... properties)
Shorter method to create a PropertyBox with given
properties set. |
<T> T |
getValue(Property<T> property)
Get the value for given
property. |
<T> Optional<T> |
getValueIfPresent(Property<T> property)
Get the value for given
property, if property is present in this box and has a not null
value. |
boolean |
isInvalidAllowed()
Gets whether to accept invalid property values when using
setValue(Property, Object) to set a property
value, i.e. ignores any Validator registered for property. |
default <T> String |
present(Property<T> property)
Present given
property value, obtained from this PropertyBox, as a String, using current
PropertyValuePresenterRegistry if available as Context resource to obtain a suitable
PropertyValuePresenter, or default presenter PropertyValuePresenterRegistry.getDefault()
otherwise. |
<T> Stream<PropertyBox.PropertyValue<T>> |
propertyValues()
Get the
Stream of all the Propertys of the property set bound to this PropertyBox and
their values, using the PropertyBox.PropertyValue representation. |
void |
setInvalidAllowed(boolean invalidAllowed)
Set whether to accept invalid property values when using
setValue(Property, Object) to set a property
value, i.e. to ignore any Validator registered for property. |
<T> void |
setValue(Property<T> property,
T value)
Set the value of given
property. |
void |
validate()
Checks the validity of the value of each property in the box against every registered property validator, if any.
|
asList, builder, builder, builderOf, contains, execute, getConfiguration, getFirstIdentifier, getIdentifiers, identifiers, join, of, of, of, size, streamforEach, iterator, spliteratorhasConfiguration<T> boolean containsValue(Property<T> property)
property with a not null value.T - Property typeproperty - Property to check (not null)true if box contains given property and the property value is not null<T> T getValue(Property<T> property)
property.T - Property and value typeproperty - Property for which obtain the value (not null)null if no value is associated to given propertyProperty.PropertyNotFoundException - If property is not present in the box property setProperty.PropertyAccessException - If an error occurred reading the property value<T> Optional<T> getValueIfPresent(Property<T> property)
property, if property is present in this box and has a not null
value.
Unlike getValue(Property), this method does not throw a Property.PropertyNotFoundException when the
specified property is not part of this box property set, an empty Optional is returned instead. An empty Optional
is returned also when the property is present but has no value.
T - Property and value typeproperty - Property for which obtain the value (not null)Property.PropertyAccessException - If an error occurred reading the property value<T> Stream<PropertyBox.PropertyValue<T>> propertyValues()
Stream of all the Propertys of the property set bound to this PropertyBox and
their values, using the PropertyBox.PropertyValue representation.
All the properties will be part of the stream, even the ones without a value. If a property has not a value in
this PropertyBox, null will be returned by PropertyBox.PropertyValue.getValue().
T - Property and value typePropertyBox.PropertyValue stream with all the property values<T> void setValue(Property<T> property, T value)
property.T - Property and value typeproperty - Property for which to set the value (not null)value - Value to setProperty.PropertyNotFoundException - If property is not present in the box property setProperty.PropertyAccessException - If an error occurred setting the property valueProperty.PropertyReadOnlyException - If the property is read-onlyValidator.ValidationException - If not isInvalidAllowed() and property is Validator.Validatable and validation
against given value was not successfulboolean isInvalidAllowed()
setValue(Property, Object) to set a property
value, i.e. ignores any Validator registered for property. If invalid values are not allowed and any
property Validator do not validate the value, a Validator.ValidationException is thrown by
setValue(Property, Object).
Default value is false.
true if accept invalid property values (ignore validators), false otherwisevoid setInvalidAllowed(boolean invalidAllowed)
setValue(Property, Object) to set a property
value, i.e. to ignore any Validator registered for property. If invalid values are not allowed and any
property Validator do not validate the value, a Validator.ValidationException is thrown by
setValue(Property, Object).invalidAllowed - true to accept invalid property values (ignore validators), false
otherwisevoid validate()
throws Validator.ValidationException
Validator.ValidationException is thrown.Validator.ValidationException - One or more property value is not validdefault PropertyBox cloneBox()
default <P extends Property> PropertyBox cloneBox(PropertySet<P> propertySet)
propertySet, i.e. create a new PropertyBox and copy all given set
property values from this box to the newly created box.P - Actual property typepropertySet - Property set of the cloned PropertyBox (not null)default PropertyBox cloneBox(Property<?>... propertySet)
propertySet, i.e. create a new PropertyBox and copy all given set
property values from this box to the newly created box.propertySet - Property set of the cloned PropertyBox (not null)default <T> String present(Property<T> property)
property value, obtained from this PropertyBox, as a String, using current
PropertyValuePresenterRegistry if available as Context resource to obtain a suitable
PropertyValuePresenter, or default presenter PropertyValuePresenterRegistry.getDefault()
otherwise.T - Property typeproperty - Property to presentvalueProperty.PropertyNotFoundException - Property is not present in box property setProperty.PropertyAccessException - Failed to read property value (value type is not consistent with property type or
other internal errors)static <P extends Property> PropertyBox create(Iterable<P> properties)
properties set.
If given properties are provided as a PropertySet instance, any property set configuration,
such as identifier properties, is inherited by the PropertyBox property set.
P - Actual property typeproperties - Set of properties of the PropertyBox to createPropertyBox builder@SafeVarargs static <P extends Property> PropertyBox create(P... properties)
properties set.P - Actual property typeproperties - Set of properties of the PropertyBox to createPropertyBox builderstatic <P extends Property> PropertyBox.Builder builder(Iterable<P> properties)
If given properties are provided as a PropertySet instance, any property set configuration,
such as identifier properties, is inherited by the PropertyBox property set.
P - Actual property typeproperties - Set of properties of the PropertyBox to createPropertyBox builder@SafeVarargs static <P extends Property> PropertyBox.Builder builder(P... properties)
P - Actual property typeproperties - Set of properties of the PropertyBox to createPropertyBox builderCopyright © 2019 The Holon Platform. All rights reserved.