Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
1 package org.apidesign.cloneproblem;
6 /** Quiz: Anyone can come up with a JUnit test to generate
7 * {@link NullPointerException} directly from the code of
8 * the <code>Interval</code> class?
10 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
12 public final class Interval {
13 private final Date from, to;
15 /** Constructs interval between two dates.
17 * @param from the 'sooner' date
18 * @param to the 'later' date
19 * @throws IllegalArgumentException
20 * if <code>from</code> is not less then <code>to</code>
22 public Interval(Date from, Date to) {
24 throw new IllegalArgumentException("'from' cannot be null!");
27 throw new IllegalArgumentException("'to' cannot be null!");
29 // shield us from Date's mutability
30 this.from = (Date) from.clone();
31 this.to = (Date)to.clone();
32 if (from.compareTo(to) >= 0) {
33 throw new IllegalArgumentException(
34 "'from' must be lower than 'to'!"
39 /** The length of the interval in milliseconds
41 * @return amount of milliseconds between 'from' and 'to' dates.
43 public long getLength() {
44 return to.getTime() - from.getTime();