TimeCompareUtils { public static int compareEndWithBegin( final TimeGeometricPrimitive a, final TimeGeometricPrimitive b ) { final Temporal endA = new TemporalConverter().convert( end( a ) ); final Temporal beginB = new TemporalConverter().convert( begin( b ) ); if ( endA == null || beginB == null ) return 0; return endA.compareTo( beginB ); }  static int compareBegin( final TimeGeometricPrimitive a, final TimeGeometricPrimitive b ); static int compareEnd( final TimeGeometricPrimitive a, final TimeGeometricPrimitive b ); static int compareBeginWithEnd( final TimeGeometricPrimitive a, final TimeGeometricPrimitive b ); static int compareEndWithBegin( final TimeGeometricPrimitive a, final TimeGeometricPrimitive b ); static TimePosition begin( final TimeGeometricPrimitive t ); static TimePosition end( final TimeGeometricPrimitive t );  }
@Test(expected = NullPointerException.class) public void evaluateInstantInstant_BothNull() { compareEndWithBegin( null, null ); }
@Test(expected = NullPointerException.class) public void evaluateInstantInstant_FirstNull() { compareEndWithBegin( null, instant( "2014-01-01" ) ); }
@Test(expected = NullPointerException.class) public void evaluateInstantInstant_SecondNull() { compareEndWithBegin( instant( "2014-01-01" ), null ); }
@Test public void evaluateInstantInstant() { assertThat( compareEndWithBegin( instant( "2014-01-01" ), instant( "2014-01-01" ) ), is( 0 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:01" ), instant( "2014-01-01T00:00:01" ) ), is( 0 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:01.000" ), instant( "2014-01-01T00:00:01.000" ) ), is( 0 ) ); assertThat( compareEndWithBegin( instant( "INDETERMINATE" ), instant( "INDETERMINATE" ) ), is( 0 ) ); assertThat( compareEndWithBegin( instant( "INDETERMINATE" ), instant( "2014-01-01T00:00:01" ) ), is( 0 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:01" ), instant( "INDETERMINATE" ) ), is( 0 ) ); assertThat( compareEndWithBegin( instant( "2015-01-01" ), instant( "2014-01-01" ) ), is( 1 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:02" ), instant( "2014-01-01T00:00:01" ) ), is( 1 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:01.001" ), instant( "2014-01-01T00:00:01.000" ) ), is( 1 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01" ), instant( "2015-01-01" ) ), is( -1 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:01" ), instant( "2014-01-01T00:00:02" ) ), is( -1 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:01.000" ), instant( "2014-01-01T00:00:01.001" ) ), is( -1 ) ); }
@Test public void evaluateInstantPeriod() { assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:01" ), period( "2014-01-01T00:00:01", "2014-01-01T00:00:01" ) ), is( 0 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:01" ), period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ) ), is( 0 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:02" ), period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ) ), is( 1 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:03" ), period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ) ), is( 1 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:04" ), period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ) ), is( 1 ) ); assertThat( compareEndWithBegin( instant( "2014-01-01T00:00:00" ), period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ) ), is( -1 ) ); }
@Test public void evaluatePeriodInstant() { assertThat( compareEndWithBegin( period( "2014-01-01T00:00:01", "2014-01-01T00:00:01" ), instant( "2014-01-01T00:00:01" ) ), is( 0 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ), instant( "2014-01-01T00:00:03" ) ), is( 0 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ), instant( "2014-01-01T00:00:02" ) ), is( 1 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ), instant( "2014-01-01T00:00:01" ) ), is( 1 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ), instant( "2014-01-01T00:00:00" ) ), is( 1 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:01", "2014-01-01T00:00:03" ), instant( "2014-01-01T00:00:04" ) ), is( -1 ) ); }
@Test public void evaluatePeriodPeriod() { assertThat( compareEndWithBegin( period( "2014-01-01T00:00:01", "2014-01-01T00:00:01" ), period( "2014-01-01T00:00:01", "2014-01-01T00:00:01" ) ), is( 0 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:00", "2014-01-01T00:00:01" ), period( "2014-01-01T00:00:01", "2014-01-01T00:00:02" ) ), is( 0 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:02", "2014-01-01T00:00:03" ), period( "2014-01-01T00:00:00", "2014-01-01T00:00:01" ) ), is( 1 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:02", "2014-01-01T00:00:03" ), period( "2014-01-01T00:00:01", "2014-01-01T00:00:02" ) ), is( 1 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:02", "2014-01-01T00:00:03" ), period( "2014-01-01T00:00:02", "2014-01-01T00:00:03" ) ), is( 1 ) ); assertThat( compareEndWithBegin( period( "2014-01-01T00:00:01", "2014-01-01T00:00:02" ), period( "2014-01-01T00:00:03", "2014-01-01T00:00:04" ) ), is( -1 ) ); }