private Duration aggregateDurations(List<? extends IntervalBase> intervals) {
   Duration aggregatedDuration = new Duration(0);
   for (IntervalBase interval : intervals) {
     aggregatedDuration = aggregatedDuration.plus(interval.getDuration());
   }
   return aggregatedDuration;
 }
 private void addIntervals(IntervalManager intervalManager) {
   for (IntervalBase interval : intervalPersister.readIntervals()) {
     interval.setClosed();
     intervals.add(interval);
   }
   intervals.addAll(intervalManager.getOpenIntervals());
 }
 private void adjustIntervalStartAndEndDate(
     DateTime thresholdDateView, IntervalBase interval, IntervalBase clonedInterval) {
   if (interval.getStart().before(thresholdDateView.toDate())) {
     // Set start of the interval to threshold if the start is
     // before the threshold.
     clonedInterval.setStartTime(thresholdDateView.toDate());
   }
   if (!clonedInterval.isClosed()) {
     clonedInterval.setEndTime(mostRecentDate);
   }
 }
  /**
   * Filters out and removes intervals which are older than 10 hours from Database. Filters
   * intervals for selected time span.
   */
  private void filterIntervals() {
    ArrayList<IntervalBase> filteredIntervals = new ArrayList<IntervalBase>();
    ArrayList<IntervalBase> intervalsToRemove = new ArrayList<IntervalBase>();

    if (intervals.size() == 0) {
      return;
    }

    mostRecentDate = intervals.get(intervals.size() - 1).getEnd();
    DateTime thresholdDateDatabase = new DateTime(mostRecentDate);
    thresholdDateDatabase = thresholdDateDatabase.minusMinutes(FILTERED_INTERVALS_IN_MINUTES);

    DateTime thresholdDateView = new DateTime(mostRecentDate);
    thresholdDateView = thresholdDateView.minusMinutes(selectedInterval.minutes);

    for (IntervalBase interval : intervals) {
      if (intervalIsOlderThanThreshold(thresholdDateDatabase, interval)) {
        intervalsToRemove.add(interval);
        continue;
      }

      if (!intervalIsOlderThanThreshold(thresholdDateView, interval)) {
        IntervalBase clonedInterval = null;
        try {
          clonedInterval = (IntervalBase) interval.clone();
          adjustIntervalStartAndEndDate(thresholdDateView, interval, clonedInterval);
          filteredIntervals.add(clonedInterval);
        } catch (CloneNotSupportedException e) {
          // intentionally empty
        }
      }
    }

    oldestDate = filteredIntervals.get(0).getStart();
    intervalPersister.removeIntervals(intervalsToRemove);
    intervals = filteredIntervals;
  }
 private boolean intervalIsOlderThanThreshold(
     DateTime thresholdDateDatabase, IntervalBase interval) {
   return interval.getEnd().before(thresholdDateDatabase.toDate());
 }
Example #6
0
 private boolean isClosed(IntervalBase interval) {
   return interval == null || interval.isClosed();
 }
Example #7
0
 private boolean intervalIsOfType(IntervalBase interval, IntervalType type) {
   return interval != null && interval.getType() == type;
 }