DefaultTemporalPrimitive extends DefaultTemporalObject implements TemporalPrimitive, TemporalOrder, Comparable<TemporalPrimitive> { public RelativePosition relativePosition(TemporalPrimitive other) { if (this instanceof Instant && other instanceof Instant) { Instant timeobject = (Instant) this; Instant instantOther = (Instant) other; if (timeobject.getPosition().getDate().before(instantOther.getPosition().getDate())) { return RelativePosition.BEFORE; } else { return (timeobject.getPosition().getDate().compareTo(instantOther.getPosition().getDate()) == 0) ? RelativePosition.EQUALS : RelativePosition.AFTER; } } else { if (this instanceof Period && other instanceof Instant) { Period timeobject = (Period) this; Instant instantarg = (Instant) other; if (timeobject.getEnding().getPosition().getDate().before(instantarg.getPosition().getDate())) { return RelativePosition.BEFORE; } else { if (timeobject.getEnding().getPosition().getDate().compareTo(instantarg.getPosition().getDate()) == 0) { return RelativePosition.ENDED_BY; } else { if (timeobject.getBeginning().getPosition().getDate().before(instantarg.getPosition().getDate()) && timeobject.getEnding().getPosition().getDate().after(instantarg.getPosition().getDate())) { return RelativePosition.CONTAINS; } else { return (timeobject.getBeginning().getPosition().getDate().compareTo(instantarg.getPosition().getDate()) == 0) ? RelativePosition.BEGUN_BY : RelativePosition.AFTER; } } } } else { if (this instanceof Instant && other instanceof Period) { Instant timeobject = (Instant) this; Period instantarg = (Period) other; if (instantarg.getEnding().getPosition().getDate().before(timeobject.getPosition().getDate())) { return RelativePosition.AFTER; } else { if (instantarg.getEnding().getPosition().getDate().compareTo(timeobject.getPosition().getDate()) == 0) { return RelativePosition.ENDS; } else { if (instantarg.getBeginning().getPosition().getDate().before(timeobject.getPosition().getDate()) && instantarg.getEnding().getPosition().getDate().after(timeobject.getPosition().getDate())) { return RelativePosition.DURING; } else { return (instantarg.getBeginning().getPosition().getDate().compareTo(timeobject.getPosition().getDate()) == 0) ? RelativePosition.BEGINS : RelativePosition.BEFORE; } } } } else { if (this instanceof Period && other instanceof Period) { Period timeobject = (Period) this; Period instantarg = (Period) other; if (timeobject.getEnding().getPosition().getDate().before(instantarg.getBeginning().getPosition().getDate())) { return RelativePosition.BEFORE; } else { if (timeobject.getEnding().getPosition().getDate().compareTo(instantarg.getBeginning().getPosition().getDate()) == 0) { return RelativePosition.MEETS; } else { if (timeobject.getBeginning().getPosition().getDate().before(instantarg.getBeginning().getPosition().getDate()) && timeobject.getEnding().getPosition().getDate().after(instantarg.getBeginning().getPosition().getDate()) && timeobject.getEnding().getPosition().getDate().before(instantarg.getEnding().getPosition().getDate())) { return RelativePosition.OVERLAPS; } else { if (timeobject.getBeginning().getPosition().getDate().compareTo(instantarg.getBeginning().getPosition().getDate()) == 0 && timeobject.getEnding().getPosition().getDate().before(instantarg.getEnding().getPosition().getDate())) { return RelativePosition.BEGINS; } else { if (timeobject.getBeginning().getPosition().getDate().compareTo(instantarg.getBeginning().getPosition().getDate()) == 0 && timeobject.getEnding().getPosition().getDate().after(instantarg.getEnding().getPosition().getDate())) { return RelativePosition.BEGUN_BY; } else { if (timeobject.getBeginning().getPosition().getDate().after(instantarg.getBeginning().getPosition().getDate()) && timeobject.getEnding().getPosition().getDate().before(instantarg.getEnding().getPosition().getDate())) { return RelativePosition.DURING; } else { if (timeobject.getBeginning().getPosition().getDate().before(instantarg.getBeginning().getPosition().getDate()) && timeobject.getEnding().getPosition().getDate().after(instantarg.getEnding().getPosition().getDate())) { return RelativePosition.CONTAINS; } else { if (timeobject.getBeginning().getPosition().getDate().compareTo(instantarg.getBeginning().getPosition().getDate()) == 0 && timeobject.getEnding().getPosition().getDate().compareTo(instantarg.getEnding().getPosition().getDate()) == 0) { return RelativePosition.EQUALS; } else { if (timeobject.getBeginning().getPosition().getDate().after(instantarg.getBeginning().getPosition().getDate()) && timeobject.getBeginning().getPosition().getDate().before(instantarg.getEnding().getPosition().getDate()) && timeobject.getEnding().getPosition().getDate().after(instantarg.getEnding().getPosition().getDate())) { return RelativePosition.OVERLAPPED_BY; } else { if (timeobject.getBeginning().getPosition().getDate().after(instantarg.getBeginning().getPosition().getDate()) && timeobject.getEnding().getPosition().getDate().compareTo(instantarg.getEnding().getPosition().getDate()) == 0) { return RelativePosition.ENDS; } else { if (timeobject.getBeginning().getPosition().getDate().before(instantarg.getBeginning().getPosition().getDate()) && timeobject.getEnding().getPosition().getDate().compareTo(instantarg.getEnding().getPosition().getDate()) == 0) { return RelativePosition.ENDED_BY; } else { return (timeobject.getBeginning().getPosition().getDate().compareTo(instantarg.getEnding().getPosition().getDate()) == 0) ? RelativePosition.MET_BY : RelativePosition.AFTER; } } } } } } } } } } } } else { return null; } } } } }  int compareTo(TemporalPrimitive that); RelativePosition relativePosition(TemporalPrimitive other);  }
@Test public void testRelativePosition() { TemporalPrimitive other; cal.set(2000, 0, 1); Position position = new DefaultPosition(cal.getTime()); other = new DefaultInstant(position); RelativePosition result = temporalPrimitive1.relativePosition(other); assertFalse(temporalPrimitive2.relativePosition(other).equals(result)); Instant instant1 = new DefaultInstant(new DefaultPosition(cal.getTime())); Instant instant2 = (DefaultInstant) temporalPrimitive2; other = new DefaultPeriod(instant1, instant2); result = temporalPrimitive1.relativePosition(other); assertFalse(temporalPrimitive2.relativePosition(other).equals(result)); temporalPrimitive1 = new DefaultPeriod(new DefaultInstant(position1), instant1); cal.set(2200, 9, 1); temporalPrimitive2 = new DefaultPeriod(instant2, new DefaultInstant(new DefaultPosition(cal.getTime()))); result = temporalPrimitive1.relativePosition(other); assertFalse(temporalPrimitive2.relativePosition(other).equals(result)); }
@Test public void testRelativePosition() { TemporalPrimitive other; cal.set(2000, 0, 1); Position position = new DefaultPosition(cal.getTime()); other = new DefaultInstant(position); RelativePosition result = temporalPrimitive1.relativePosition(other); assertFalse(temporalPrimitive2.relativePosition(other).equals(result)); Instant instant1 = new DefaultInstant(new DefaultPosition(cal.getTime())); Instant instant2 = (DefaultInstant) temporalPrimitive2; other = new DefaultPeriod(instant1, instant2); result = temporalPrimitive1.relativePosition(other); assertFalse(temporalPrimitive2.relativePosition(other).equals(result)); temporalPrimitive1 = new DefaultPeriod(new DefaultInstant(position1), instant1); cal.set(2020, 9, 1); temporalPrimitive2 = new DefaultPeriod(instant2, new DefaultInstant(new DefaultPosition(cal.getTime()))); result = temporalPrimitive1.relativePosition(other); assertFalse(temporalPrimitive2.relativePosition(other).equals(result)); }