Class TableDuration

java.lang.Object
com.datastax.astra.client.tables.definition.TableDuration
All Implemented Interfaces:
TemporalAmount

public class TableDuration extends Object implements 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 Details

    • TableDuration

      public TableDuration(Period period, Duration duration)
      Constructs a TableDuration from the specified period and duration. Null values are treated as zero.
      Parameters:
      period - the period component, or null for zero period
      duration - the duration component, or null for zero duration
  • Method Details

    • of

      public static TableDuration of(Period period, Duration duration)
      Factory method to create a new TableDuration instance.
      Parameters:
      period - the period component
      duration - the duration component
      Returns:
      a new instance of TableDuration
    • plus

      public TableDuration plus(TableDuration other)
      Adds the specified TableDuration to this instance.
      Parameters:
      other - the other TableDuration to add
      Returns:
      a new TableDuration instance representing the result
    • minus

      public TableDuration minus(TableDuration other)
      Subtracts the specified TableDuration from this instance.
      Parameters:
      other - the other TableDuration to subtract
      Returns:
      a new TableDuration instance representing the result
    • multipliedBy

      public TableDuration multipliedBy(int scalar)
      Multiplies this duration by the specified scalar value.
      Parameters:
      scalar - the scalar to multiply by
      Returns:
      a new TableDuration instance representing the result
    • negated

      public TableDuration negated()
      Negates this duration.
      Returns:
      a new TableDuration instance with the negated values
    • get

      public long get(TemporalUnit unit)
      Specified by:
      get in interface TemporalAmount
    • getUnits

      public List<TemporalUnit> getUnits()
      Specified by:
      getUnits in interface TemporalAmount
    • addTo

      public Temporal addTo(Temporal temporal)
      Specified by:
      addTo in interface TemporalAmount
    • subtractFrom

      public Temporal subtractFrom(Temporal temporal)
      Specified by:
      subtractFrom in interface TemporalAmount
    • toISO8601

      public String toISO8601()
      Converts this TableDuration to an ISO8601 string representation. The format follows the standard for combining periods and durations.
      Returns:
      an ISO8601 string representing this duration
    • toCompactString

      public String 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