Class RangeAttribute<T extends Number & Comparable<T>>
- Type Parameters:
T- the type of the attribute value, which must be a Number and Comparable
- All Implemented Interfaces:
IAttribute<T>, Serializable
Represents an attribute with a defined range, extending the base Attribute class. The attribute value is constrained between a minimum and maximum value.
This class is XML-serializable via JAXB. The base value, min and max are persisted as XML attributes; modifiers and property change support are runtime-only state and are not serialized.
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionRangeAttribute(T min, T max) Constructs a newRangeAttributewith the specified minimum and maximum values, usingminas the initial base value.RangeAttribute(T initialValue, T min, T max) Constructs a new RangeAttribute with the specified initial value, minimum value, and maximum value. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMaxListener(PropertyChangeListener listener) Adds a PropertyChangeListener for the maximum value.voidaddMaxModifier(AttributeModifier<T> modifier) Adds a modifier to the list of maximum value modifiers and notifies listeners of the change.voidaddMinListener(PropertyChangeListener listener) Adds a PropertyChangeListener for the minimum value.voidaddMinModifier(AttributeModifier<T> modifier) Adds a modifier to the list of minimum value modifiers and notifies listeners of the change.getMax()Gets the base maximum value of the attribute.Gets the list of maximum value modifiers.getMin()Gets the base minimum value of the attribute.Gets the list of minimum value modifiers.Computes the modified maximum value by applying all active modifiers to the base maximum value.Computes the modified minimum value by applying all active modifiers to the base minimum value.Gets the current value of the attribute, ensuring it is within the defined range.Returns a uniformly distributed pseudo-random number between this attribute's modified minimum and modified maximum values.floatgetRatio()Gets the ratio of the current value to the maximum value as a float.getValue()Gets the base value of the attribute.voidremoveMaxListener(PropertyChangeListener listener) Removes a PropertyChangeListener for the maximum value.voidremoveMaxModifier(AttributeModifier<T> modifier) Removes a modifier from the list of maximum value modifiers and notifies listeners of the change.voidremoveMinListener(PropertyChangeListener listener) Removes a PropertyChangeListener for the minimum value.voidremoveMinModifier(AttributeModifier<T> modifier) Removes a modifier from the list of minimum value modifiers and notifies listeners of the change.voidSets the maximum value of the attribute and notifies listeners of the change.voidSets the minimum value of the attribute and notifies listeners of the change.voidSets the base value of the attribute and fires a property change event.Methods inherited from class Attribute
addListener, addModifier, getModifiers, modify, modify, removeListener, removeModifier, toString
-
Constructor Details
-
RangeAttribute
public RangeAttribute() -
RangeAttribute
Constructs a new RangeAttribute with the specified initial value, minimum value, and maximum value. Ensures that the minimum value is not greater than the maximum value.- Parameters:
initialValue- the initial value of the attributemin- the minimum value of the attributemax- the maximum value of the attribute- Throws:
IllegalArgumentException- if the minimum value is greater than the maximum value
-
RangeAttribute
Constructs a newRangeAttributewith the specified minimum and maximum values, usingminas the initial base value.- Parameters:
min- the minimum value of the attributemax- the maximum value of the attribute- Throws:
IllegalArgumentException- if the minimum value is greater than the maximum value
-
-
Method Details
-
getModifiedValue
Gets the current value of the attribute, ensuring it is within the defined range.- Specified by:
getModifiedValuein interfaceIAttribute<T extends Number & Comparable<T>>- Overrides:
getModifiedValuein classAttribute<T extends Number & Comparable<T>>- Returns:
- the current value of the attribute
-
getValue
Gets the base value of the attribute.
The base value is intentionally not serialized for a
RangeAttribute. Range attributes describe a value range via min and max (for example particle emitter parameters); persisting a single base value alongside the range is not meaningful, since consumers such as the particle system always draw a fresh random sample betweenminandmax(seegetRandomNumber()). Suppression of the inheritedvalueXML attribute is implemented via the JAXBbeforeMarshal/afterMarshalcallbacks below.- Specified by:
getValuein interfaceIAttribute<T extends Number & Comparable<T>>- Overrides:
getValuein classAttribute<T extends Number & Comparable<T>>- Returns:
- the base value of the attribute
-
getMin
Gets the base minimum value of the attribute.- Returns:
- the minimum value of the attribute
-
getModifiedMin
Computes the modified minimum value by applying all active modifiers to the base minimum value.- Returns:
- the computed modified minimum value
-
setMin
Sets the minimum value of the attribute and notifies listeners of the change.- Parameters:
min- the new minimum value
-
getMax
Gets the base maximum value of the attribute.- Returns:
- the maximum value of the attribute
-
getModifiedMax
Computes the modified maximum value by applying all active modifiers to the base maximum value.- Returns:
- the computed modified maximum value
-
setMax
Sets the maximum value of the attribute and notifies listeners of the change.- Parameters:
max- the new maximum value
-
addMinListener
Adds a PropertyChangeListener for the minimum value.- Parameters:
listener- the listener to be added
-
removeMinListener
Removes a PropertyChangeListener for the minimum value.- Parameters:
listener- the listener to be removed
-
addMaxListener
Adds a PropertyChangeListener for the maximum value.- Parameters:
listener- the listener to be added
-
removeMaxListener
Removes a PropertyChangeListener for the maximum value.- Parameters:
listener- the listener to be removed
-
getMinModifiers
Gets the list of minimum value modifiers.- Returns:
- the list of minimum value modifiers
-
getMaxModifiers
Gets the list of maximum value modifiers.- Returns:
- the list of maximum value modifiers
-
addMinModifier
Adds a modifier to the list of minimum value modifiers and notifies listeners of the change.- Parameters:
modifier- the modifier to add
-
removeMinModifier
Removes a modifier from the list of minimum value modifiers and notifies listeners of the change.- Parameters:
modifier- the modifier to remove
-
addMaxModifier
Adds a modifier to the list of maximum value modifiers and notifies listeners of the change.- Parameters:
modifier- the modifier to add
-
removeMaxModifier
Removes a modifier from the list of maximum value modifiers and notifies listeners of the change.- Parameters:
modifier- the modifier to remove
-
getRatio
public float getRatio()Gets the ratio of the current value to the maximum value as a float. This is calculated as the current value divided by the maximum value.- Returns:
- The ratio of the current value to the maximum value.
-
getRandomNumber
Returns a uniformly distributed pseudo-random number between this attribute's modified minimum and modified maximum values.
This is intended for use-cases that need to draw a random sample from a configured range (e.g. particle parameters used by an emitter). If
modifiedMin >= modifiedMax, the modified minimum is returned.- Returns:
- a
NumberbetweengetModifiedMin()(inclusive) andgetModifiedMax()(exclusive), orgetModifiedMin()if the range is empty
-
setValue
Description copied from class:AttributeSets the base value of the attribute and fires a property change event.- Specified by:
setValuein interfaceIAttribute<T extends Number & Comparable<T>>- Overrides:
setValuein classAttribute<T extends Number & Comparable<T>>- Parameters:
newValue- the new base value of the attribute
-