code: public static <T extends Comparable<T>> Partition<T> intersect(Partition<T> p1, Partition<T> p2) throws MIDDException {
  
          if (p1.size() == 0 || p2.size() == 0) {
              return new Partition<T>();
          }
  
          List<Interval<T>> tempIntervals = combine(p1, p2);
  
          Interval<T> newInterval = null;
          Interval<T> superOfNewIntervalP1 = null;
          Interval<T> superOfNewIntervalP2 = null;
  
          // combine adjacent intervals which belong to the same type
          List<Interval<T>> outputPartition = new ArrayList<Interval<T>>();
  
          for (int i = 0; i < tempIntervals.size(); i++) {
              Interval<T> tempInterval = tempIntervals.get(i);
              Interval<T> superOfTempIntervalP1 = p1.getSuperInterval(tempInterval);
              Interval<T> superOfTempIntervalP2 = p2.getSuperInterval(tempInterval);
  
              // if it belongs to at most one partition, ignore!
              if (superOfTempIntervalP1 == null || superOfTempIntervalP2 == null) {
                  continue;
              }
  
              if (newInterval == null) {
                  newInterval = tempInterval;
                  superOfNewIntervalP1 = superOfTempIntervalP1;
                  superOfNewIntervalP2 = superOfTempIntervalP2;
                  continue;
              }
  
              if (superOfNewIntervalP1 == superOfTempIntervalP1 && superOfNewIntervalP2 == superOfTempIntervalP2) {
                  newInterval.includeBound(tempInterval);
              } else {
                  outputPartition.add(newInterval);
                  newInterval = tempInterval;
                  superOfNewIntervalP1 = superOfTempIntervalP1;
                  superOfNewIntervalP2 = superOfTempIntervalP2;
              }
  
          }
          if (newInterval != null) {
              outputPartition.add(newInterval);
          }
          return new Partition<T>(outputPartition);
      }
docs: Return the intersect of two disjoint partition. The returned disjoint partition has items that: - Each interval
  item is a subset of only an interval I1 \in p1 and a subset of only an interval I2 \in p2.
  
  @param p1
  @param p2
  @return