code: public static List<MilestoneRectangle> merge(List<MilestoneRectangle> input)
      {
          Stack<MilestoneRectangle> mergeStack = new Stack<MilestoneRectangle>();
          for (MilestoneRectangle rectangle : input)
          {
              if (rectangle.isValid())
              {
                  mergeStack.push(rectangle);
              }
              else
              {
                  MithraDataObject dataObject = (MithraDataObject) rectangle.data;
                  LOGGER.warn("Invalid milestoning of " + dataObject.getClass().getSimpleName() + '[' + dataObject.zGetPrintablePrimaryKey() + ']');
              }
          }
          List<MilestoneRectangle> merged = FastList.newList(input.size());
          while (!mergeStack.isEmpty())
          {
              MilestoneRectangle next = mergeStack.pop();
  
              boolean fragmented = false;
              for(int i = mergeStack.size() - 1; !fragmented && i >=0; i--)
              {
                  MilestoneRectangle rect = mergeStack.get(i);
                  if (next.intersects(rect))
                  {
                      next.fragment(rect, mergeStack);
                      fragmented = true;
                  }
              }
              if (!fragmented)
              {
                  merged.add(next);
              }
          }
          return merged;
      }
docs: /*
  Takes a list of rectangles and cleans up any overlapping ranges by giving precedence to rectangles closest to
  the start of the list and fragmenting those towards the end of the list where necessary. It is assumed that the
  data objects in each rectangle share the same dateless primary key. Any data differences will be handled by
  giving precedence to objects nearest the start of the list.