Interface UnitRule<T>

Type Parameters:
T - generic type of time context compatible to TimePoint

public interface UnitRule<T>

Represents a rule for the addition or subtraction associated with a time unit.

A unit rule will usually be registered together with an unit for a TimeAxis, during loading of the concrete TimePoint-class. For every time axis and every time unit there is exactly one rule instance. Implementations must be always immutable.

Author:
Meno Hochschild
  • Method Summary

    Modifier and Type
    Method
    Description
    addTo​(T timepoint, long amount)
    Adds given amount to a time point in the context of an associated time unit.
    long
    between​(T start, T end)
    Queries how many units are between given time points.
  • Method Details

    • addTo

      T addTo(T timepoint, long amount)

      Adds given amount to a time point in the context of an associated time unit.

      This method is called by the plus()- and minus()-methods in the class TimePoint. If not specified otherwise then a possible range overflow will be resolved such that the last valid time point is choosen. For example the addition of one month to date of 31th of may will yield June, 30th.

      Parameters:
      timepoint - time point
      amount - count of units to be added to
      Returns:
      result of addition as changed copy, given time point remains unaffected
      Throws:
      IllegalArgumentException - if boundary constraints are violated
      ArithmeticException - in case of numerical overflow
      See Also:
      TimePoint.plus(long, U), TimePoint.minus(long, U)
    • between

      long between(T start, T end)

      Queries how many units are between given time points.

      This method is called by TimePoint.until(T, U). The expression start.until(end, unit) corresponds to ruleForUnit.between(start, end). Only full units will be counted. A possible remainder of subtraction will always be truncated.

      Parameters:
      start - start time point
      end - end time point
      Returns:
      difference in units (negative if end is before start)
      Throws:
      ArithmeticException - in case of numerical overflow
      See Also:
      TimePoint.until(T, U)