/** {@inheritDoc} */ @Override public VType next() throws Exception { if (index < 0) throw new Exception("End of samples"); // $NON-NLS-1$ // Remember value, prepare the next value final VType result = value; samples.getLock().lock(); try { ++index; if (index >= samples.size()) index = -1; // No more samples else { value = samples.get(index).getVType(); if (VTypeHelper.getTimestamp(value).compareTo(end) > 0) index = -1; // Beyond end time } } finally { samples.getLock().unlock(); } return result; }
/** * Initialize * * @param item Item from which to get samples /** @param start Start time /** @param end End time */ public ModelSampleIterator(final ModelItem item, final Instant start, final Instant end) { this.samples = item.getSamples(); this.end = end; samples.getLock().lock(); try { // Anything? if (samples.size() <= 0) index = -1; // All data after start time? else if (samples.get(0).getPosition().compareTo(start) >= 0) index = 0; else { // There is data before the start time. Find sample just before start time. index = findSampleLessOrEqual(start); } // Is first sample already after end time? if (index >= 0) { final PlotSample sample = samples.get(index); value = sample.getVType(); if (sample.getPosition().compareTo(end) > 0) index = -1; } } finally { samples.getLock().unlock(); } }