338 * @return true if this Duration is equivalent to Duration.INDEFINITE or Double.POSITIVE_INFINITY. 339 */ 340 public boolean isIndefinite() { 341 return millis == Double.POSITIVE_INFINITY; 342 } 343 344 /** 345 * Gets whether this Duration instance is Unknown. A Duration is Unknown 346 * if it equals Duration.UNKNOWN. 347 * @return true if this Duration is equivalent to Duration.UNKNOWN or Double.isNaN(millis) 348 */ 349 public boolean isUnknown() { 350 return Double.isNaN(millis); 351 } 352 353 /** 354 * Returns true if the specified duration is less than (<) this instance. 355 * INDEFINITE is treated as if it were positive infinity. 356 * 357 * @param other cannot be null 358 * @return true if millis < other.millis using double arithmetic 359 */ 360 public boolean lessThan(Duration other) { 361 return millis < other.millis; 362 } 363 364 /** 365 * Returns true if the specified duration is less than or equal to (<=) this instance. 366 * INDEFINITE is treated as if it were positive infinity. 367 * 368 * @param other cannot be null 369 * @return true if millis <= other.millis using double arithmetic 370 */ 371 public boolean lessThanOrEqualTo(Duration other) { 372 return millis <= other.millis; 373 } 374 375 /** 376 * Returns true if the specified duration is greater than (>) this instance. 377 * INDEFINITE is treated as if it were positive infinity. 378 * 379 * @param other cannot be null 380 * @return true if millis > other.millis using double arithmetic 381 */ 382 public boolean greaterThan(Duration other) { 383 return millis > other.millis; 384 } 385 386 /** 387 * Returns true if the specified duration is greater than or equal to (>=) this instance. 388 * INDEFINITE is treated as if it were positive infinity. 389 * 390 * @param other cannot be null 391 * @return true if millis >= other.millis using double arithmetic 392 */ 393 public boolean greaterThanOrEqualTo(Duration other) { 394 return millis >= other.millis; 395 } 396 397 /** 398 * Returns a string representation of this {@code Duration} object. 399 * @return a string representation of this {@code Duration} object. 400 */ 401 @Override public String toString() { 402 return isIndefinite() ? "INDEFINITE" : (isUnknown() ? "UNKNOWN" : millis + " ms"); 403 } 404 405 /** 406 * Compares durations represented by this object and the specified object. 407 * Returns a negative integer, zero, or a positive integer as this duration 408 * is less than, equal to, or greater than the specified duration. 409 * @param d the duration to be compared. 410 * @return a negative integer, zero, or a positive integer as this duration 411 * is less than, equal to, or greater than the specified duration. | 338 * @return true if this Duration is equivalent to Duration.INDEFINITE or Double.POSITIVE_INFINITY. 339 */ 340 public boolean isIndefinite() { 341 return millis == Double.POSITIVE_INFINITY; 342 } 343 344 /** 345 * Gets whether this Duration instance is Unknown. A Duration is Unknown 346 * if it equals Duration.UNKNOWN. 347 * @return true if this Duration is equivalent to Duration.UNKNOWN or Double.isNaN(millis) 348 */ 349 public boolean isUnknown() { 350 return Double.isNaN(millis); 351 } 352 353 /** 354 * Returns true if the specified duration is less than (<) this instance. 355 * INDEFINITE is treated as if it were positive infinity. 356 * 357 * @param other cannot be null 358 * @return true if millis < other.millis using double arithmetic 359 */ 360 public boolean lessThan(Duration other) { 361 return millis < other.millis; 362 } 363 364 /** 365 * Returns true if the specified duration is less than or equal to (<=) this instance. 366 * INDEFINITE is treated as if it were positive infinity. 367 * 368 * @param other cannot be null 369 * @return true if millis <= other.millis using double arithmetic 370 */ 371 public boolean lessThanOrEqualTo(Duration other) { 372 return millis <= other.millis; 373 } 374 375 /** 376 * Returns true if the specified duration is greater than (>) this instance. 377 * INDEFINITE is treated as if it were positive infinity. 378 * 379 * @param other cannot be null 380 * @return true if millis > other.millis using double arithmetic 381 */ 382 public boolean greaterThan(Duration other) { 383 return millis > other.millis; 384 } 385 386 /** 387 * Returns true if the specified duration is greater than or equal to (>=) this instance. 388 * INDEFINITE is treated as if it were positive infinity. 389 * 390 * @param other cannot be null 391 * @return true if millis >= other.millis using double arithmetic 392 */ 393 public boolean greaterThanOrEqualTo(Duration other) { 394 return millis >= other.millis; 395 } 396 397 /** 398 * Returns a string representation of this {@code Duration} object. 399 * @return a string representation of this {@code Duration} object. 400 */ 401 @Override public String toString() { 402 return isIndefinite() ? "INDEFINITE" : (isUnknown() ? "UNKNOWN" : millis + " ms"); 403 } 404 405 /** 406 * Compares durations represented by this object and the specified object. 407 * Returns a negative integer, zero, or a positive integer as this duration 408 * is less than, equal to, or greater than the specified duration. 409 * @param d the duration to be compared. 410 * @return a negative integer, zero, or a positive integer as this duration 411 * is less than, equal to, or greater than the specified duration. |