java.lang.Object
nl.pim16aap2.animatedarchitecture.core.structures.properties.PropertyContainer
All Implemented Interfaces:
Iterable<PropertyValuePair<?>>, IPropertyContainerConst, IPropertyHolder, IPropertyHolderConst

@NotThreadSafe public final class PropertyContainer extends Object implements IPropertyHolder, IPropertyContainerConst
Manages the properties of a structure.

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.

  • Method Details

    • of

      public static PropertyContainer of(IPropertyContainerConst other)
      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

      public <T> IPropertyValue<T> setPropertyValue(Property<T> property, @Nullable T value)
      Sets the value of the given property.
      Specified by:
      setPropertyValue in interface IPropertyHolder
      Type Parameters:
      T - The type of the property.
      Parameters:
      property - The property to set the value for.
      value - The value to set. May be null if the property is nullable.
      Returns:
      The previous value of the property, or null if the property had no value set.
      Throws:
      IllegalArgumentException - If the property is not valid for the structure type this property container was created for.
    • setUntypedPropertyValue

      public <T> IPropertyValue<?> setUntypedPropertyValue(Property<T> property, @Nullable @Nullable Object value)
      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. May be null if the property is nullable.
      Throws:
      ClassCastException - If the value cannot be cast to the type of the property.
    • getPropertyValue

      public <T> IPropertyValue<T> getPropertyValue(Property<T> property)
      Description copied from interface: IPropertyHolderConst
      Gets the value of the given property.
      Specified by:
      getPropertyValue in interface IPropertyHolderConst
      Type Parameters:
      T - The type of the property.
      Parameters:
      property - The property to get the value of.
      Returns:
      The value of the property.
    • hasProperty

      public boolean hasProperty(Property<?> property)
      Description copied from interface: IPropertyHolderConst
      Checks if the given property has a value set.
      Specified by:
      hasProperty in interface IPropertyHolderConst
      Parameters:
      property - The property to check.
      Returns:
      true if the property has a value set, false otherwise.
    • hasProperties

      public boolean hasProperties(Collection<Property<?>> properties)
      Description copied from interface: IPropertyHolderConst
      Checks if this property holder has all the given properties.
      Specified by:
      hasProperties in interface IPropertyHolderConst
      Parameters:
      properties - The properties to check.
      Returns:
      true if this property holder has all the given properties, false otherwise.
    • snapshot

      public PropertyContainerSnapshot snapshot()
      Creates a new snapshot of this property container.
      Returns:
      A new snapshot of this property container.
    • forType

      public static PropertyContainer forType(StructureType structureType)
      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)
      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.
      Returns:
      A new property container for the given properties.
    • iterator

      @NotNull public @NotNull Iterator<PropertyValuePair<?>> iterator()
      Description copied from interface: IPropertyContainerConst
      Returns 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:
      iterator in interface IPropertyContainerConst
      Specified by:
      iterator in interface Iterable<PropertyValuePair<?>>
      Returns:
      A read-only iterator over the properties in this container.
    • spliterator

      public Spliterator<PropertyValuePair<?>> spliterator()
      Description copied from interface: IPropertyContainerConst
      Returns 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:
      spliterator in interface IPropertyContainerConst
      Specified by:
      spliterator in interface Iterable<PropertyValuePair<?>>
      Returns:
      A read-only spliterator over the properties in this container.
    • of

      public static PropertyContainer of(@Nullable @Nullable Object @Nullable ... properties)
      Creates a new PropertyContainer from the given properties.
      Parameters:
      properties - A group of interleaved property-value pairs.

      The even indices must be non-null Propertys.

      The odd indices are the (nullable) values for the properties.

      Returns:
      A new PropertyContainer with the given properties.
      Throws:
      IllegalArgumentException - If the properties are not provided in pairs of 2.

      If an object at an even index is not a Property.

      NullPointerException - If a property is null.
      ClassCastException - If the value of a property cannot be cast to the type of the preceding property using Property.cast(Object).
    • of

      public static <A> PropertyContainer of(Property<A> property0, @Nullable A value0)
      Type-safe version of of(Object...) for 1 property.
    • of

      public static <A, B> PropertyContainer of(Property<A> property0, @Nullable A value0, Property<B> property1, @Nullable B value1)
      Type-safe version of of(Object...) for 2 properties.
    • of

      public static <A, B, C> PropertyContainer of(Property<A> property0, @Nullable A value0, Property<B> property1, @Nullable B value1, Property<C> property2, @Nullable C value2)
      Type-safe version of of(Object...) for 3 properties.
    • of

      public static <A, B, C, D> PropertyContainer of(Property<A> property0, @Nullable A value0, Property<B> property1, @Nullable B value1, Property<C> property2, @Nullable C value2, Property<D> property3, @Nullable D value3)
      Type-safe version of of(Object...) for 4 properties.
    • of

      public static <A, B, C, D, E> PropertyContainer of(Property<A> property0, @Nullable A value0, Property<B> property1, @Nullable B value1, Property<C> property2, @Nullable C value2, Property<D> property3, @Nullable D value3, Property<E> property4, @Nullable E value4)
      Type-safe version of of(Object...) for 5 properties.
    • addAll

      public void addAll(IPropertyContainerConst propertyContainer)
      Adds all properties from the given property container to this property container.

      Existing properties will be overwritten.

      Parameters:
      propertyContainer - The property container to add the properties from.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object