List of usage examples for com.google.common.collect PeekingIterator hasNext
boolean hasNext();
From source file:com.google.errorprone.bugpatterns.FallThrough.java
@Override public Description matchSwitch(SwitchTree tree, VisitorState state) { PeekingIterator<JCTree.JCCase> it = Iterators.peekingIterator(((JCTree.JCSwitch) tree).cases.iterator()); while (it.hasNext()) { JCTree.JCCase caseTree = it.next(); if (!it.hasNext()) { break; }//from w w w . j av a2 s. c om JCTree.JCCase next = it.peek(); if (caseTree.stats.isEmpty()) { continue; } // We only care whether the last statement completes; javac would have already // reported an error if that statement wasn't reachable, and the answer is // independent of any preceding statements. boolean completes = Reachability.canCompleteNormally(getLast(caseTree.stats)); String comments = state.getSourceCode() .subSequence(caseEndPosition(state, caseTree), next.getStartPosition()).toString().trim(); if (completes && !FALL_THROUGH_PATTERN.matcher(comments).find()) { state.reportMatch(buildDescription(next).setMessage( "Switch case may fall through; add a `// fall through` comment if it was" + " deliberate") .build()); } else if (!completes && FALL_THROUGH_PATTERN.matcher(comments).find()) { state.reportMatch(buildDescription(next) .setMessage("Switch case has 'fall through' comment, but does not fall through").build()); } } return NO_MATCH; }
From source file:org.diqube.cache.ConstantTimeCache.java
private void cleanupCache(long now) { PeekingIterator<Triple<Long, K1, K2>> it = Iterators.peekingIterator(timeouts.iterator()); while (it.hasNext() && it.peek().getLeft() < now) { Triple<Long, K1, K2> t = it.next(); values.remove(new Pair<>(t.getMiddle(), t.getRight())); secondLevelKeys.computeIfPresent(t.getMiddle(), (k, v) -> { Set<K2> res = new ConcurrentSkipListSet<>(v); res.remove(t.getRight());/*from w w w . j ava2 s . c o m*/ if (res.isEmpty()) return null; return res; }); it.remove(); } }
From source file:com.github.zhongl.index.Merger.java
public IndicesFile merge(PeekingIterator<Index> base, PeekingIterator<Index> delta) throws IOException { IndicesFile file = new IndicesFile(dir, encoder); while (base.hasNext() && delta.hasNext()) { Index a = base.peek();// ww w .j a v a2s. co m Index b = delta.peek(); Index c; int result = a.compareTo(b); if (result < 0) c = base.next(); // a < b, use a else if (result > 0) c = delta.next(); // a > b, use b else { // a == b, use b c = b; delta.next(); base.next(); } if (c.isRemoved()) continue; // remove this entry file.append(c); } mergeRestOf(base, file); mergeRestOf(delta, file); return file; }
From source file:is.illuminati.block.spyros.garmin.model.Lap.java
/** * Get a list of all pauses in the lap.// w ww . j av a 2 s .com * @return list of all pauses. */ public ImmutableList<Pause> getPauses() { ImmutableList.Builder<Pause> pausesBuilder = ImmutableList.builder(); PeekingIterator<Track> it = Iterators.peekingIterator(tracks.iterator()); while (it.hasNext()) { Track former = it.next(); Track latter; if (it.hasNext()) { latter = it.peek(); } else { break; } Duration gap = new Duration(former.getEndTime(), latter.getStartTime()); if (gap.isLongerThan(Duration.standardSeconds(10))) { pausesBuilder.add(new Pause(former.getEndTime(), latter.getStartTime())); } } return pausesBuilder.build(); }
From source file:org.apache.jackrabbit.oak.plugins.document.util.MergeSortedIterators.java
@Override public T next() { if (!hasNext()) { throw new NoSuchElementException(); }/*from www . j a va2s . c o m*/ PeekingIterator<T> it = iterators.get(0); T next = it.next(); // more elements? if (it.hasNext()) { adjustFirst(); } else { // remove from list of iterators iterators.remove(0); } // fetch next iterator? if (comparator.compare(next, lastPeek) >= 0) { fetchNextIterator(); } return next; }
From source file:io.druid.segment.indexing.granularity.ArbitraryGranularitySpec.java
@JsonCreator public ArbitraryGranularitySpec(@JsonProperty("queryGranularity") QueryGranularity queryGranularity, @JsonProperty("intervals") List<Interval> inputIntervals) { this.queryGranularity = queryGranularity; this.intervals = Sets.newTreeSet(Comparators.intervalsByStartThenEnd()); if (inputIntervals == null) { inputIntervals = Lists.newArrayList(); }/*from w ww. ja va 2 s . co m*/ // Insert all intervals for (final Interval inputInterval : inputIntervals) { intervals.add(inputInterval); } // Ensure intervals are non-overlapping (but they may abut each other) final PeekingIterator<Interval> intervalIterator = Iterators.peekingIterator(intervals.iterator()); while (intervalIterator.hasNext()) { final Interval currentInterval = intervalIterator.next(); if (intervalIterator.hasNext()) { final Interval nextInterval = intervalIterator.peek(); if (currentInterval.overlaps(nextInterval)) { throw new IllegalArgumentException( String.format("Overlapping intervals: %s, %s", currentInterval, nextInterval)); } } } }
From source file:com.indeed.lsmtree.core.MergingIterator.java
@Override protected Generation.Entry<K, V> computeNext() { if (heap.isEmpty()) { return endOfData(); }/*w w w . j a va 2s . co m*/ PeekingIterator<EntryAndGenerationId<K, V>> first = heap.poll(); EntryAndGenerationId<K, V> ret = first.next(); if (first.hasNext()) { temp.add(first); } while (!heap.isEmpty() && keyComparator.compare(ret.entry.getKey(), heap.peek().peek().entry.getKey()) == 0) { PeekingIterator<EntryAndGenerationId<K, V>> iter = heap.poll(); iter.next(); if (iter.hasNext()) { temp.add(iter); } } heap.addAll(temp); temp.clear(); return ret.entry; }
From source file:org.apache.druid.segment.indexing.granularity.ArbitraryGranularitySpec.java
@JsonCreator public ArbitraryGranularitySpec(@JsonProperty("queryGranularity") Granularity queryGranularity, @JsonProperty("rollup") Boolean rollup, @JsonProperty("intervals") List<Interval> inputIntervals) { this.queryGranularity = queryGranularity == null ? Granularities.NONE : queryGranularity; this.rollup = rollup == null ? Boolean.TRUE : rollup; this.intervals = Sets.newTreeSet(Comparators.intervalsByStartThenEnd()); if (inputIntervals == null) { inputIntervals = Lists.newArrayList(); }/*from w ww. ja va 2s.c o m*/ // Insert all intervals for (final Interval inputInterval : inputIntervals) { intervals.add(inputInterval); } // Ensure intervals are non-overlapping (but they may abut each other) final PeekingIterator<Interval> intervalIterator = Iterators.peekingIterator(intervals.iterator()); while (intervalIterator.hasNext()) { final Interval currentInterval = intervalIterator.next(); if (intervalIterator.hasNext()) { final Interval nextInterval = intervalIterator.peek(); if (currentInterval.overlaps(nextInterval)) { throw new IAE("Overlapping intervals: %s, %s", currentInterval, nextInterval); } } } }
From source file:org.apache.storm.state.BaseStateIterator.java
private boolean seekToAvailableEntry(PeekingIterator<Map.Entry<KENCODED, VENCODED>> iterator) { if (iterator != null) { while (iterator.hasNext()) { Map.Entry<KENCODED, VENCODED> entry = iterator.peek(); if (!providedKeys.contains(entry.getKey())) { if (isTombstoneValue(entry.getValue())) { providedKeys.add(entry.getKey()); } else { return true; }/*from w w w. j a v a2 s .c om*/ } iterator.next(); } } return false; }
From source file:co.cask.cdap.data.file.PartitionedFileWriter.java
@Override public void appendAll(final Iterator<? extends T> events) throws IOException { if (closed) { throw new IOException("Attempts to write to a closed FileWriter."); }//from w ww .j a v a 2s .c o m PeekingIterator<T> iterator = Iterators.peekingIterator(events); while (iterator.hasNext()) { getWriter(iterator.peek()).appendAll(new AppendIterator(iterator)); } }