Package me.ahoo.cosid.sharding
Class IntervalStep
java.lang.Object
me.ahoo.cosid.sharding.IntervalStep
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfloorUnit(LocalDateTime time) Truncates time to the precision of the unit.intGets the amount.getUnit()Gets the time unit.next(LocalDateTime previous) Calculates the next time by adding the interval.static IntervalStepof(ChronoUnit unit) Creates an interval step with default amount of 1.static IntervalStepof(ChronoUnit unit, int amount) Creates an interval step with custom amount.intoffsetUnit(LocalDateTime start, LocalDateTime time) Calculates the offset from start to time in unit increments.
-
Field Details
-
DEFAULT_AMOUNT
public static final int DEFAULT_AMOUNTDefault amount of 1.- See Also:
-
-
Constructor Details
-
IntervalStep
Creates an interval step.- Parameters:
unit- the time unit (years, months, days, etc.)amount- the number of units per step
-
-
Method Details
-
getUnit
Gets the time unit.- Returns:
- the unit
-
getAmount
public int getAmount()Gets the amount.- Returns:
- the amount
-
next
Calculates the next time by adding the interval.- Parameters:
previous- the previous time- Returns:
- the next time
-
floorUnit
Truncates time to the precision of the unit.- Parameters:
time- the time to truncate- Returns:
- time truncated to unit precision
-
offsetUnit
Calculates the offset from start to time in unit increments.- Parameters:
start- the start timetime- the target time- Returns:
- the offset in units
-
of
Creates an interval step with default amount of 1.- Parameters:
unit- the time unit- Returns:
- the interval step
-
of
Creates an interval step with custom amount.- Parameters:
unit- the time unitamount- the number of units- Returns:
- the interval step
-