Class Interval

java.lang.Object
org.salespointframework.time.Interval

@Embeddable public final class Interval extends Object
Simple value object to represent time intervals. Note that whether the endpoints are included or not can vary between the offered methods.
Author:
Oliver Drotbohm, Martin Morgenstern, Rebecca Uecker
  • Method Details

    • from

      public static Interval.IntervalBuilder from(LocalDateTime start)
      Starts building a new Interval with the given start time.
      Parameters:
      start - must not be null.
      Returns:
      will never be null.
    • getDuration

      public Duration getDuration()
      Returns the duration of the interval, with the end excluded.
      Returns:
      will never be null.
    • contains

      public boolean contains(LocalDateTime reference)
      Returns whether the given LocalDateTime is contained in the current Interval. The comparison includes start and end, i.e., the method treats this interval as closed.
      Parameters:
      reference - must not be null.
      Returns:
    • overlaps

      public boolean overlaps(Interval reference)
      Returns whether the current Interval overlaps with the given one. The comparison excludes start and end, i.e., the method treats both intervals as open.
      Parameters:
      reference - must not be null.
      Returns:
    • toDuration

      public Duration toDuration()
      Returns the Duration represented by the given Interval, with the end excluded.
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getStart

      public LocalDateTime getStart()
      The start date of the Interval.
    • getEnd

      public LocalDateTime getEnd()
      The end date of the Interval.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object