Record Class NaftahPeriod

java.lang.Object
java.lang.Record
org.daiitech.naftah.builtin.time.NaftahPeriod
Record Components:
periodDefinition - the definition of the period in Arabic text
temporalAmount - the actual period value
All Implemented Interfaces:
NaftahTemporal, NaftahTemporalAmount

public record NaftahPeriod(NaftahPeriod.PeriodDefinition periodDefinition, Period temporalAmount) extends Record implements NaftahTemporalAmount
Represents a period expressed in Arabic text, including years, months, and days.

This class wraps a NaftahPeriod.PeriodDefinition for Arabic formatting and a Period for the actual temporal amount.

Author:
Chakib Daii
  • Field Details

  • Constructor Details

  • Method Details

    • of

      public static NaftahPeriod of(NaftahPeriod.PeriodDefinition periodDefinition, Period temporalAmount)
      Creates a new NaftahPeriod instance using the provided Arabic period definition and the underlying Period.
      Parameters:
      periodDefinition - the Arabic textual definition describing the period (years, months, and days)
      temporalAmount - the underlying Period representing the actual date-based amount
      Returns:
      a new NaftahPeriod instance
    • of

      public static NaftahPeriod of(Period period)
      Creates a new NaftahPeriod instance from a Period.

      The period is decomposed into its date-based components (years, months, and days) to build the corresponding Arabic textual representation.

      Parameters:
      period - the Period to convert into an NaftahPeriod
      Returns:
      a new NaftahPeriod instance representing the given period
    • ofZero

      public static NaftahPeriod ofZero()
      Returns an NaftahPeriod representing a zero period.

      The returned period has all components set to zero: years, months, and days.

      Returns:
      an NaftahPeriod representing a period of zero
    • ofYears

      public static NaftahPeriod ofYears(int years)
      Obtains a ArabicPeriod representing a number of years.

      The resulting period will have the specified years. The months and days units will be zero.

      Parameters:
      years - the number of years, positive or negative
      Returns:
      the period of years, not null
    • ofMonths

      public static NaftahPeriod ofMonths(int months)
      Obtains a ArabicPeriod representing a number of months.

      The resulting period will have the specified months. The years and days units will be zero.

      Parameters:
      months - the number of months, positive or negative
      Returns:
      the period of months, not null
    • ofWeeks

      public static NaftahPeriod ofWeeks(int weeks)
      Obtains a ArabicPeriod representing a number of weeks.

      The resulting period will be day-based, with the amount of days equal to the number of weeks multiplied by 7. The years and months units will be zero.

      Parameters:
      weeks - the number of weeks, positive or negative
      Returns:
      the period, with the input weeks converted to days, not null
    • ofDays

      public static NaftahPeriod ofDays(int days)
      Obtains a ArabicPeriod representing a number of days.

      The resulting period will have the specified days. The years and months units will be zero.

      Parameters:
      days - the number of days, positive or negative
      Returns:
      the period of days, not null
    • getYears

      public int getYears()
      Returns the number of years in this period.
      Returns:
      the years component of the period
    • getMonths

      public int getMonths()
      Returns the number of months in this period.
      Returns:
      the months component of the period
    • getDays

      public int getDays()
      Returns the number of days in this period.
      Returns:
      the days component of the period
    • plus

      public NaftahPeriod plus(NaftahTemporalAmount other)
      Returns a new ArabicPeriod obtained by adding the given Arabic temporal amount to this period.

      Addition is supported only when the other amount is also an ArabicPeriod.

      Specified by:
      plus in interface NaftahTemporalAmount
      Parameters:
      other - the temporal amount to add
      Returns:
      a new ArabicPeriod instance
    • plusYears

      public NaftahPeriod plusYears(long yearsToAdd)
      Returns a copy of this period with the specified years added.

      This adds the amount to the years unit in a copy of this period. The months and days units are unaffected. For example, "1 year, 6 months and 3 days" plus 2 years returns "3 years, 6 months and 3 days".

      This instance is immutable and unaffected by this method call.

      Parameters:
      yearsToAdd - the years to add, positive or negative
      Returns:
      a ArabicPeriod based on this period with the specified years added, not null
      Throws:
      ArithmeticException - if numeric overflow occurs
    • plusMonths

      public NaftahPeriod plusMonths(long monthsToAdd)
      Returns a copy of this period with the specified months added.

      This adds the amount to the months unit in a copy of this period. The years and days units are unaffected. For example, "1 year, 6 months and 3 days" plus 2 months returns "1 year, 8 months and 3 days".

      This instance is immutable and unaffected by this method call.

      Parameters:
      monthsToAdd - the months to add, positive or negative
      Returns:
      a ArabicPeriod based on this period with the specified months added, not null
      Throws:
      ArithmeticException - if numeric overflow occurs
    • plusDays

      public NaftahPeriod plusDays(long daysToAdd)
      Returns a copy of this period with the specified days added.

      This adds the amount to the days unit in a copy of this period. The years and months units are unaffected. For example, "1 year, 6 months and 3 days" plus 2 days returns "1 year, 6 months and 5 days".

      This instance is immutable and unaffected by this method call.

      Parameters:
      daysToAdd - the days to add, positive or negative
      Returns:
      a ArabicPeriod based on this period with the specified days added, not null
      Throws:
      ArithmeticException - if numeric overflow occurs
    • minus

      public NaftahPeriod minus(NaftahTemporalAmount other)
      Returns a new ArabicPeriod obtained by subtracting the given Arabic temporal amount from this period.

      Subtraction is supported only when the other amount is also an ArabicPeriod.

      Specified by:
      minus in interface NaftahTemporalAmount
      Parameters:
      other - the temporal amount to subtract
      Returns:
      a new ArabicPeriod instance
    • minusYears

      public NaftahPeriod minusYears(long yearsToSubtract)
      Returns a copy of this period with the specified years subtracted.

      This subtracts the amount from the years unit in a copy of this period. The months and days units are unaffected. For example, "1 year, 6 months and 3 days" minus 2 years returns "-1 years, 6 months and 3 days".

      This instance is immutable and unaffected by this method call.

      Parameters:
      yearsToSubtract - the years to subtract, positive or negative
      Returns:
      a ArabicPeriod based on this period with the specified years subtracted, not null
      Throws:
      ArithmeticException - if numeric overflow occurs
    • minusMonths

      public NaftahPeriod minusMonths(long monthsToSubtract)
      Returns a copy of this period with the specified months subtracted.

      This subtracts the amount from the months unit in a copy of this period. The years and days units are unaffected. For example, "1 year, 6 months and 3 days" minus 2 months returns "1 year, 4 months and 3 days".

      This instance is immutable and unaffected by this method call.

      Parameters:
      monthsToSubtract - the years to subtract, positive or negative
      Returns:
      a ArabicPeriod based on this period with the specified months subtracted, not null
      Throws:
      ArithmeticException - if numeric overflow occurs
    • minusDays

      public NaftahPeriod minusDays(long daysToSubtract)
      Returns a copy of this period with the specified days subtracted.

      This subtracts the amount from the days unit in a copy of this period. The years and months units are unaffected. For example, "1 year, 6 months and 3 days" minus 2 days returns "1 year, 6 months and 1 day".

      This instance is immutable and unaffected by this method call.

      Parameters:
      daysToSubtract - the months to subtract, positive or negative
      Returns:
      a ArabicPeriod based on this period with the specified days subtracted, not null
      Throws:
      ArithmeticException - if numeric overflow occurs
    • isEquals

      public boolean isEquals(NaftahTemporalAmount other)
      Determines whether this period is equal to the given temporal amount.
      Specified by:
      isEquals in interface NaftahTemporalAmount
      Parameters:
      other - the temporal amount to compare with
      Returns:
      true if the periods are equal; false otherwise
    • notEquals

      public boolean notEquals(NaftahTemporalAmount other)
      Determines whether this period is not equal to the given temporal amount.
      Specified by:
      notEquals in interface NaftahTemporalAmount
      Parameters:
      other - the temporal amount to compare with
      Returns:
      true if the periods are not equal; false otherwise
    • greaterThan

      public boolean greaterThan(NaftahTemporalAmount other)
      Determines whether this period is greater than the given temporal amount.

      Comparison is performed lexicographically: years → months → days.

      Specified by:
      greaterThan in interface NaftahTemporalAmount
      Parameters:
      other - the temporal amount to compare with
      Returns:
      true if this period is greater
    • greaterThanEquals

      public boolean greaterThanEquals(NaftahTemporalAmount other)
      Determines whether this period is greater than or equal to the given temporal amount.
      Specified by:
      greaterThanEquals in interface NaftahTemporalAmount
      Parameters:
      other - the temporal amount to compare with
      Returns:
      true if this period is greater than or equal
    • lessThan

      public boolean lessThan(NaftahTemporalAmount other)
      Determines whether this period is less than the given temporal amount.
      Specified by:
      lessThan in interface NaftahTemporalAmount
      Parameters:
      other - the temporal amount to compare with
      Returns:
      true if this period is less
    • lessThanEquals

      public boolean lessThanEquals(NaftahTemporalAmount other)
      Determines whether this period is less than or equal to the given temporal amount.
      Specified by:
      lessThanEquals in interface NaftahTemporalAmount
      Parameters:
      other - the temporal amount to compare with
      Returns:
      true if this period is less than or equal
    • toString

      public String toString()
      Returns the Arabic textual representation of the period.
      Specified by:
      toString in class Record
      Returns:
      a string describing the period in Arabic
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • periodDefinition

      public NaftahPeriod.PeriodDefinition periodDefinition()
      Returns the value of the periodDefinition record component.
      Returns:
      the value of the periodDefinition record component
    • temporalAmount

      public Period temporalAmount()
      Returns the value of the temporalAmount record component.
      Specified by:
      temporalAmount in interface NaftahTemporalAmount
      Returns:
      the value of the temporalAmount record component