Record Class NaftahPeriod
- Record Components:
periodDefinition- the definition of the period in Arabic texttemporalAmount- the actual period value
- All Implemented Interfaces:
NaftahTemporal,NaftahTemporalAmount
This class wraps a NaftahPeriod.PeriodDefinition for Arabic formatting and a Period
for the actual temporal amount.
- Author:
- Chakib Daii
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordDefinition of a period in Arabic text, including years, months, and days. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final NaftahPeriod.PeriodDefinitionThe field for theperiodDefinitionrecord component.private final PeriodThe field for thetemporalAmountrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionNaftahPeriod(NaftahPeriod.PeriodDefinition periodDefinition, Period temporalAmount) Creates an instance of aNaftahPeriodrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.intgetDays()Returns the number of days in this period.intReturns the number of months in this period.intgetYears()Returns the number of years in this period.booleangreaterThan(NaftahTemporalAmount other) Determines whether this period is greater than the given temporal amount.booleanDetermines whether this period is greater than or equal to the given temporal amount.final inthashCode()Returns a hash code value for this object.booleanisEquals(NaftahTemporalAmount other) Determines whether this period is equal to the given temporal amount.booleanlessThan(NaftahTemporalAmount other) Determines whether this period is less than the given temporal amount.booleanDetermines whether this period is less than or equal to the given temporal amount.minus(NaftahTemporalAmount other) Returns a newArabicPeriodobtained by subtracting the given Arabic temporal amount from this period.minusDays(long daysToSubtract) Returns a copy of this period with the specified days subtracted.minusMonths(long monthsToSubtract) Returns a copy of this period with the specified months subtracted.minusYears(long yearsToSubtract) Returns a copy of this period with the specified years subtracted.booleannotEquals(NaftahTemporalAmount other) Determines whether this period is not equal to the given temporal amount.static NaftahPeriodCreates a newNaftahPeriodinstance from aPeriod.static NaftahPeriodof(NaftahPeriod.PeriodDefinition periodDefinition, Period temporalAmount) Creates a newNaftahPeriodinstance using the provided Arabic period definition and the underlyingPeriod.static NaftahPeriodofDays(int days) Obtains aArabicPeriodrepresenting a number of days.static NaftahPeriodofMonths(int months) Obtains aArabicPeriodrepresenting a number of months.static NaftahPeriodofWeeks(int weeks) Obtains aArabicPeriodrepresenting a number of weeks.static NaftahPeriodofYears(int years) Obtains aArabicPeriodrepresenting a number of years.static NaftahPeriodofZero()Returns anNaftahPeriodrepresenting a zero period.Returns the value of theperiodDefinitionrecord component.plus(NaftahTemporalAmount other) Returns a newArabicPeriodobtained by adding the given Arabic temporal amount to this period.plusDays(long daysToAdd) Returns a copy of this period with the specified days added.plusMonths(long monthsToAdd) Returns a copy of this period with the specified months added.plusYears(long yearsToAdd) Returns a copy of this period with the specified years added.Returns the value of thetemporalAmountrecord component.toString()Returns the Arabic textual representation of the period.
-
Field Details
-
periodDefinition
The field for theperiodDefinitionrecord component. -
temporalAmount
The field for thetemporalAmountrecord component.
-
-
Constructor Details
-
NaftahPeriod
Creates an instance of aNaftahPeriodrecord class.- Parameters:
periodDefinition- the value for theperiodDefinitionrecord componenttemporalAmount- the value for thetemporalAmountrecord component
-
-
Method Details
-
of
public static NaftahPeriod of(NaftahPeriod.PeriodDefinition periodDefinition, Period temporalAmount) Creates a newNaftahPeriodinstance using the provided Arabic period definition and the underlyingPeriod.- Parameters:
periodDefinition- the Arabic textual definition describing the period (years, months, and days)temporalAmount- the underlyingPeriodrepresenting the actual date-based amount- Returns:
- a new
NaftahPeriodinstance
-
of
Creates a newNaftahPeriodinstance from aPeriod.The period is decomposed into its date-based components (years, months, and days) to build the corresponding Arabic textual representation.
- Parameters:
period- thePeriodto convert into anNaftahPeriod- Returns:
- a new
NaftahPeriodinstance representing the given period
-
ofZero
Returns anNaftahPeriodrepresenting a zero period.The returned period has all components set to zero: years, months, and days.
- Returns:
- an
NaftahPeriodrepresenting a period of zero
-
ofYears
Obtains aArabicPeriodrepresenting 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
Obtains aArabicPeriodrepresenting 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
Obtains aArabicPeriodrepresenting 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
Obtains aArabicPeriodrepresenting 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
Returns a newArabicPeriodobtained by adding the given Arabic temporal amount to this period.Addition is supported only when the other amount is also an
ArabicPeriod.- Specified by:
plusin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to add- Returns:
- a new
ArabicPeriodinstance
-
plusYears
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
ArabicPeriodbased on this period with the specified years added, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
plusMonths
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
ArabicPeriodbased on this period with the specified months added, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
plusDays
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
ArabicPeriodbased on this period with the specified days added, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
minus
Returns a newArabicPeriodobtained by subtracting the given Arabic temporal amount from this period.Subtraction is supported only when the other amount is also an
ArabicPeriod.- Specified by:
minusin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to subtract- Returns:
- a new
ArabicPeriodinstance
-
minusYears
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
ArabicPeriodbased on this period with the specified years subtracted, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
minusMonths
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
ArabicPeriodbased on this period with the specified months subtracted, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
minusDays
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
ArabicPeriodbased on this period with the specified days subtracted, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
isEquals
Determines whether this period is equal to the given temporal amount.- Specified by:
isEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif the periods are equal;falseotherwise
-
notEquals
Determines whether this period is not equal to the given temporal amount.- Specified by:
notEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif the periods are not equal;falseotherwise
-
greaterThan
Determines whether this period is greater than the given temporal amount.Comparison is performed lexicographically: years → months → days.
- Specified by:
greaterThanin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif this period is greater
-
greaterThanEquals
Determines whether this period is greater than or equal to the given temporal amount.- Specified by:
greaterThanEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif this period is greater than or equal
-
lessThan
Determines whether this period is less than the given temporal amount.- Specified by:
lessThanin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif this period is less
-
lessThanEquals
Determines whether this period is less than or equal to the given temporal amount.- Specified by:
lessThanEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif this period is less than or equal
-
toString
Returns the Arabic textual representation of the period. -
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. -
equals
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 withObjects::equals(Object,Object). -
periodDefinition
Returns the value of theperiodDefinitionrecord component.- Returns:
- the value of the
periodDefinitionrecord component
-
temporalAmount
Returns the value of thetemporalAmountrecord component.- Specified by:
temporalAmountin interfaceNaftahTemporalAmount- Returns:
- the value of the
temporalAmountrecord component
-