Class TableDuration
java.lang.Object
com.datastax.astra.client.tables.definition.TableDuration
- All Implemented Interfaces:
TemporalAmount
Represents a combination of a
Period
and a Duration
.
This class is immutable and implements TemporalAmount
to
support arithmetic operations and integration with temporal objects.
The TableDuration
class provides methods to manipulate and retrieve
combined period and duration values, as well as utility methods for
serialization and formatting.
Example usage:
TableDuration td1 = TableDuration.of(Period.ofDays(2), Duration.ofHours(5));
TableDuration td2 = TableDuration.of(Period.ofMonths(1), Duration.ofMinutes(30));
TableDuration combined = td1.plus(td2);
System.out.println(combined.toISO8601()); // Prints ISO8601 representation
-
Constructor Summary
ConstructorDescriptionTableDuration
(Period period, Duration duration) Constructs aTableDuration
from the specified period and duration. -
Method Summary
Modifier and TypeMethodDescriptionlong
get
(TemporalUnit unit) getUnits()
minus
(TableDuration other) Subtracts the specifiedTableDuration
from this instance.multipliedBy
(int scalar) Multiplies this duration by the specified scalar value.negated()
Negates this duration.static TableDuration
Factory method to create a newTableDuration
instance.plus
(TableDuration other) Adds the specifiedTableDuration
to this instance.subtractFrom
(Temporal temporal) Returns a compact string representation of this duration.Converts thisTableDuration
to an ISO8601 string representation.
-
Constructor Details
-
TableDuration
Constructs aTableDuration
from the specified period and duration. Null values are treated as zero.- Parameters:
period
- the period component, or null for zero periodduration
- the duration component, or null for zero duration
-
-
Method Details
-
of
Factory method to create a newTableDuration
instance.- Parameters:
period
- the period componentduration
- the duration component- Returns:
- a new instance of
TableDuration
-
plus
Adds the specifiedTableDuration
to this instance.- Parameters:
other
- the otherTableDuration
to add- Returns:
- a new
TableDuration
instance representing the result
-
minus
Subtracts the specifiedTableDuration
from this instance.- Parameters:
other
- the otherTableDuration
to subtract- Returns:
- a new
TableDuration
instance representing the result
-
multipliedBy
Multiplies this duration by the specified scalar value.- Parameters:
scalar
- the scalar to multiply by- Returns:
- a new
TableDuration
instance representing the result
-
negated
Negates this duration.- Returns:
- a new
TableDuration
instance with the negated values
-
get
- Specified by:
get
in interfaceTemporalAmount
-
getUnits
- Specified by:
getUnits
in interfaceTemporalAmount
-
addTo
- Specified by:
addTo
in interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFrom
in interfaceTemporalAmount
-
toISO8601
Converts thisTableDuration
to an ISO8601 string representation. The format follows the standard for combining periods and durations.- Returns:
- an ISO8601 string representing this duration
-
toCompactString
Returns a compact string representation of this duration. Negative values are prefixed with a "-" and units are suffixed with appropriate abbreviations.Example:
-1y2mo3d4h5m6s
represents negative 1 year, 2 months, etc.- Returns:
- a compact string representation of this duration
-