Class TimeInterval
java.lang.Object
com.amalgamasimulation.core.intervals.Interval
com.amalgamasimulation.core.scheduling.TimeInterval
- All Implemented Interfaces:
IntervalLike,Comparable<IntervalLike>
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:
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionTimeInterval(double beginTime, double endTime) Creates a new instance of a time interval with the specified begin time and end time. -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturns the begin time of this interval, possibly infinite.booleancontains(TimeInterval otherInterval) Checks if this time interval contains (i.e.doubleduration()Returns the duration of this time interval, i.e.doubleendTime()Returns the end time of this interval, possibly infinite.List<? extends TimeInterval> getExclusion(TimeInterval excludedInterval) Deprecated, for removal: This API element is subject to removal in a future version.getIntersection(TimeInterval otherInterval) Deprecated, for removal: This API element is subject to removal in a future version.UseInterval.intersection(com.amalgamasimulation.core.intervals.IntervalLike)and, if needed,IntervalLike.isZeroLength()insteadbooleanintersectsWith(TimeInterval otherInterval) Checks if this time interval intersects (i.e.Methods inherited from class com.amalgamasimulation.core.intervals.Interval
asIntervalSet, contains, equals, equalsWithinEpsilon, equalsWithinEpsilon, exclusion, hashCode, hasNonZeroIntersectionWith, intersection, isEmpty, isUniverse, leftSubset, max, min, of, of, rightSubset, shift, size, toCodeString, toString, unionMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface com.amalgamasimulation.core.intervals.IntervalLike
compareTo, complement, contains, isFinite, isZeroLength, length
-
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
RuntimeExceptionis thrown.Infinite begin and end times are allowed. NaNs are not allowed.
- Parameters:
beginTime- specified begin time of this intervalendTime- 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 expressionendTime() - beginTime(). The duration can potentially be infinite.- Returns:
- duration of this time interval
- See Also:
-
contains
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:
trueif this time interval contains the specified one,falseotherwise
-
intersectsWith
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:
trueif this time interval intersects with the specified one,falseotherwise
-
getIntersection
Deprecated, for removal: This API element is subject to removal in a future version.UseInterval.intersection(com.amalgamasimulation.core.intervals.IntervalLike)and, if needed,IntervalLike.isZeroLength()insteadReturns theTimeIntervalthat is the intersection of this interval and the other specified interval, ornullif this intersection is empty.- Parameters:
otherInterval- other specified time interval- Returns:
TimeIntervalthat is the intersection of this interval and the other specified interval, ornull
-
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.UseInterval.exclusion(com.amalgamasimulation.core.intervals.IntervalLike)and, if needed,IntervalLike.isZeroLength()insteadReturns 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
-
Interval.exclusion(com.amalgamasimulation.core.intervals.IntervalLike)and, if needed,IntervalLike.isZeroLength()instead