Class EInterval

  • All Implemented Interfaces:
    java.io.Serializable

    public final class EInterval
    extends EField
    Implements a time interval from one Instant to another. EInterval guarantees that begin time is ≤ end time. Each end point may be separately configured to be inclusive or exclusive. If begin time equals end time then both ends must be marked as inclusive.

    EInterval extends EField so that it can be used in an eBus message. This means that EInterval.Builder must be used to create an EInterval instance.

    EInterval is immutable and thread-safe.

    Allen's Interval Algebra

    Allen's temporal reasoning calculus is based on 13 base relations. Since 12 of these relations are simply inverses of each other (for example the inverse of x precedes y is y is preceded by x) only 7 relations are implemented in EInterval which are:

    1. precedes: interval 1 precedes interval 2 if interval 1 end time < interval 2 begin time.
    2. meets: interval 1 meets interval 2 if if interval 1 end time equals interval 2 begin time.
    3. overlaps: interval 1 overlaps interval 2 if interval 1 begin time < interval 2 begin time and interval 1 end time < interval 2 end time.
    4. contains: interval 1 contains interval 2 if interval 1 begin time < interval 2 begin time and interval 1 end time > interval 2 end time.
    5. starts: interval 1 starts interval 2 if interval 1 begin time equals interval 2 begin time and interval 1 end time < interval 2 end time.
    6. finishes: interval 1 finishes interval 2 if interval 1 begin time > interval 2 begin time and interval 1 end time equals interval 2 end time.
    7. equals: interval 1 begin and end times equal interval 2 begin and end times.

    Note: interval algebra methods below are based solely on the end point times and do not take clusivity into account.

    Author:
    Charles W. Rapp
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  EInterval.Builder
      EInterval instances may be created only by using a Builder instance.
      static class  EInterval.Clusivity
      Specifies whether an end point is inclusive or exclusive.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static EInterval.Builder builder()
      Returns a new EInterval builder instance which is used to create an EInterval object.
      boolean contains​(EInterval interval)
      contains: Returns true if: this EInterval begin time < interval begin time and this EInterval end time > interval end time.
      boolean equals​(java.lang.Object o)
      equals: Returns true if: o is the same EInterval instance as this interval or o is a non-null EInterval instance with the same end points and clusivities as this EInterval instance.
      boolean finishes​(EInterval interval)
      finishes: Returns true if this interval starts after intervaL buts ends at the same time.
      int hashCode()
      Returns hash code based on end point times and clusivities.
      boolean meets​(EInterval interval)
      meets: Returns true if this EInterval end time equals interval begin time.
      boolean overlaps​(EInterval interval)
      overlaps: Returns true if: this EInterval end time is > interval's begin time, this EInterval end time is < interval's end time, and this EInterval begin time is < interval's begin time.
      boolean precedes​(EInterval interval)
      precedes: Returns true if this EInterval end time is < interval begin time.
      boolean starts​(EInterval interval)
      starts: Returns true if this interval starts at the same time as interval but ends before.
      java.lang.String toString()
      Returns textual representation of end point times and clusivities.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • beginTime

        public final java.time.Instant beginTime
        Interval begin time.
      • beginClusivity

        public final EInterval.Clusivity beginClusivity
        Interval begin time clusivity.
      • endTime

        public final java.time.Instant endTime
        Interval end time.
    • Method Detail

      • toString

        public java.lang.String toString()
        Returns textual representation of end point times and clusivities. Uses default Instant time format.
        Overrides:
        toString in class java.lang.Object
        Returns:
        interval as text.
      • equals

        public boolean equals​(java.lang.Object o)
        equals: Returns true if:
        • o is the same EInterval instance as this interval or
        • o is a non-null EInterval instance with the same end points and clusivities as this EInterval instance.
        Otherwise returns false.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - comparison object.
        Returns:
        true if o is a non-null EInterval instance whose end points are equal and have the same clusivities.
      • hashCode

        public int hashCode()
        Returns hash code based on end point times and clusivities.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        hash code based on end point times and clusivities.
      • precedes

        public boolean precedes​(EInterval interval)
        precedes: Returns true if this EInterval end time is < interval begin time.

        Note that this comparison is based only on time and does not take clusivity into account.

        Parameters:
        interval - comparison time interval.
        Returns:
        true if this EInterval precedes interval and false otherwise.
      • meets

        public boolean meets​(EInterval interval)
        meets: Returns true if this EInterval end time equals interval begin time.

        Note that this comparison is based only on time and does not take clusivity into account.

        Parameters:
        interval - comparison time interval.
        Returns:
        true if this EInterval meets interval and false otherwise.
      • overlaps

        public boolean overlaps​(EInterval interval)
        overlaps: Returns true if:
        • this EInterval end time is > interval's begin time,
        • this EInterval end time is < interval's end time, and
        • this EInterval begin time is < interval's begin time.

        Note that this comparison is based only on time and does not take clusivity into account.

        Parameters:
        interval - comparison time interval.
        Returns:
        true if this EInterval overlaps interval and false otherwise.
      • contains

        public boolean contains​(EInterval interval)
        contains: Returns true if:
        • this EInterval begin time < interval begin time and
        • this EInterval end time > interval end time.
        In short, this interval contains the given argument interval.

        Note that this comparison is based only on time and does not take clusivity into account.

        Parameters:
        interval - comparison time interval.
        Returns:
        true if this interval begins before interval and ends after.
      • starts

        public boolean starts​(EInterval interval)
        starts: Returns true if this interval starts at the same time as interval but ends before. That is:
        • this EInterval begin time equals interval begin time and
        • this EInterval end time < interval end time.

        Note that this comparison is based only on time and does not take clusivity into account.

        Parameters:
        interval - comparison time interval.
        Returns:
        true if this interval starts at the same time as interval but ends before.
      • finishes

        public boolean finishes​(EInterval interval)
        finishes: Returns true if this interval starts after intervaL buts ends at the same time. That is:
        • this EInterval begin time > interval begin time and
        • this EInterval end time equals interval end time.

        Note that this comparison is based only on time and does not take clusivity into account.

        Parameters:
        interval - comparison time interval.
        Returns:
        true if this interval starts after intervaL buts ends at the same time.
      • builder

        public static EInterval.Builder builder()
        Returns a new EInterval builder instance which is used to create an EInterval object. It is recommended that a new builder be used when creating an EInterval instance and not re-use a Builder to create multiple intervals.
        Returns:
        interval builder instance.