Class CheckerDuration

java.lang.Object
com.luchersol.core.util.AbstractChecker<Duration,CheckerDuration>
com.luchersol.core.specialized_checkers.time.CheckerDuration
All Implemented Interfaces:
InterfaceChecker<AbstractChecker<Duration,CheckerDuration>,Duration>

public class CheckerDuration extends AbstractChecker<Duration,CheckerDuration>
A specialized checker for Duration instances, providing fluent API methods to assert various temporal properties such as positivity, negativity, zero value, and comparisons with other durations or specific temporal units.

Typical usage:


 Duration d1 = Duration.ofMinutes(5);
 Duration d2 = Duration.ofMinutes(10);

 CheckerDuration checker = CheckerDuration.check(d1)
     .isPositive()
     .isLessThan(d2)
     .isGreaterOrEqualThan(Duration.ofMinutes(3));
 

This class supports chaining multiple assertions in a fluent style and integrates with AbstractChecker for generalized validation handling.

See Also:
  • Constructor Details

    • CheckerDuration

      protected CheckerDuration(Duration duration, String name)
      Constructs a new CheckerDuration with the specified duration and name.
      Parameters:
      duration - the Duration to be associated with this checker
      name - the name of the checker
  • Method Details

    • check

      public static CheckerDuration check(Duration duration, String name)
      Creates a new CheckerDuration instance for the given duration and name.
      Parameters:
      duration - the duration value to be checked
      name - the name to identify the duration in error messages
      Returns:
      a CheckerDuration instance for further validations
    • check

      public static CheckerDuration check(Duration duration)
      Creates a new CheckerDuration instance for the given duration with a default name.
      Parameters:
      duration - the duration value to be checked
      Returns:
      a CheckerDuration instance for further validations
    • self

      protected CheckerDuration self()
      Returns this instance (for fluent API usage).
      Specified by:
      self in class AbstractChecker<Duration,CheckerDuration>
      Returns:
      this CheckerDuration instance
    • isPositive

      public CheckerDuration isPositive()
      Checks if the duration is positive (greater than zero).
      Returns:
      this CheckerDuration instance for chaining
    • isNegative

      public CheckerDuration isNegative()
      Checks if the duration is negative (less than zero).
      Returns:
      this CheckerDuration instance for chaining
    • isZero

      public CheckerDuration isZero()
      Checks if the duration is zero.
      Returns:
      this CheckerDuration instance for chaining
    • isGreaterThan

      public CheckerDuration isGreaterThan(TemporalUnit temporalUnit, double time)
      Checks if the duration is greater than the specified time in the given temporal unit.
      Parameters:
      temporalUnit - the unit of time to compare (e.g., SECONDS, MINUTES)
      time - the value to compare against
      Returns:
      this CheckerDuration instance for chaining
    • isGreaterOrEqualThan

      public CheckerDuration isGreaterOrEqualThan(TemporalUnit temporalUnit, double time)
      Checks if the duration is greater than or equal to the specified time in the given temporal unit.
      Parameters:
      temporalUnit - the unit of time to compare (e.g., SECONDS, MINUTES)
      time - the value to compare against
      Returns:
      this CheckerDuration instance for chaining
    • isLessThan

      public CheckerDuration isLessThan(TemporalUnit temporalUnit, double time)
      Checks if the duration is less than the specified time in the given temporal unit.
      Parameters:
      temporalUnit - the unit of time to compare (e.g., SECONDS, MINUTES)
      time - the value to compare against
      Returns:
      this CheckerDuration instance for chaining
    • isLessOrEqualThan

      public CheckerDuration isLessOrEqualThan(TemporalUnit temporalUnit, double time)
      Checks if the duration is less than or equal to the specified time in the given temporal unit.
      Parameters:
      temporalUnit - the unit of time to compare (e.g., SECONDS, MINUTES)
      time - the value to compare against
      Returns:
      this CheckerDuration instance for chaining
    • isEqual

      public CheckerDuration isEqual(TemporalUnit temporalUnit, double time)
      Checks if the duration is equal to the specified time in the given temporal unit.
      Parameters:
      temporalUnit - the unit of time to compare (e.g., SECONDS, MINUTES)
      time - the value to compare against
      Returns:
      this CheckerDuration instance for chaining
    • isGreaterThan

      public CheckerDuration isGreaterThan(Duration other)
      Checks if the duration is greater than another duration.
      Parameters:
      other - the other duration to compare with
      Returns:
      this CheckerDuration instance for chaining
    • isGreaterOrEqualThan

      public CheckerDuration isGreaterOrEqualThan(Duration other)
      Checks if the duration is greater than or equal to another duration.
      Parameters:
      other - the other duration to compare with
      Returns:
      this CheckerDuration instance for chaining
    • isLessThan

      public CheckerDuration isLessThan(Duration other)
      Checks if the duration is less than another duration.
      Parameters:
      other - the other duration to compare with
      Returns:
      this CheckerDuration instance for chaining
    • isLessOrEqualThan

      public CheckerDuration isLessOrEqualThan(Duration other)
      Checks if the duration is less than or equal to another duration.
      Parameters:
      other - the other duration to compare with
      Returns:
      this CheckerDuration instance for chaining
    • isEqual

      public CheckerDuration isEqual(Duration other)
      Checks if the duration is equal to another duration.
      Parameters:
      other - the other duration to compare with
      Returns:
      this CheckerDuration instance for chaining