@@ -129,7 +129,7 @@ public Timeout asTimeout() {
129
129
* timeout {@link #isInfinite()} before calling.
130
130
*/
131
131
private long remaining (final TimeUnit unit ) {
132
- if (nanos == null ) {
132
+ if (isInfinite () ) {
133
133
throw new AssertionError ("Infinite TimePoints have infinite remaining time" );
134
134
}
135
135
long remaining = nanos - currentNanos ();
@@ -146,7 +146,7 @@ private long remaining(final TimeUnit unit) {
146
146
* @see #durationSince(TimePoint)
147
147
*/
148
148
public Duration elapsed () {
149
- if (nanos == null ) {
149
+ if (isInfinite () ) {
150
150
throw new AssertionError ("No time can elapse since an infinite TimePoint" );
151
151
}
152
152
return Duration .ofNanos (currentNanos () - nanos );
@@ -160,13 +160,13 @@ public Duration elapsed() {
160
160
* @see #elapsed()
161
161
*/
162
162
Duration durationSince (final TimePoint t ) {
163
- if (nanos == null ) {
163
+ if (this . isInfinite () ) {
164
164
throw new AssertionError ("this timepoint is infinite, with no duration since" );
165
165
}
166
- if (t .nanos == null ) {
166
+ if (t .isInfinite () ) {
167
167
throw new AssertionError ("the other timepoint is infinite, with no duration until" );
168
168
}
169
- return Duration .ofNanos (nanos - t .nanos );
169
+ return Duration .ofNanos (nanos - assertNotNull ( t .nanos ) );
170
170
}
171
171
172
172
/**
@@ -189,7 +189,7 @@ public TimePoint timeoutAfterOrInfiniteIfNegative(final long timeoutValue, final
189
189
* @param duration A duration that may also be {@linkplain Duration#isNegative() negative}.
190
190
*/
191
191
TimePoint add (final Duration duration ) {
192
- if (nanos == null ) {
192
+ if (isInfinite () ) {
193
193
throw new AssertionError ("No time can be added to an infinite TimePoint" );
194
194
}
195
195
long durationNanos = duration .toNanos ();
@@ -205,12 +205,12 @@ TimePoint add(final Duration duration) {
205
205
public int compareTo (final TimePoint t ) {
206
206
if (Objects .equals (nanos , t .nanos )) {
207
207
return 0 ;
208
- } else if (nanos == null ) {
208
+ } else if (this . isInfinite () ) {
209
209
return 1 ;
210
- } else if (t .nanos == null ) {
210
+ } else if (t .isInfinite () ) {
211
211
return -1 ;
212
212
}
213
- return Long .signum (nanos - t .nanos );
213
+ return Long .signum (nanos - assertNotNull ( t .nanos ) );
214
214
}
215
215
216
216
@ Override
@@ -232,9 +232,9 @@ public int hashCode() {
232
232
233
233
@ Override
234
234
public String toString () {
235
- long remainingMs = nanos == null
236
- ? - 1
237
- : TimeUnit .MILLISECONDS .convert (currentNanos () - nanos , NANOSECONDS );
235
+ String remainingMs = isInfinite ()
236
+ ? "infinite"
237
+ : "" + TimeUnit .MILLISECONDS .convert (currentNanos () - nanos , NANOSECONDS );
238
238
return "TimePoint{"
239
239
+ "nanos=" + nanos
240
240
+ "remainingMs=" + remainingMs
0 commit comments