Class PercentType
- All Implemented Interfaces:
Serializable
This class is: - Immutable: Once an instance is created, its value cannot be changed. - Thread-safe: The immutability ensures no synchronization issues during concurrent access. - Validated: Ensures the percentage value lies within the valid range [0, 1] during initialization.
Features and behaviors: - Contains factory and parsing methods for creating instances. - Provides
a string representation of the percentage value. - Overridden equals and hashCode
methods for dictionary lookup or comparison purposes. - Integrated with JSON serialization
frameworks such as Jackson through custom configuration.
The intended use of this class includes scenarios where precise representation and validation of percentages are required, for example in financial, academic, or mathematical applications.
Note: The numeric value does not enforce a specific scale or precision but must lie in the range 0 to 1.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for the PercentType class.PercentType(BigDecimal value) Constructs a PercentType instance with the specified value. -
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()static PercentTypeParses a string as a PercentType.toString()Returns the string representation of the percentage value.value()Retrieves the value of the percentage as a BigDecimal.
-
Constructor Details
-
PercentType
public PercentType()Default constructor for the PercentType class. -
PercentType
Constructs a PercentType instance with the specified value.- Parameters:
value- the decimal value for the percentage must be between 0 and 1.- Throws:
IllegalArgumentException- if the value is out of range.
-
-
Method Details
-
parse
Parses a string as a PercentType.- Parameters:
value- the string representation of the percentage must be a decimal between 0 and 1.- Returns:
- a new PercentType instance.
- Throws:
IllegalArgumentException- if the value is out of range or not a valid decimal format.
-
toString
Returns the string representation of the percentage value. -
equals
-
hashCode
public int hashCode() -
value
Retrieves the value of the percentage as a BigDecimal.- Returns:
- the decimal representation of the percentage value.
-