Class SimpleInterval<T>

java.lang.Object
net.time4j.range.SimpleInterval<T>
Type Parameters:
T - generic type of timepoints on the underlying timeline
All Implemented Interfaces:
Serializable, ChronoInterval<T>

public final class SimpleInterval<T> extends Object implements ChronoInterval<T>, Serializable

Generic interval class suitable for any type of timepoints on a timeline.

Represents an interval with following simplified features:

  • If calendrical, then always closed else half-open with inclusive start and exclusive end.
  • Supports infinite boundaries (exception to half-open-state or closed-state).
  • Can be adapted to any foreign type as long as a timeline can be implemented.
  • Can be used in conjunction with IntervalCollection and IntervalTree.

This class is mainly intended to adapt foreign types like java.util.Date. It is serializable as long as the underlying timeline is serializable.

Since:
3.25/4.21
Author:
Meno Hochschild
See Also:
Serialized Form
  • Method Details

    • between

      public static SimpleInterval<Date> between(Date start, Date end)

      Creates a new interval between given boundaries.

      Parameters:
      start - the start of interval (inclusive)
      end - the end of interval (exclusive)
      Returns:
      new interval (half-open)
    • between

      public static SimpleInterval<Instant> between(Instant start, Instant end)

      Creates a new interval between given boundaries.

      Parameters:
      start - the start of interval (inclusive)
      end - the end of interval (exclusive)
      Returns:
      new interval (half-open)
      See Also:
      MomentInterval.between(Instant, Instant)
    • since

      public static SimpleInterval<Date> since(Date start)

      Creates a new interval since given start.

      Parameters:
      start - the start of interval (inclusive)
      Returns:
      new interval (half-open and infinite)
    • since

      public static SimpleInterval<Instant> since(Instant start)

      Creates a new interval since given start.

      Parameters:
      start - the start of interval (inclusive)
      Returns:
      new interval (half-open and infinite)
      See Also:
      MomentInterval.since(Instant)
    • until

      public static SimpleInterval<Date> until(Date end)

      Creates a new interval until given end.

      Parameters:
      end - the end of interval (exclusive)
      Returns:
      new interval (open and infinite)
    • until

      public static SimpleInterval<Instant> until(Instant end)

      Creates a new interval until given end.

      Parameters:
      end - the end of interval (exclusive)
      Returns:
      new interval (open and infinite)
      See Also:
      MomentInterval.until(Instant)
    • onTraditionalTimeLine

      public static SimpleInterval.Factory<Date> onTraditionalTimeLine()

      Defines a timeline on which new intervals for the type java.util.Date can be created.

      Returns:
      singleton interval factory
    • onInstantTimeLine

      public static SimpleInterval.Factory<Instant> onInstantTimeLine()

      Defines a timeline on which new intervals for the type java.time.Instant can be created.

      Returns:
      singleton interval factory
    • on

      public static <T> SimpleInterval.Factory<T> on(TimeLine<T> timeLine)

      Defines a timeline on which new generic intervals can be created.

      Type Parameters:
      T - generic type of timepoints on the underlying timeline
      Parameters:
      timeLine - the timeline definition
      Returns:
      new interval factory
      Since:
      5.0
    • getStart

      public Boundary<T> getStart()
      Description copied from interface: ChronoInterval

      Yields the lower bound of this interval.

      Specified by:
      getStart in interface ChronoInterval<T>
      Returns:
      start interval boundary
    • getEnd

      public Boundary<T> getEnd()
      Description copied from interface: ChronoInterval

      Yields the upper bound of this interval.

      Specified by:
      getEnd in interface ChronoInterval<T>
      Returns:
      end interval boundary
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ChronoInterval

      Determines if this interval is empty.

      Specified by:
      isEmpty in interface ChronoInterval<T>
      Returns:
      true if this interval does not contain any time point else false
    • contains

      public boolean contains(T temporal)
      Description copied from interface: ChronoInterval

      Queries if given time point belongs to this interval.

      Specified by:
      contains in interface ChronoInterval<T>
      Parameters:
      temporal - time point to be queried
      Returns:
      true if given time point belongs to this interval else false
    • contains

      public boolean contains(ChronoInterval<T> other)
      Description copied from interface: ChronoInterval

      Does this interval contain the other one?

      An interval cannot contain infinite intervals but can contain an empty interval if it contains the start anchor of the empty interval.

      Specified by:
      contains in interface ChronoInterval<T>
      Parameters:
      other - another interval whose relation to this interval is to be investigated
      Returns:
      true if this interval contains the other one else false
      See Also:
      ChronoInterval.intersects(ChronoInterval)
    • isAfter

      public boolean isAfter(T temporal)
      Description copied from interface: ChronoInterval

      Is this interval after the given time point?

      Specified by:
      isAfter in interface ChronoInterval<T>
      Parameters:
      temporal - reference time point
      Returns:
      true if this interval is after given time point else false
    • isBefore

      public boolean isBefore(T temporal)
      Description copied from interface: ChronoInterval

      Is this interval before the given time point?

      Specified by:
      isBefore in interface ChronoInterval<T>
      Parameters:
      temporal - reference time point
      Returns:
      true if this interval is before given time point else false
    • isBefore

      public boolean isBefore(ChronoInterval<T> other)
      Description copied from interface: ChronoInterval

      Is this interval before the other one?

      Specified by:
      isBefore in interface ChronoInterval<T>
      Parameters:
      other - another interval whose relation to this interval is to be investigated
      Returns:
      true if this interval is before the other one else false
    • abuts

      public boolean abuts(ChronoInterval<T> other)
      Description copied from interface: ChronoInterval

      Queries if this interval abuts the other one such that there is neither any overlap nor any gap between.

      Note: Empty intervals never abut.

      Specified by:
      abuts in interface ChronoInterval<T>
      Parameters:
      other - another interval which might abut this interval
      Returns:
      true if there is no intersection and no gap between else false
    • findIntersection

      public Optional<SimpleInterval<T>> findIntersection(ChronoInterval<T> other)

      Obtains the intersection of this interval and other one if present.

      Note that the return type of the method is for the older version line v3.25 or later just SimpleInterval&lt;T&gt;, possibly returning null.

      Parameters:
      other - another interval which might have an intersection with this interval
      Returns:
      a wrapper around the found intersection or an empty wrapper
      Since:
      4.21
      See Also:
      Optional.isPresent(), ChronoInterval.intersects(ChronoInterval)
    • print

      public String print(ChronoPrinter<T> printer)

      Prints this interval using a localized interval pattern.

      If given printer does not contain a reference to a locale then the interval pattern "{0}/{1}" will be used.

      Parameters:
      printer - format object for printing start and end
      Returns:
      localized formatted string
      See Also:
      print(ChronoPrinter, String), FormatPatternProvider.getIntervalPattern(Locale)
    • print

      public String print(ChronoPrinter<T> printer, String intervalPattern)

      Prints this interval in a custom format.

      Parameters:
      printer - format object for printing start and end components
      intervalPattern - interval pattern containing placeholders {0} and {1} (for start and end)
      Returns:
      formatted string in given pattern format
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()

      Returns a string in technical notation (suitable for debugging purposes).

      Overrides:
      toString in class Object
      Returns:
      String