Aggregation(Resource resource, Timestamp start, Timestamp end, ResultDescriptor resultDescriptor, Duration resolution, Iterator<Row<Measurement>> input) {
m_resultDescriptor = checkNotNull(resultDescriptor, "result descriptor argument");
m_resource = checkNotNull(resource, "resource argument");
checkNotNull(start, "start argument");
checkNotNull(end, "end argument");
m_resolution = checkNotNull(resolution, "resolution argument");
m_input = checkNotNull(input, "input argument");
Duration interval = resultDescriptor.getInterval();
checkArgument(resolution.isMultiple(interval), "resolution must be a multiple of interval");
m_timestamps = new IntervalGenerator(start.stepFloor(m_resolution), end.stepCeiling(m_resolution), m_resolution);
m_intervalsPer = (double) resolution.divideBy(interval);
m_working = m_input.hasNext() ? m_input.next() : null;
m_nextOut = m_timestamps.hasNext() ? new Row<Measurement>(m_timestamps.next(), m_resource) : null;
if (m_nextOut != null) {
while (m_working != null && m_working.getTimestamp().lte(m_nextOut.getTimestamp().minus(m_resolution))) {
m_working = nextWorking();
}
}
}