Class PercentType

java.lang.Object
dev.jcputney.elearning.parser.input.common.PercentType
All Implemented Interfaces:
Serializable

public final class PercentType extends Object implements Serializable
Represents a percentage value constrained between 0 and 1 (inclusive). It is designed for use cases where percentages are represented as decimal values.

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 Details

    • PercentType

      public PercentType()
      Default constructor for the PercentType class.
    • PercentType

      public PercentType(BigDecimal value)
      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

      public static PercentType parse(String value)
      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

      public String toString()
      Returns the string representation of the percentage value.
      Overrides:
      toString in class Object
      Returns:
      the string representation of the percentage value.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • value

      public BigDecimal value()
      Retrieves the value of the percentage as a BigDecimal.
      Returns:
      the decimal representation of the percentage value.