Class TimeInterval

java.lang.Object
com.amalgamasimulation.core.intervals.Interval
com.amalgamasimulation.core.scheduling.TimeInterval
All Implemented Interfaces:
IntervalLike, Comparable<IntervalLike>
Direct Known Subclasses:
Gap, Slot

public class TimeInterval extends Interval
Class representing an interval on a time axis. The interval is determined by begin time and end time. The class provides methods to calculate the duration of the interval, intersection of intervals and exclusion of intervals.

The class is also used many classes of scheduling API.

Author:
Andrey Malykhanov
See Also:
  • Constructor Details

    • TimeInterval

      public TimeInterval(double beginTime, double endTime)
      Creates a new instance of a time interval with the specified begin time and end time.

      The interval should have non-negative duration, i.e. end time should be >= than begin begin time. Otherwise, a RuntimeException is thrown.

      Infinite begin and end times are allowed. NaNs are not allowed.

      Parameters:
      beginTime - specified begin time of this interval
      endTime - specified end time of this interval
  • Method Details

    • beginTime

      public double beginTime()
      Returns the begin time of this interval, possibly infinite.
      Returns:
      begin time of this interval
    • endTime

      public double endTime()
      Returns the end time of this interval, possibly infinite.

      Warning:In case of applying "open statistics slots" pattern, do not override this method, override Interval.max() method instead.

      Returns:
      end time of this interval
    • duration

      public double duration()
      Returns the duration of this time interval, i.e. result of the expression endTime() - beginTime(). The duration can potentially be infinite.
      Returns:
      duration of this time interval
      See Also:
    • contains

      public boolean contains(TimeInterval otherInterval)
      Checks if this time interval contains (i.e. fully encloses) the other specified time interval.

      The comparisons inside this method are made using the default comparator (see Compare).

      Parameters:
      otherInterval - other specified time interval
      Returns:
      true if this time interval contains the specified one, false otherwise
    • intersectsWith

      public boolean intersectsWith(TimeInterval otherInterval)
      Checks if this time interval intersects (i.e. has non-zero intersection) with the other specified time interval.

      The comparisons inside this method are made using the default comparator (see Compare).

      Parameters:
      otherInterval - other specified time interval
      Returns:
      true if this time interval intersects with the specified one, false otherwise
    • getIntersection

      @Deprecated(forRemoval=true) public TimeInterval getIntersection(TimeInterval otherInterval)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the TimeInterval that is the intersection of this interval and the other specified interval, or null if this intersection is empty.
      Parameters:
      otherInterval - other specified time interval
      Returns:
      TimeInterval that is the intersection of this interval and the other specified interval, or null
    • getExclusion

      @Deprecated(forRemoval=true) public List<? extends TimeInterval> getExclusion(TimeInterval excludedInterval)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns a list of at most 2 intervals that is equal to this interval with the specified interval excluded.

    • If the specified other interval does not intersect with this one, returns a list containing this interval only
    • If the specified interval is fully inside this one, returns a list of 2 intervals ordered by begin time in ascending order
    • If the specified interval is not fully inside this one, returns a list of 1 interval, as the exclusion means cutting off a part either from right or left side of this interval
    • If the specified interval fully encloses this one, return an empty list
    • Parameters:
      excludedInterval - the interval to be excluded from this one
      Returns:
      list of at most 2 intervals representing exclusion of this interval and the specified interval