Record Class NaftahPeriodWithDuration
- Record Components:
naftahPeriod- the period part in ArabicnaftahDuration- the duration part in Arabic
- All Implemented Interfaces:
NaftahTemporal,NaftahTemporalAmount
This class wraps an NaftahPeriod and an NaftahDuration, allowing
you to work with both periods (years, months, days) and durations (hours, minutes, seconds)
together in Arabic formatting.
- Author:
- Chakib Daii
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final NaftahDurationThe field for thenaftahDurationrecord component.private final NaftahPeriodThe field for thenaftahPeriodrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionNaftahPeriodWithDuration(NaftahPeriod naftahPeriod, NaftahDuration naftahDuration) Creates an instance of aNaftahPeriodWithDurationrecord class. -
Method Summary
Modifier and TypeMethodDescriptionprivate static NaftahPeriodWithDurationadjustDurationIntoPeriod(NaftahPeriod period, NaftahDuration duration) Adjusts durations of 24 hours or more by converting full days into the period.final booleanIndicates whether some other object is "equal to" this one.intgetDays()Returns the number of days in this period.longgetHours()Returns the total number of hours in this duration.longReturns the millisecond-of-second component of this duration.longReturns the minute-of-hour component of this duration.intReturns the number of months in this period.intgetNano()Returns the nanosecond-of-second component of this duration.longReturns the second-of-minute component of this duration.intgetYears()Returns the number of years in this period.booleangreaterThan(NaftahTemporalAmount other) Determines whether this temporal amount is greater than the given one.booleanDetermines whether this temporal amount is greater than or equal to the given one.final inthashCode()Returns a hash code value for this object.booleanisEquals(NaftahTemporalAmount other) Determines whether this temporal amount is equal to the given one.booleanlessThan(NaftahTemporalAmount other) Determines whether this temporal amount is less than the given one.booleanDetermines whether this temporal amount is less than or equal to the given one.minus(NaftahTemporalAmount other) Subtracts the given Arabic temporal amount from this instance.minusDays(long daysToSubtract) Returns a copy of this period with the specified days subtracted.minusHours(long hoursToSubtract) Returns a copy of this duration with the specified duration in hours subtracted.minusMillis(long millisToSubtract) Returns a copy of this duration with the specified duration in milliseconds subtracted.minusMinutes(long minutesToSubtract) Returns a copy of this duration with the specified duration in minutes subtracted.minusMonths(long monthsToSubtract) Returns a copy of this period with the specified months subtracted.minusNanos(long nanosToSubtract) Returns a copy of this duration with the specified duration in nanoseconds subtracted.minusSeconds(long secondsToSubtract) Returns a copy of this duration with the specified duration in seconds subtracted.minusYears(long yearsToSubtract) Returns a copy of this period with the specified years subtracted.Returns the value of thenaftahDurationrecord component.Returns the value of thenaftahPeriodrecord component.booleannotEquals(NaftahTemporalAmount other) Determines whether this temporal amount is not equal to the given one.static NaftahPeriodWithDurationof(NaftahPeriod naftahPeriod, NaftahDuration naftahDuration) Creates a newArabicPeriodWithDurationinstance.static NaftahPeriodWithDurationofDays(int days) Obtains aArabicPeriodWithDurationrepresenting a number of days.static NaftahPeriodWithDurationofHours(long hours) Obtains aArabicPeriodWithDurationrepresenting a number of standard hours.static NaftahPeriodWithDurationofMillis(long millis) Obtains aArabicPeriodWithDurationrepresenting a number of milliseconds.static NaftahPeriodWithDurationofMinutes(long minutes) Obtains aArabicPeriodWithDurationrepresenting a number of standard minutes.static NaftahPeriodWithDurationofMonths(int months) Obtains aArabicPeriodWithDurationrepresenting a number of months.static NaftahPeriodWithDurationofNanos(long nanos) Obtains aArabicPeriodWithDurationrepresenting a number of nanoseconds.static NaftahPeriodWithDurationofSeconds(long seconds) Obtains aArabicPeriodWithDurationrepresenting a number of seconds.static NaftahPeriodWithDurationofSeconds(long seconds, long nanoAdjustment) Obtains aArabicPeriodWithDurationrepresenting a number of seconds and an adjustment in nanoseconds.static NaftahPeriodWithDurationofWeeks(int weeks) Obtains aArabicPeriodWithDurationrepresenting a number of weeks.static NaftahPeriodWithDurationofYears(int years) Obtains aArabicPeriodWithDurationrepresenting a number of years.static NaftahPeriodWithDurationofZero()Returns anNaftahPeriodWithDurationrepresenting a zero period and zero duration.plus(NaftahTemporalAmount other) Adds the given Arabic temporal amount to this instance.plusDays(long daysToAdd) Returns a copy of this period with the specified days added.plusHours(long hoursToAdd) Returns a copy of this duration with the specified duration in hours added.plusMillis(long millisToAdd) Returns a copy of this duration with the specified duration in milliseconds added.plusMinutes(long minutesToAdd) Returns a copy of this duration with the specified duration in minutes added.plusMonths(long monthsToAdd) Returns a copy of this period with the specified months added.plusNanos(long nanosToAdd) Returns a copy of this duration with the specified duration in nanoseconds added.plusSeconds(long secondsToAdd) Returns a copy of this duration with the specified duration in seconds added.plusYears(long yearsToAdd) Returns a copy of this period with the specified years added.Returns the combined temporal amount of the period and duration.toString()Returns the Arabic textual representation of the combined period and duration.
-
Field Details
-
naftahPeriod
The field for thenaftahPeriodrecord component. -
naftahDuration
The field for thenaftahDurationrecord component.
-
-
Constructor Details
-
NaftahPeriodWithDuration
Creates an instance of aNaftahPeriodWithDurationrecord class.- Parameters:
naftahPeriod- the value for thenaftahPeriodrecord componentnaftahDuration- the value for thenaftahDurationrecord component
-
-
Method Details
-
of
Creates a newArabicPeriodWithDurationinstance.- Parameters:
naftahPeriod- the period part in ArabicnaftahDuration- the duration part in Arabic- Returns:
- a new
ArabicPeriodWithDurationinstance
-
ofZero
Returns anNaftahPeriodWithDurationrepresenting a zero period and zero duration.The returned object has all components of both the period (years, months, days) and the duration (hours, minutes, seconds, milliseconds, nanoseconds) set to zero.
- Returns:
- an
NaftahPeriodWithDurationwith zero period and zero duration
-
ofYears
Obtains aArabicPeriodWithDurationrepresenting 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 aArabicPeriodWithDurationrepresenting 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 aArabicPeriodWithDurationrepresenting 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 aArabicPeriodWithDurationrepresenting 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
-
ofHours
Obtains aArabicPeriodWithDurationrepresenting a number of standard hours.The seconds are calculated based on the standard definition of an hour, where each hour is 3600 seconds. The nanosecond in second field is set to zero.
- Parameters:
hours- the number of hours, positive or negative- Returns:
- a
ArabicPeriodWithDuration, not null - Throws:
ArithmeticException- if the input hours exceeds the capacity ofDuration
-
ofMinutes
Obtains aArabicPeriodWithDurationrepresenting a number of standard minutes.The seconds are calculated based on the standard definition of a minute, where each minute is 60 seconds. The nanosecond in second field is set to zero.
- Parameters:
minutes- the number of minutes, positive or negative- Returns:
- a
ArabicPeriodWithDuration, not null - Throws:
ArithmeticException- if the input minutes exceeds the capacity ofDuration
-
ofSeconds
Obtains aArabicPeriodWithDurationrepresenting a number of seconds.The nanosecond in second field is set to zero.
- Parameters:
seconds- the number of seconds, positive or negative- Returns:
- a
ArabicPeriodWithDuration, not null
-
ofSeconds
Obtains aArabicPeriodWithDurationrepresenting a number of seconds and an adjustment in nanoseconds.This method allows an arbitrary number of nanoseconds to be passed in. The factory will alter the values of the second and nanosecond in order to ensure that the stored nanosecond is in the range 0 to 999,999,999. For example, the following will result in exactly the same duration:
Duration.ofSeconds(3, 1); Duration.ofSeconds(4, -999_999_999); Duration.ofSeconds(2, 1000_000_001);
- Parameters:
seconds- the number of seconds, positive or negativenanoAdjustment- the nanosecond adjustment to the number of seconds, positive or negative- Returns:
- a
ArabicPeriodWithDuration, not null - Throws:
ArithmeticException- if the adjustment causes the seconds to exceed the capacity ofDuration
-
ofMillis
Obtains aArabicPeriodWithDurationrepresenting a number of milliseconds.The seconds and nanoseconds are extracted from the specified milliseconds.
- Parameters:
millis- the number of milliseconds, positive or negative- Returns:
- a
ArabicPeriodWithDuration, not null
-
ofNanos
Obtains aArabicPeriodWithDurationrepresenting a number of nanoseconds.The seconds and nanoseconds are extracted from the specified nanoseconds.
- Parameters:
nanos- the number of nanoseconds, positive or negative- Returns:
- a
ArabicPeriodWithDuration, not null
-
adjustDurationIntoPeriod
private static NaftahPeriodWithDuration adjustDurationIntoPeriod(NaftahPeriod period, NaftahDuration duration) Adjusts durations of 24 hours or more by converting full days into the period.- Parameters:
period- the original ArabicPeriodduration- the original ArabicDuration- Returns:
- a new
ArabicPeriodWithDurationwith normalized duration and adjusted period
-
temporalAmount
Returns the combined temporal amount of the period and duration.The period and duration are added together as a single
TemporalAmount.- Specified by:
temporalAmountin interfaceNaftahTemporalAmount- Returns:
- the total temporal amount
-
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
-
getHours
public long getHours()Returns the total number of hours in this duration.- Returns:
- the total hours
-
getMinutes
public long getMinutes()Returns the minute-of-hour component of this duration.This is calculated as the total minutes modulo 60, representing the remaining minutes after full hours are accounted for.
- Returns:
- the minutes within the current hour (0-59)
-
getSeconds
public long getSeconds()Returns the second-of-minute component of this duration.This is calculated as the total seconds modulo 60, representing the remaining seconds after full minutes are accounted for.
- Returns:
- the seconds within the current minute (0-59)
-
getMillis
public long getMillis()Returns the millisecond-of-second component of this duration.This is calculated as the total milliseconds modulo 1000, representing the remaining milliseconds after full seconds are accounted for.
- Returns:
- the milliseconds within the current second (0-999)
-
getNano
public int getNano()Returns the nanosecond-of-second component of this duration.- Returns:
- the nanoseconds within the current second (0-999,999,999)
-
plus
Adds the given Arabic temporal amount to this instance.Supported combinations:
NaftahDurationNaftahPeriodWithDuration- Any
NaftahTemporalAmountconvertible to aPeriod
- Specified by:
plusin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to add- Returns:
- a new normalized
ArabicPeriodWithDuration
-
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
ArabicPeriodWithDurationbased 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
ArabicPeriodWithDurationbased 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
ArabicPeriodWithDurationbased on this period with the specified days added, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
plusHours
Returns a copy of this duration with the specified duration in hours added.This instance is immutable and unaffected by this method call.
- Parameters:
hoursToAdd- the hours to add, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified hours added, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
plusMinutes
Returns a copy of this duration with the specified duration in minutes added.This instance is immutable and unaffected by this method call.
- Parameters:
minutesToAdd- the minutes to add, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified minutes added, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
plusSeconds
Returns a copy of this duration with the specified duration in seconds added.This instance is immutable and unaffected by this method call.
- Parameters:
secondsToAdd- the seconds to add, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified seconds added, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
plusMillis
Returns a copy of this duration with the specified duration in milliseconds added.This instance is immutable and unaffected by this method call.
- Parameters:
millisToAdd- the milliseconds to add, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified milliseconds added, not * null - Throws:
ArithmeticException- if numeric overflow occurs
-
plusNanos
Returns a copy of this duration with the specified duration in nanoseconds added.This instance is immutable and unaffected by this method call.
- Parameters:
nanosToAdd- the nanoseconds to add, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified nanoseconds added, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
minus
Subtracts the given Arabic temporal amount from this instance.Supported combinations mirror those of
plus(NaftahTemporalAmount).- Specified by:
minusin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to subtract- Returns:
- a new normalized
ArabicPeriodWithDuration
-
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
ArabicPeriodWithDurationbased 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
ArabicPeriodWithDurationbased 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
ArabicPeriodWithDurationbased on this period with the specified days subtracted, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
minusHours
Returns a copy of this duration with the specified duration in hours subtracted.The number of hours is multiplied by 3600 to obtain the number of seconds to subtract.
This instance is immutable and unaffected by this method call.
- Parameters:
hoursToSubtract- the hours to subtract, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified hours subtracted, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
minusMinutes
Returns a copy of this duration with the specified duration in minutes subtracted.The number of hours is multiplied by 60 to obtain the number of seconds to subtract.
This instance is immutable and unaffected by this method call.
- Parameters:
minutesToSubtract- the minutes to subtract, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified minutes subtracted, not * null - Throws:
ArithmeticException- if numeric overflow occurs
-
minusSeconds
Returns a copy of this duration with the specified duration in seconds subtracted.This instance is immutable and unaffected by this method call.
- Parameters:
secondsToSubtract- the seconds to subtract, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified seconds subtracted, not * null - Throws:
ArithmeticException- if numeric overflow occurs
-
minusMillis
Returns a copy of this duration with the specified duration in milliseconds subtracted.This instance is immutable and unaffected by this method call.
- Parameters:
millisToSubtract- the milliseconds to subtract, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified milliseconds subtracted, * not null - Throws:
ArithmeticException- if numeric overflow occurs
-
minusNanos
Returns a copy of this duration with the specified duration in nanoseconds subtracted.This instance is immutable and unaffected by this method call.
- Parameters:
nanosToSubtract- the nanoseconds to subtract, positive or negative- Returns:
- a
ArabicPeriodWithDurationbased on this duration with the specified nanoseconds subtracted, * not null - Throws:
ArithmeticException- if numeric overflow occurs
-
isEquals
Determines whether this temporal amount is equal to the given one.Equality requires both the period and duration components to be equal.
- Specified by:
isEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif both components are equal
-
notEquals
Determines whether this temporal amount is not equal to the given one.- Specified by:
notEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif the amounts are not equal
-
greaterThan
Determines whether this temporal amount is greater than the given one.Comparison is performed component-wise: both the period and duration must be greater.
- Specified by:
greaterThanin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif both components are greater
-
greaterThanEquals
Determines whether this temporal amount is greater than or equal to the given one.- Specified by:
greaterThanEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif both components are greater than or equal
-
lessThan
Determines whether this temporal amount is less than the given one.- Specified by:
lessThanin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif both components are less
-
lessThanEquals
Determines whether this temporal amount is less than or equal to the given one.- Specified by:
lessThanEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif both components are less than or equal
-
toString
Returns the Arabic textual representation of the combined period and duration.The string consists of the Arabic period followed by the Arabic duration, joined with the Arabic conjunction " و ".
-
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). -
naftahPeriod
Returns the value of thenaftahPeriodrecord component.- Returns:
- the value of the
naftahPeriodrecord component
-
naftahDuration
Returns the value of thenaftahDurationrecord component.- Returns:
- the value of the
naftahDurationrecord component
-