public int compareTo(TemporalPrimitive that) { if (that == null) throw new IllegalArgumentException("Provided temporal object is null"); final RelativePosition pos = this.relativePosition(that); if (pos == null) throw new ClassCastException("The provided object cannot be compared to this one"); if (pos == RelativePosition.BEFORE) return -1; if (pos == RelativePosition.AFTER) return +1; if (pos == RelativePosition.EQUALS) return 0; // TODO rethink this since it looks like it is a pretty dirty hack if (this instanceof Period && that instanceof Instant || this instanceof Instant && that instanceof Period) { if (pos == RelativePosition.ENDED_BY || pos == RelativePosition.BEGUN_BY || pos == RelativePosition.CONTAINS) return 0; } // TODO rethink this since it looks like it is a pretty dirty hack if (this instanceof Period && that instanceof Period) { if (pos == RelativePosition.MEETS) return -1; if (pos == RelativePosition.BEGINS) return -1; if (pos == RelativePosition.BEGUN_BY) return +1; if (pos == RelativePosition.ENDS) return +1; if (pos == RelativePosition.ENDED_BY) return -1; if (pos == RelativePosition.OVERLAPS) return -1; if (pos == RelativePosition.OVERLAPPED_BY) return +1; if (pos == RelativePosition.DURING || pos == RelativePosition.CONTAINS || pos == RelativePosition.EQUALS) return 0; } throw new IllegalStateException("Unable to compare the provided object with this one"); }
/** Test comparison of Instants */ @Test public void testCompare() { assertEquals( -1, ((DefaultTemporalPrimitive) temporalGeomericPrimitive1) .compareTo(temporalGeomericPrimitive2)); assertEquals( 0, ((DefaultTemporalPrimitive) temporalGeomericPrimitive1) .compareTo(temporalGeomericPrimitive1)); assertEquals( 0, ((DefaultTemporalPrimitive) temporalGeomericPrimitive2) .compareTo(temporalGeomericPrimitive2)); } }
public int compareTo(TemporalPrimitive that) { if (that==null) throw new IllegalArgumentException("Provided temporal object is null"); final RelativePosition pos= this.relativePosition(that); if(pos==null) throw new ClassCastException("The provided object cannot be compared to this one");
public int compareTo(TemporalPrimitive that) { if (that==null) throw new IllegalArgumentException("Provided temporal object is null"); final RelativePosition pos= this.relativePosition(that); if(pos==null) throw new ClassCastException("The provided object cannot be compared to this one");