Record Class NaftahDuration
- Record Components:
durationDefinition- the definition of the duration in Arabic texttemporalAmount- the actual duration value
- All Implemented Interfaces:
NaftahTemporal,NaftahTemporalAmount
This class wraps a NaftahDuration.DurationDefinition for formatting purposes and a Duration
for the actual temporal amount.
- Author:
- Chakib Daii
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordDefinition of a duration in Arabic text, including hours, minutes, seconds, milliseconds, and nanoseconds. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final NaftahDuration.DurationDefinitionThe field for thedurationDefinitionrecord component.private final DurationThe field for thetemporalAmountrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionNaftahDuration(NaftahDuration.DurationDefinition durationDefinition, Duration temporalAmount) Creates an instance of aNaftahDurationrecord class. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thedurationDefinitionrecord component.final booleanIndicates whether some other object is "equal to" this one.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.intgetNano()Returns the nanosecond-of-second component of this duration.longReturns the second-of-minute component of this duration.booleangreaterThan(NaftahTemporalAmount other) Determines whether this duration is greater than the given temporal amount.booleanDetermines whether this duration 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 duration is equal to the given temporal amount.booleanlessThan(NaftahTemporalAmount other) Determines whether this duration is less than the given temporal amount.booleanDetermines whether this duration is less than or equal to the given temporal amount.minus(NaftahTemporalAmount other) Returns a newArabicDurationobtained by subtracting the given Arabic temporal amount from this duration.minusDays(long daysToSubtract) Returns a copy of this duration with the specified duration in standard 24 hour 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.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.booleannotEquals(NaftahTemporalAmount other) Determines whether this duration is not equal to the given temporal amount.static NaftahDurationCreates a newNaftahDurationinstance from aDuration.static NaftahDurationof(NaftahDuration.DurationDefinition durationDefinition, Duration temporalAmount) Creates a newNaftahDurationinstance using the provided Arabic duration definition and the underlyingDuration.static NaftahDurationofDays(long days) Obtains aArabicDurationrepresenting a number of standard 24 hour days.static NaftahDurationofHours(long hours) Obtains aArabicDurationrepresenting a number of standard hours.static NaftahDurationofMillis(long millis) Obtains aArabicDurationrepresenting a number of milliseconds.static NaftahDurationofMinutes(long minutes) Obtains aArabicDurationrepresenting a number of standard minutes.static NaftahDurationofNanos(long nanos) Obtains aArabicDurationrepresenting a number of nanoseconds.static NaftahDurationofSeconds(long seconds) Obtains aArabicDurationrepresenting a number of seconds.static NaftahDurationofSeconds(long seconds, long nanoAdjustment) Obtains aArabicDurationrepresenting a number of seconds and an adjustment in nanoseconds.static NaftahDurationofZero()Returns anNaftahDurationrepresenting a zero duration.plus(NaftahTemporalAmount other) Returns a newArabicDurationobtained by adding the given Arabic temporal amount to this duration.plusDays(long daysToAdd) Returns a copy of this duration with the specified duration in standard 24 hour 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.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.Returns the value of thetemporalAmountrecord component.toString()Returns the Arabic textual representation of the duration.
-
Field Details
-
durationDefinition
The field for thedurationDefinitionrecord component. -
temporalAmount
The field for thetemporalAmountrecord component.
-
-
Constructor Details
-
NaftahDuration
public NaftahDuration(NaftahDuration.DurationDefinition durationDefinition, Duration temporalAmount) Creates an instance of aNaftahDurationrecord class.- Parameters:
durationDefinition- the value for thedurationDefinitionrecord componenttemporalAmount- the value for thetemporalAmountrecord component
-
-
Method Details
-
of
public static NaftahDuration of(NaftahDuration.DurationDefinition durationDefinition, Duration temporalAmount) Creates a newNaftahDurationinstance using the provided Arabic duration definition and the underlyingDuration.- Parameters:
durationDefinition- the Arabic textual definition describing the duration (hours, minutes, seconds, etc.)temporalAmount- the underlyingDurationrepresenting the actual time-based amount- Returns:
- a new
NaftahDurationinstance
-
of
Creates a newNaftahDurationinstance from aDuration.The duration is decomposed into its time-based components (hours, minutes, seconds, milliseconds, and nanoseconds) to build the corresponding Arabic textual representation.
- Parameters:
duration- theDurationto convert into anNaftahDuration- Returns:
- a new
NaftahDurationinstance representing the given duration
-
ofZero
Returns anNaftahDurationrepresenting a zero duration.The returned duration has all components set to zero: hours, minutes, seconds, milliseconds, and nanoseconds.
- Returns:
- an
NaftahDurationrepresenting a duration of zero
-
ofDays
Obtains aArabicDurationrepresenting a number of standard 24 hour days.The seconds are calculated based on the standard definition of a day, where each day is 86400 seconds which implies a 24 hour day. The nanosecond in second field is set to zero.
- Parameters:
days- the number of days, positive or negative- Returns:
- a
ArabicDuration, not null - Throws:
ArithmeticException- if the input days exceeds the capacity ofDuration
-
ofHours
Obtains aArabicDurationrepresenting 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
ArabicDuration, not null - Throws:
ArithmeticException- if the input hours exceeds the capacity ofDuration
-
ofMinutes
Obtains aArabicDurationrepresenting 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
ArabicDuration, not null - Throws:
ArithmeticException- if the input minutes exceeds the capacity ofDuration
-
ofSeconds
Obtains aArabicDurationrepresenting a number of seconds.The nanosecond in second field is set to zero.
- Parameters:
seconds- the number of seconds, positive or negative- Returns:
- a
ArabicDuration, not null
-
ofSeconds
Obtains aArabicDurationrepresenting 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
ArabicDuration, not null - Throws:
ArithmeticException- if the adjustment causes the seconds to exceed the capacity ofDuration
-
ofMillis
Obtains aArabicDurationrepresenting 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
ArabicDuration, not null
-
ofNanos
Obtains aArabicDurationrepresenting 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
ArabicDuration, not null
-
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
Returns a newArabicDurationobtained by adding the given Arabic temporal amount to this duration.Addition is supported only when the other amount is also an
ArabicDuration.- Specified by:
plusin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to add- Returns:
- a new
ArabicDurationinstance
-
plusDays
Returns a copy of this duration with the specified duration in standard 24 hour days added.The number of days is multiplied by 86400 to obtain the number of seconds to add. This is based on the standard definition of a day as 24 hours.
This instance is immutable and unaffected by this method call.
- Parameters:
daysToAdd- the days to add, positive or negative- Returns:
- a
ArabicDurationbased on this duration 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
ArabicDurationbased 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
ArabicDurationbased 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
ArabicDurationbased 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
ArabicDurationbased 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
ArabicDurationbased on this duration with the specified nanoseconds added, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
minus
Returns a newArabicDurationobtained by subtracting the given Arabic temporal amount from this duration.Subtraction is supported only when the other amount is also an
ArabicDuration.- Specified by:
minusin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to subtract- Returns:
- a new
ArabicDurationinstance
-
minusDays
Returns a copy of this duration with the specified duration in standard 24 hour days subtracted.The number of days is multiplied by 86400 to obtain the number of seconds to subtract. This is based on the standard definition of a day as 24 hours.
This instance is immutable and unaffected by this method call.
- Parameters:
daysToSubtract- the days to subtract, positive or negative- Returns:
- a
ArabicDurationbased on this duration 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
ArabicDurationbased 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
ArabicDurationbased 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
ArabicDurationbased 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
ArabicDurationbased 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
ArabicDurationbased on this duration with the specified nanoseconds subtracted, not null - Throws:
ArithmeticException- if numeric overflow occurs
-
isEquals
Determines whether this duration is equal to the given temporal amount.- Specified by:
isEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif the amounts are equal;falseotherwise
-
notEquals
Determines whether this duration is not equal to the given temporal amount.- Specified by:
notEqualsin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif the amounts are not equal;falseotherwise
-
greaterThan
Determines whether this duration is greater than the given temporal amount.- Specified by:
greaterThanin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif this duration is greater
-
greaterThanEquals
Determines whether this duration 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 duration is greater than or equal
-
lessThan
Determines whether this duration is less than the given temporal amount.- Specified by:
lessThanin interfaceNaftahTemporalAmount- Parameters:
other- the temporal amount to compare with- Returns:
trueif this duration is less
-
lessThanEquals
Determines whether this duration 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 duration is less than or equal
-
toString
Returns the Arabic textual representation of the duration. -
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). -
durationDefinition
Returns the value of thedurationDefinitionrecord component.- Returns:
- the value of the
durationDefinitionrecord component
-
temporalAmount
Returns the value of thetemporalAmountrecord component.- Specified by:
temporalAmountin interfaceNaftahTemporalAmount- Returns:
- the value of the
temporalAmountrecord component
-