Class IntervalStep

java.lang.Object
me.ahoo.cosid.sharding.IntervalStep

@Immutable public class IntervalStep extends Object
Represents a time interval step for sharding operations.

Defines the granularity and size of time-based sharding intervals. Used for interval sharding algorithms in ShardingSphere integration.

  • Field Details

    • DEFAULT_AMOUNT

      public static final int DEFAULT_AMOUNT
      Default amount of 1.
      See Also:
  • Constructor Details

    • IntervalStep

      public IntervalStep(ChronoUnit unit, int amount)
      Creates an interval step.
      Parameters:
      unit - the time unit (years, months, days, etc.)
      amount - the number of units per step
  • Method Details

    • getUnit

      public ChronoUnit getUnit()
      Gets the time unit.
      Returns:
      the unit
    • getAmount

      public int getAmount()
      Gets the amount.
      Returns:
      the amount
    • next

      public LocalDateTime next(LocalDateTime previous)
      Calculates the next time by adding the interval.
      Parameters:
      previous - the previous time
      Returns:
      the next time
    • floorUnit

      public LocalDateTime floorUnit(LocalDateTime time)
      Truncates time to the precision of the unit.
      Parameters:
      time - the time to truncate
      Returns:
      time truncated to unit precision
    • offsetUnit

      public int offsetUnit(LocalDateTime start, LocalDateTime time)
      Calculates the offset from start to time in unit increments.
      Parameters:
      start - the start time
      time - the target time
      Returns:
      the offset in units
    • of

      public static IntervalStep of(ChronoUnit unit)
      Creates an interval step with default amount of 1.
      Parameters:
      unit - the time unit
      Returns:
      the interval step
    • of

      public static IntervalStep of(ChronoUnit unit, int amount)
      Creates an interval step with custom amount.
      Parameters:
      unit - the time unit
      amount - the number of units
      Returns:
      the interval step