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
ConstructorsConstructorDescriptionTableDuration(Period period, Duration duration) Constructs aTableDurationfrom the specified period and duration. -
Method Summary
Modifier and TypeMethodDescriptionlongget(TemporalUnit unit) getUnits()minus(TableDuration other) Subtracts the specifiedTableDurationfrom this instance.multipliedBy(int scalar) Multiplies this duration by the specified scalar value.negated()Negates this duration.static TableDurationFactory method to create a newTableDurationinstance.plus(TableDuration other) Adds the specifiedTableDurationto this instance.subtractFrom(Temporal temporal) Returns a compact string representation of this duration.Converts thisTableDurationto an ISO8601 string representation.
-
Constructor Details
-
TableDuration
Constructs aTableDurationfrom 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 newTableDurationinstance.- Parameters:
period- the period componentduration- the duration component- Returns:
- a new instance of
TableDuration
-
plus
Adds the specifiedTableDurationto this instance.- Parameters:
other- the otherTableDurationto add- Returns:
- a new
TableDurationinstance representing the result
-
minus
Subtracts the specifiedTableDurationfrom this instance.- Parameters:
other- the otherTableDurationto subtract- Returns:
- a new
TableDurationinstance representing the result
-
multipliedBy
Multiplies this duration by the specified scalar value.- Parameters:
scalar- the scalar to multiply by- Returns:
- a new
TableDurationinstance representing the result
-
negated
Negates this duration.- Returns:
- a new
TableDurationinstance with the negated values
-
get
- Specified by:
getin interfaceTemporalAmount
-
getUnits
- Specified by:
getUnitsin interfaceTemporalAmount
-
addTo
- Specified by:
addToin interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFromin interfaceTemporalAmount
-
toISO8601
Converts thisTableDurationto 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:
-1y2mo3d4h5m6srepresents negative 1 year, 2 months, etc.- Returns:
- a compact string representation of this duration
-