Example usage for com.google.common.collect Iterators peekingIterator

List of usage examples for com.google.common.collect Iterators peekingIterator

Introduction

In this page you can find the example usage for com.google.common.collect Iterators peekingIterator.

Prototype

@Deprecated
public static <T> PeekingIterator<T> peekingIterator(PeekingIterator<T> iterator) 

Source Link

Document

Simply returns its argument.

Usage

From source file:org.locationtech.geogig.storage.postgresql.v9.PGObjectStoreObjectIterator.java

public PGObjectStoreObjectIterator(Iterator<NodeRef> refs, Class<T> type, BulkOpListener listener,
        PGObjectStore store) {/*w ww.  ja v a 2  s  .  c  o  m*/
    this.nodes = Iterators.peekingIterator(refs);
    this.type = type;
    this.listener = listener;
    this.store = store;
    cache = store.sharedCache;
}

From source file:org.apache.fluo.core.impl.scanner.ColumnScannerImpl.java

ColumnScannerImpl(Iterator<Entry<Key, Value>> e, Function<Key, Column> columnConverter) {
    peekingIter = Iterators.peekingIterator(e);
    this.columnConverter = columnConverter;
    row = ByteUtil.toBytes(peekingIter.peek().getKey().getRowData());
    iter = Iterators.transform(peekingIter, this::entry2cv);
}

From source file:org.locationtech.geogig.storage.internal.ObjectStoreDiffObjectIterator.java

public ObjectStoreDiffObjectIterator(//@formatter:off
        Iterator<DiffEntry> refs, Class<T> type, ObjectStore leftStore, ObjectStore rightStore) {//@formatter:on
    this.nodes = Iterators.peekingIterator(refs);
    this.type = type;
    this.leftStore = leftStore;
    this.rightStore = rightStore;
}

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  ava 2s  . c o m*/
        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.apache.kylin.storage.gtrecord.SortMergedPartitionResultIterator.java

SortMergedPartitionResultIterator(List<PartitionResultIterator> partitionResults, GTInfo info,
        final Comparator<GTRecord> comparator) {

    this.record = new GTRecord(info);
    Comparator<PeekingIterator<GTRecord>> heapComparator = new Comparator<PeekingIterator<GTRecord>>() {
        public int compare(PeekingIterator<GTRecord> o1, PeekingIterator<GTRecord> o2) {
            return comparator.compare(o1.peek(), o2.peek());
        }/*  w w w .j  a v a2 s .c om*/
    };
    this.heap = new PriorityQueue<>(partitionResults.size(), heapComparator);

    for (PartitionResultIterator it : partitionResults) {
        if (it.hasNext()) {
            heap.offer(Iterators.peekingIterator(it));
        }
    }
}

From source file:com.hubspot.jinjava.tree.TreeParser.java

public TreeParser(JinjavaInterpreter interpreter, String input) {
    this.scanner = Iterators.peekingIterator(new TokenScanner(input, interpreter.getConfig()));
    this.interpreter = interpreter;
}

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  w w .  j  a va 2s  .  c  om

    // 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:org.apache.druid.java.util.common.guava.nary.SortedMergeIterator.java

public SortedMergeIterator(Iterator<InType> lhs, Iterator<InType> rhs, Comparator<InType> comparator,
        BinaryFn<InType, InType, OutType> fn) {
    this.lhs = Iterators.peekingIterator(lhs);
    this.rhs = Iterators.peekingIterator(rhs);
    this.comparator = comparator;
    this.fn = fn;
}

From source file:org.apache.storm.state.BaseStateIterator.java

/**
 * Constructor./*from ww w . j a v a  2s. c o m*/
 *
 * @param pendingPrepareIterator The iterator of pendingPrepare
 * @param pendingCommitIterator The iterator of pendingCommit
 * @param initialProvidedKeys The initial value of provided keys
 */
public BaseStateIterator(Iterator<Map.Entry<KENCODED, VENCODED>> pendingPrepareIterator,
        Iterator<Map.Entry<KENCODED, VENCODED>> pendingCommitIterator, Set<KENCODED> initialProvidedKeys) {
    this.pendingPrepareIterator = Iterators.peekingIterator(pendingPrepareIterator);
    this.pendingCommitIterator = Iterators.peekingIterator(pendingCommitIterator);
    this.providedKeys = initialProvidedKeys;
}

From source file:org.apache.accumulo.examples.filedata.ChunkInputFormat.java

@Override
public RecordReader<List<Entry<Key, Value>>, InputStream> createRecordReader(InputSplit split,
        TaskAttemptContext context) throws IOException, InterruptedException {
    return new RecordReaderBase<List<Entry<Key, Value>>, InputStream>() {
        private PeekingIterator<Entry<Key, Value>> peekingScannerIterator;

        @Override/*  w w w  .j  a  v  a 2 s  . c o  m*/
        public void initialize(InputSplit inSplit, TaskAttemptContext attempt) throws IOException {
            super.initialize(inSplit, attempt);
            peekingScannerIterator = Iterators.peekingIterator(scannerIterator);
            currentK = new ArrayList<>();
            currentV = new ChunkInputStream();
        }

        @Override
        public boolean nextKeyValue() throws IOException, InterruptedException {
            currentK.clear();
            if (peekingScannerIterator.hasNext()) {
                ++numKeysRead;
                Entry<Key, Value> entry = peekingScannerIterator.peek();
                while (!entry.getKey().getColumnFamily().equals(FileDataIngest.CHUNK_CF)) {
                    currentK.add(entry);
                    peekingScannerIterator.next();
                    if (!peekingScannerIterator.hasNext())
                        return true;
                    entry = peekingScannerIterator.peek();
                }
                currentKey = entry.getKey();
                ((ChunkInputStream) currentV).setSource(peekingScannerIterator);
                if (log.isTraceEnabled())
                    log.trace("Processing key/value pair: " + DefaultFormatter.formatEntry(entry, true));
                return true;
            }
            return false;
        }
    };
}