@Test public void testCompareTo() throws ParseException { final TimeValue tv1 = TimeValue.ofMilliseconds(1000L); final TimeValue tv2 = TimeValue.ofMilliseconds(1001L); final TimeValue tv3 = TimeValue.ofMilliseconds(1000L); final TimeValue tv4 = TimeValue.ofSeconds(1L); final TimeValue tv5 = TimeValue.ofSeconds(60L); final TimeValue tv6 = TimeValue.ofMinutes(1L); Assert.assertThat(tv1.compareTo(tv1) == 0, CoreMatchers.equalTo(true)); Assert.assertThat(tv1.compareTo(tv2) < 0, CoreMatchers.equalTo(true)); Assert.assertThat(tv1.compareTo(tv3) == 0, CoreMatchers.equalTo(true)); Assert.assertThat(tv1.compareTo(tv4) == 0, CoreMatchers.equalTo(true)); Assert.assertThat(tv1.compareTo(tv5) < 0, CoreMatchers.equalTo(true)); Assert.assertThat(tv6.compareTo(tv5) == 0, CoreMatchers.equalTo(true)); Assert.assertThat(tv6.compareTo(tv4) > 0, CoreMatchers.equalTo(true)); try { tv1.compareTo(null); Assert.fail("NullPointerException expected"); } catch (final NullPointerException expected) { } }
@Override public int compareTo(final TimeValue other) { final TimeUnit targetTimeUnit = min(other.getTimeUnit()); return Long.compare(convert(targetTimeUnit), other.convert(targetTimeUnit)); }
TimeValue implements Comparable<TimeValue> { @Override public int compareTo(final TimeValue other) { final TimeUnit targetTimeUnit = min(other.getTimeUnit()); return Long.compare(convert(targetTimeUnit), other.convert(targetTimeUnit)); } }
TimeValue implements Comparable<TimeValue> { @Override public int compareTo(final TimeValue other) { final TimeUnit targetTimeUnit = min(other.getTimeUnit()); return Long.compare(convert(targetTimeUnit), other.convert(targetTimeUnit)); } TimeValue(final long duration, final TimeUnit timeUnit); }
TimeValue implements Comparable<TimeValue> { @Override public int compareTo(final TimeValue other) { final TimeUnit targetTimeUnit = min(other.getTimeUnit()); return Long.compare(convert(targetTimeUnit), other.convert(targetTimeUnit)); } TimeValue(final long duration, final TimeUnit timeUnit); static int asBoundInt(final long value); static T defaultsTo(final T timeValue, final T defaultValue); static TimeValue defaultsToNegativeOneMillisecond(final TimeValue timeValue); static TimeValue defaultsToNegativeOneSecond(final TimeValue timeValue); static TimeValue defaultsToZeroMilliseconds(final TimeValue timeValue); static boolean isNonNegative(final TimeValue timeValue); static boolean isPositive(final TimeValue timeValue); static TimeValue of(final long duration, final TimeUnit timeUnit); static TimeValue ofDays(final long days); static TimeValue ofHours(final long hours); static TimeValue ofMicroseconds(final long microseconds); static TimeValue ofMilliseconds(final long millis); static TimeValue ofMinutes(final long minutes); static TimeValue ofNanoseconds(final long nanoseconds); static TimeValue ofSeconds(final long seconds); static TimeValue parse(final String value); long convert(final TimeUnit targetTimeUnit); @Override boolean equals(final Object obj); TimeValue divide(final long divisor); TimeValue divide(final long divisor, final TimeUnit targetTimeUnit); long getDuration(); TimeUnit getTimeUnit(); @Override int hashCode(); TimeValue min(final TimeValue other); void sleep(); void timedJoin(final Thread thread); void timedWait(final Object obj); long toDays(); long toHours(); long toMicroseconds(); long toMilliseconds(); int toMillisecondsIntBound(); long toMinutes(); long toNanoseconds(); long toSeconds(); int toSecondsIntBound(); @Override int compareTo(final TimeValue other); @Override String toString(); Timeout toTimeout(); }
TimeValue implements Comparable<TimeValue> { @Override public int compareTo(final TimeValue other) { final TimeUnit targetTimeUnit = min(other.getTimeUnit()); return Long.compare(convert(targetTimeUnit), other.convert(targetTimeUnit)); } TimeValue(final long duration, final TimeUnit timeUnit); static int asBoundInt(final long value); static T defaultsTo(final T timeValue, final T defaultValue); static TimeValue defaultsToNegativeOneMillisecond(final TimeValue timeValue); static TimeValue defaultsToNegativeOneSecond(final TimeValue timeValue); static TimeValue defaultsToZeroMilliseconds(final TimeValue timeValue); static boolean isNonNegative(final TimeValue timeValue); static boolean isPositive(final TimeValue timeValue); static TimeValue of(final long duration, final TimeUnit timeUnit); static TimeValue ofDays(final long days); static TimeValue ofHours(final long hours); static TimeValue ofMicroseconds(final long microseconds); static TimeValue ofMilliseconds(final long millis); static TimeValue ofMinutes(final long minutes); static TimeValue ofNanoseconds(final long nanoseconds); static TimeValue ofSeconds(final long seconds); static TimeValue parse(final String value); long convert(final TimeUnit targetTimeUnit); @Override boolean equals(final Object obj); TimeValue divide(final long divisor); TimeValue divide(final long divisor, final TimeUnit targetTimeUnit); long getDuration(); TimeUnit getTimeUnit(); @Override int hashCode(); TimeValue min(final TimeValue other); void sleep(); void timedJoin(final Thread thread); void timedWait(final Object obj); long toDays(); long toHours(); long toMicroseconds(); long toMilliseconds(); int toMillisecondsIntBound(); long toMinutes(); long toNanoseconds(); long toSeconds(); int toSecondsIntBound(); @Override int compareTo(final TimeValue other); @Override String toString(); Timeout toTimeout(); static final TimeValue MAX_VALUE; static final TimeValue NEG_ONE_MILLISECOND; static final TimeValue NEG_ONE_SECOND; static final TimeValue ZERO_MILLISECONDS; }