A class representing an interval with Dates as start and end points.
| 6 | * A class representing an interval with Dates as start and end points. |
| 7 | */ |
| 8 | public class DateInterval extends Interval<Date> { |
| 9 | |
| 10 | /** |
| 11 | * Instantiates an interval extending from positive infinity to negative |
| 12 | * infinity and thus containing all Dates. |
| 13 | */ |
| 14 | public DateInterval(){} |
| 15 | |
| 16 | /** |
| 17 | * Instantiates a new bounded interval. |
| 18 | * |
| 19 | * @param start The start date of the interval |
| 20 | * @param end The end date of the interval. |
| 21 | * @param type Description of whether the interval is open/closed at one or both |
| 22 | * of its ends. See {@link Bounded the documentation of the Bounded enum} |
| 23 | * for more information on the different possibilities. |
| 24 | */ |
| 25 | public DateInterval(Date start, Date end, Bounded type){ |
| 26 | super(start, end, type); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Instantiates a new unbounded interval - an interval that extends to positive or |
| 31 | * negative infinity. The interval will be bounded by either the start point |
| 32 | * or the end point and unbounded in the other point. |
| 33 | * |
| 34 | * @param value The bounding date for either the start or the end point. |
| 35 | * @param type Describes whether the interval extends to positive or negative infinity, |
| 36 | * as well as if it is open or closed at the bounding point. See {@link Unbounded |
| 37 | * the Unbounded enum} for description of the different possibilities. |
| 38 | */ |
| 39 | public DateInterval(Date value, Unbounded type){ |
| 40 | super(value, type); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | protected Interval<Date> create() { |
| 45 | return new DateInterval(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Determines the center of the interval. |
| 50 | * <p> |
| 51 | * Similarly to the class {@link IntegerInterval}, it assumes that unbounded intervals |
| 52 | * are bounded by Dates with timestamps Long.MIN_VALUE and/or Long.MAX_VALUE. The center |
| 53 | * of an unbounded interval is computed accordingly. |
| 54 | * </p> |
| 55 | * |
| 56 | * @return The center of the interval. |
| 57 | */ |
| 58 | @Override |
| 59 | public Date getMidpoint() { |
| 60 | if (isEmpty()) |
| 61 | return null; |
| 62 | long start = getStart() == null ? new Date(Long.MIN_VALUE).getTime() : getStart().getTime(); |
| 63 | long end = getEnd() == null ? new Date(Long.MAX_VALUE).getTime() : getEnd().getTime(); |
| 64 | |
| 65 | // If the calculation would return the start point and the start point |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…