Class Attribute<T extends Number>

Type Parameters:
T - the type of the attribute value, which must be a Number
All Implemented Interfaces:
IAttribute<T>, Serializable
Direct Known Subclasses:
RangeAttribute

public class Attribute<T extends Number> extends Object implements IAttribute<T>, Serializable

Represents an attribute with a base value and a list of modifiers. The attribute value can be modified by adding or removing modifiers.

This class is XML-serializable via JAXB. The base value is written as an XML attribute named value; runtime-only data (such as registered modifiers and property change support) is marked transient and is not part of the serialized form.

See Also:
  • Field Details

    • support

      protected final transient PropertyChangeSupport support
      The support object used to manage and notify property change listeners. It allows other components to listen for changes to the properties of this object.
    • value

      protected T extends Number value

      The base value of the attribute. This value represents the unmodified state of the attribute before any modifiers are applied. It is serialized as the value XML attribute.

      Subclasses such as RangeAttribute that do not want to persist a base value can suppress serialization at runtime via JAXB beforeMarshal / afterMarshal callbacks.

  • Constructor Details

    • Attribute

      public Attribute()
      Default no-argument constructor.
    • Attribute

      public Attribute(T initialValue)
      Constructs a new Attribute with the specified initial value.
      Parameters:
      initialValue - the initial value of the attribute
  • Method Details

    • getValue

      public T getValue()
      Gets the base value of the attribute.
      Specified by:
      getValue in interface IAttribute<T extends Number>
      Returns:
      the base value of the attribute
    • getModifiedValue

      public T getModifiedValue()
      Gets the current value of the attribute, computed by applying all active modifications to the base value.
      Specified by:
      getModifiedValue in interface IAttribute<T extends Number>
      Returns:
      the current value
    • setValue

      public void setValue(T newValue)
      Sets the base value of the attribute and fires a property change event.
      Specified by:
      setValue in interface IAttribute<T extends Number>
      Parameters:
      newValue - the new base value of the attribute
    • addListener

      public void addListener(PropertyChangeListener listener)
      Adds a property change listener to the attribute.
      Specified by:
      addListener in interface IAttribute<T extends Number>
      Parameters:
      listener - the property change listener to be added
    • removeListener

      public void removeListener(PropertyChangeListener listener)
      Removes a property change listener from the attribute.
      Specified by:
      removeListener in interface IAttribute<T extends Number>
      Parameters:
      listener - the property change listener to be removed
    • addModifier

      public void addModifier(AttributeModifier<T> modifier)
      Adds a modifier to the attribute and fires a property change event. If the modifier is already present, it will not be added again.
      Specified by:
      addModifier in interface IAttribute<T extends Number>
      Parameters:
      modifier - the property modifier to be added
    • removeModifier

      public void removeModifier(AttributeModifier<T> modifier)
      Removes a modifier from the attribute and fires a property change event. If the modifier is not present, no action is taken.
      Specified by:
      removeModifier in interface IAttribute<T extends Number>
      Parameters:
      modifier - the property modifier to be removed
    • getModifiers

      public List<AttributeModifier<T>> getModifiers()
      Gets the list of all property modifiers applied to the attribute.
      Returns:
      the list of property modifiers
    • modify

      public void modify(AttributeModifier<T> modifier)
      Modifies the current value of the attribute using the specified property modifier.
      Specified by:
      modify in interface IAttribute<T extends Number>
      Parameters:
      modifier - the property modifier to apply
    • modify

      public void modify(Modification modification, double value)
      Modifies the current value of the attribute using a new property modifier created with the specified modification and value.
      Specified by:
      modify in interface IAttribute<T extends Number>
      Parameters:
      modification - the type of modification to apply
      value - the value to use for the modification
    • toString

      public String toString()
      Returns a string representation of the current value of the attribute.
      Overrides:
      toString in class Object
      Returns:
      the string representation of the current value