public Period intersection(Period p2, int granularity) throws TemporalException { Period result; if (startInstant.equals(p2.getStartInstant(), granularity)) { // They must intersect if (finishInstant.after(p2.getFinishInstant(), granularity)) { result = new Period(temporal, startInstant, p2.getFinishInstant(), granularity); } else { result = new Period(temporal, startInstant, finishInstant, granularity); } // if } else if (startInstant.before( p2.getStartInstant(), granularity)) { // p2 starts after this Period if (finishInstant.after(p2.getStartInstant(), granularity)) { // They intersect if (finishInstant.before(p2.getFinishInstant(), granularity)) { result = new Period(temporal, p2.getStartInstant(), finishInstant, granularity); } else { result = new Period(temporal, p2.getStartInstant(), p2.getFinishInstant(), granularity); } // if } else { result = null; } // if } else { // p2 start before this Period if (p2.getFinishInstant().after(startInstant, granularity)) { // They intersect if (finishInstant.before(p2.getFinishInstant(), granularity)) { result = new Period(temporal, startInstant, finishInstant, granularity); } else { result = new Period(temporal, startInstant, p2.getFinishInstant(), granularity); } // if } else { result = null; } // if } // if return result; } // intersection
private void orderCheck() throws TemporalException { if (startInstant.after(finishInstant, Temporal.FINEST)) throw new TemporalException( "start must be before or equal to finish in a period: (" + startInstant.toString(Temporal.FINEST) + ", " + finishInstant.toString(Temporal.FINEST) + ")"); } // orderCheck