Class PropertyContainer
- All Implemented Interfaces:
Iterable<PropertyValuePair<?>>, IPropertyContainerConst, IPropertyHolder, IPropertyHolderConst
New instances of this class can be created using forType(StructureType).
A property container is created for a specific structure type. It contains all properties that are defined for that
type as defined by StructureType.getProperties().
It is not possible to set a property that is not defined for the structure type this property container was created
for. Attempting to do so will result in an IllegalArgumentException.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(IPropertyContainerConst propertyContainer) Adds all properties from the given property container to this property container.booleancanRemoveProperty(Property<?> property) Checks if a property can be removed from this property holder.booleanstatic PropertyContainerforProperties(List<Property<?>> properties, boolean required) Creates a new property container for the given properties.static PropertyContainerforType(StructureType structureType) Creates a new property container for the given structure type.<T> IPropertyValue<T> getPropertyValue(Property<T> property) Gets the value of the given property.inthashCode()booleanhasProperties(Collection<Property<?>> properties) Checks if this property holder has all the given properties.booleanhasProperty(Property<?> property) Checks if the given property has a value set.iterator()Returns a read-only iterator over the properties in this container.static PropertyContainerof(IPropertyContainerConst other) Creates a copy of the given property container.static <A> PropertyContainerType-safe version ofofAll(Object...)for 1 property.static <A,B> PropertyContainer of(Property<A> property0, A value0, boolean required0, Property<B> property1, B value1, boolean required1) Type-safe version ofofAll(Object...)for 2 properties.static <A,B, C> PropertyContainer of(Property<A> property0, A value0, boolean required0, Property<B> property1, B value1, boolean required1, Property<C> property2, C value2, boolean required2) Type-safe version ofofAll(Object...)for 3 properties.static <A,B, C, D> PropertyContainer of(Property<A> property0, A value0, boolean required0, Property<B> property1, B value1, boolean required1, Property<C> property2, C value2, boolean required2, Property<D> property3, D value3, boolean required3) Type-safe version ofofAll(Object...)for 4 properties.static <A,B, C, D, E>
PropertyContainerof(Property<A> property0, A value0, boolean required0, Property<B> property1, B value1, boolean required1, Property<C> property2, C value2, boolean required2, Property<D> property3, D value3, boolean required3, Property<E> property4, E value4, boolean required4) Type-safe version ofofAll(Object...)for 5 properties.static PropertyContainerCreates a newPropertyContainerfrom the given properties.intGets the number of properties in this property container.<T> IPropertyValue<T> removeProperty(Property<T> property) Removes the given property from this property container.<T> IPropertyValue<T> setPropertyValue(Property<T> property, @Nullable T value) Sets the value of the given property.<T> IPropertyValue<?> setUntypedPropertyValue(Property<T> property, @Nullable Object value) Sets the value of the given property without type checking.snapshot()Creates a new snapshot of this property container.Returns a read-only spliterator over the properties in this container.@NonNull StringtoString()Methods inherited from interface IPropertyContainerConst
streamMethods inherited from interface IPropertyHolderConst
getRequiredPropertyValue, hasProperties, hasProperties
-
Constructor Details
-
PropertyContainer
public PropertyContainer()Creates a new empty property container.It is generally recommended to use
forType(StructureType)instead to create a property container with the default properties for a specific structure type. This ensures that the required properties for that structure type are correctly marked as required and have their default values set.
-
-
Method Details
-
of
Creates a copy of the given property container.- Parameters:
other- The property container to copy.- Returns:
- A new property container with the same properties as the given property container.
-
setPropertyValue
Description copied from interface:IPropertyHolderSets the value of the given property.- Specified by:
setPropertyValuein interfaceIPropertyHolder- Type Parameters:
T- The type of the property.- Parameters:
property- The property to set the value for.value- The value to set.If this is
null, the property will be removed.- Returns:
- The previous value of the property, or
nullif the property had no value set.
-
removeProperty
Description copied from interface:IPropertyHolderRemoves the given property from this property container.Properties cannot be removed under certain conditions. When in doubt, check
IPropertyHolder.canRemoveProperty(Property).- Specified by:
removePropertyin interfaceIPropertyHolder- Type Parameters:
T- The type of the property.- Parameters:
property- The property to remove.- Returns:
- The previous value of the property, or
PropertyContainer.UnsetPropertyValue.INSTANCEif the property was not set.
-
setUntypedPropertyValue
Sets the value of the given property without type checking.If possible, consider using
setPropertyValue(Property, Object)instead for better type safety.- Parameters:
property- The property to set the value for.value- The value to set.- Returns:
- The previous value of the property, or
PropertyContainer.UnsetPropertyValue.INSTANCEif the property was not set. - Throws:
ClassCastException- If the value cannot be cast to the type of the property.
-
getPropertyValue
Description copied from interface:IPropertyHolderConstGets the value of the given property.- Specified by:
getPropertyValuein interfaceIPropertyHolderConst- Type Parameters:
T- The type of the property.- Parameters:
property- The property to get the value of.- Returns:
- The value of the property.
-
hasProperty
Description copied from interface:IPropertyHolderConstChecks if the given property has a value set.- Specified by:
hasPropertyin interfaceIPropertyHolderConst- Parameters:
property- The property to check.- Returns:
trueif the property has a value set,falseotherwise.
-
hasProperties
Description copied from interface:IPropertyHolderConstChecks if this property holder has all the given properties.- Specified by:
hasPropertiesin interfaceIPropertyHolderConst- Parameters:
properties- The properties to check.- Returns:
trueif this property holder has all the given properties,falseotherwise.
-
canRemoveProperty
Description copied from interface:IPropertyHolderChecks if a property can be removed from this property holder.A property can not be removed under the following conditions:
-
The property is required (e.g. defined by
StructureType.getProperties()). - The property does not exist in this property holder.
- Specified by:
canRemovePropertyin interfaceIPropertyHolder- Parameters:
property- The property to check.- Returns:
trueif the property can be removed from this property holder,falseotherwise.
-
The property is required (e.g. defined by
-
snapshot
Creates a new snapshot of this property container.- Returns:
- A new snapshot of this property container.
-
forType
Creates a new property container for the given structure type.- Parameters:
structureType- The structure type to create the property container for.- Returns:
- A new property container for the given structure type.
-
forProperties
@VisibleForTesting public static PropertyContainer forProperties(List<Property<?>> properties, boolean required) Creates a new property container for the given properties.This method is intended for testing purposes only.
For production code, use
forType(StructureType)instead.- Parameters:
properties- The properties to create the property container for.required- Whether the properties are required.- Returns:
- A new property container for the given properties.
-
iterator
Description copied from interface:IPropertyContainerConstReturns a read-only iterator over the properties in this container.Any properties that are either unmapped or of the wrong type are excluded.
- Specified by:
iteratorin interfaceIPropertyContainerConst- Specified by:
iteratorin interfaceIterable<PropertyValuePair<?>>- Returns:
- A read-only iterator over the properties in this container.
-
spliterator
Description copied from interface:IPropertyContainerConstReturns a read-only spliterator over the properties in this container.Any properties that are either unmapped or of the wrong type are excluded.
- Specified by:
spliteratorin interfaceIPropertyContainerConst- Specified by:
spliteratorin interfaceIterable<PropertyValuePair<?>>- Returns:
- A read-only spliterator over the properties in this container.
-
addAll
Adds all properties from the given property container to this property container.Existing properties will be overwritten.
A property will be marked as required only if it is already required in this property container.
- Parameters:
propertyContainer- The property container to add the properties from.
-
propertyCount
public int propertyCount()Description copied from interface:IPropertyHolderConstGets the number of properties in this property container.This is the number of entries in the property map.
- Specified by:
propertyCountin interfaceIPropertyHolderConst- Returns:
- The number of properties in this property container.
-
ofAll
Creates a newPropertyContainerfrom the given properties.- Parameters:
properties- A group of interleaved property-value-isRequired triplets.- Returns:
- A new
PropertyContainerwith the given properties. - Throws:
IllegalArgumentException- If the properties are not provided in pairs of 3.If an object at an even index is not a
Property.NullPointerException- If any value isnull.ClassCastException- If the value of a property cannot be cast to the type of the preceding property usingProperty.cast(Object).
-
of
Type-safe version ofofAll(Object...)for 1 property. -
of
public static <A,B> PropertyContainer of(Property<A> property0, A value0, boolean required0, Property<B> property1, B value1, boolean required1) Type-safe version ofofAll(Object...)for 2 properties. -
of
public static <A,B, PropertyContainer ofC> (Property<A> property0, A value0, boolean required0, Property<B> property1, B value1, boolean required1, Property<C> property2, C value2, boolean required2) Type-safe version ofofAll(Object...)for 3 properties. -
of
public static <A,B, PropertyContainer ofC, D> (Property<A> property0, A value0, boolean required0, Property<B> property1, B value1, boolean required1, Property<C> property2, C value2, boolean required2, Property<D> property3, D value3, boolean required3) Type-safe version ofofAll(Object...)for 4 properties. -
of
public static <A,B, PropertyContainer ofC, D, E> (Property<A> property0, A value0, boolean required0, Property<B> property1, B value1, boolean required1, Property<C> property2, C value2, boolean required2, Property<D> property3, D value3, boolean required3, Property<E> property4, E value4, boolean required4) Type-safe version ofofAll(Object...)for 5 properties. -
toString
-
equals
-
hashCode
-