Esempio n. 1
0
  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
Esempio n. 2
0
 public boolean couldBeInstant() throws TemporalException {
   return startInstant.equals(finishInstant, Temporal.FINEST);
 } // couldBeInstant