SimpleXTime implements XTime<F> { @Override public final int compareTo( final XTime<F> other) { LOGGER.trace("begin {}.compareTo({})", new Object[] { getClass().getSimpleName(), other }); final int rval; if (other == null) { throw new NullPointerException("cannot compare to a null"); } rval = new CompareToBuilder() .append(_tick, other.getTick()) .append(_phase, other.getPhase()) .toComparison(); LOGGER.trace("will return: {}", rval); LOGGER.trace("end {}.compareTo()", getClass().getSimpleName()); return rval; } SimpleXTime(
            final long tick,
            final F phase); @Override final long getTick(); @Override final F getPhase(); @Override final int compareTo(
            final XTime<F> other); @Override final boolean equals(
            final Object obj); @Override final int hashCode(); @Override final String toString();  }
@Test public final void compareToIdentical() { final SimpleXTime<PhaseImpl> time = new SimpleXTime<PhaseImpl>(1, PhaseImpl.PHASE_1); assertThat(time.compareTo(time), is(0)); }
@Test public final void compareToSameTime() { final SimpleXTime<PhaseImpl> time = new SimpleXTime<PhaseImpl>(1, PhaseImpl.PHASE_1); final SimpleXTime<PhaseImpl> sameTime = new SimpleXTime<PhaseImpl>(1, PhaseImpl.PHASE_1); assertThat(time.compareTo(sameTime), is(0)); }
@Test public final void compareToSmallerTick() { final SimpleXTime<PhaseImpl> time = new SimpleXTime<PhaseImpl>(1, PhaseImpl.PHASE_1); final SimpleXTime<PhaseImpl> smallerTickTime = new SimpleXTime<PhaseImpl>( 0, PhaseImpl.PHASE_1); assertThat(time.compareTo(smallerTickTime), is(greaterThan(0))); }
@Test public final void compareToSmallerPhase() { final SimpleXTime<PhaseImpl> time = new SimpleXTime<PhaseImpl>(1, PhaseImpl.PHASE_2); final SimpleXTime<PhaseImpl> smallerPhaseTime = new SimpleXTime<PhaseImpl>( 1, PhaseImpl.PHASE_1); assertThat(time.compareTo(smallerPhaseTime), is(greaterThan(0))); }
@Test public final void compareToLargerTick() { final SimpleXTime<PhaseImpl> time = new SimpleXTime<PhaseImpl>(1, PhaseImpl.PHASE_1); final SimpleXTime<PhaseImpl> largerTickTime = new SimpleXTime<PhaseImpl>( 2, PhaseImpl.PHASE_1); assertThat(time.compareTo(largerTickTime), is(lessThan(0))); }
@Test public final void compareToLargerPhase() { final SimpleXTime<PhaseImpl> time = new SimpleXTime<PhaseImpl>(1, PhaseImpl.PHASE_1); final SimpleXTime<PhaseImpl> largerPhaseTime = new SimpleXTime<PhaseImpl>( 1, PhaseImpl.PHASE_2); assertThat(time.compareTo(largerPhaseTime), is(lessThan(0))); }
@Test(expectedExceptions = { NullPointerException.class }) public final void compareToNull() { new SimpleXTime<PhaseImpl>(1, PhaseImpl.PHASE_1).compareTo(null); }