public static List<Interval> sliceIntervals(Interval interval,TimeGrain timeGrain){
  DateTime intervalEnd=interval.getEnd();
  DateTime sliceStart=interval.getStart();
  DateTime periodStart=timeGrain.roundFloor(sliceStart);
  if (!sliceStart.equals(periodStart)) {
    LOG.info("Interval {} is not aligned to TimeGrain {} starting {}",interval,timeGrain,periodStart);
    throw new IllegalArgumentException("Interval must be aligned to the TimeGrain starting " + periodStart);
  }
  List<Interval> intervalSlices=new ArrayList<>();
  while (sliceStart.isBefore(intervalEnd)) {
    DateTime sliceEnd=DateTimeUtils.addTimeGrain(sliceStart,timeGrain);
    Interval slicedInterval=new Interval(sliceStart,sliceEnd);
    if (!interval.contains(slicedInterval)) {
      LOG.info("Interval {} is not a multiple of TimeGrain {}",interval,timeGrain);
      throw new IllegalArgumentException("Interval must be a multiple of the TimeGrain");
    }
    intervalSlices.add(slicedInterval);
    sliceStart=sliceEnd;
  }
  LOG.debug("Sliced interval {} into {} slices of {} grain",interval,intervalSlices.size(),timeGrain);
  return intervalSlices;
}

public static List < Interval > sliceIntervals ( Interval interval , TimeGrain timeGrain ) { DateTime intervalEnd = interval . getEnd ( ) ; DateTime sliceStart = interval . getStart ( ) ; DateTime periodStart = timeGrain . roundFloor ( sliceStart ) ; if ( ! sliceStart . equals ( periodStart ) ) { LOG . info ( "Interval {} is not aligned to TimeGrain {} starting {}" , interval , timeGrain , periodStart ) ; throw new IllegalArgumentException ( "Interval must be aligned to the TimeGrain starting " + periodStart ) ; } List < Interval > intervalSlices = new ArrayList < > ( ) ; while ( sliceStart . isBefore ( intervalEnd ) ) { DateTime sliceEnd = DateTimeUtils . addTimeGrain ( sliceStart , timeGrain ) ; Interval slicedInterval = new Interval ( sliceStart , sliceEnd ) ; if ( ! interval . contains ( slicedInterval ) ) { LOG . info ( "Interval {} is not a multiple of TimeGrain {}" , interval , timeGrain ) ; throw new IllegalArgumentException ( "Interval must be a multiple of the TimeGrain" ) ; } intervalSlices . add ( slicedInterval ) ; sliceStart = sliceEnd ; } LOG . debug ( "Sliced interval {} into {} slices of {} grain" , interval , intervalSlices . size ( ) , timeGrain ) ; return intervalSlices ; }
slices the intervals into smaller intervals of the timegrain duration .
