List of usage examples for com.google.common.collect Iterators peekingIterator
@Deprecated public static <T> PeekingIterator<T> peekingIterator(PeekingIterator<T> iterator)
From source file:org.spongepowered.common.service.pagination.IterablePagination.java
public IterablePagination(MessageReceiver src, PaginationCalculator calc, Iterable<Map.Entry<Text, Integer>> counts, Text title, Text header, Text footer, Text padding) { super(src, calc, title, header, footer, padding); this.countIterator = Iterators.peekingIterator(counts.iterator()); }
From source file:no.ssb.vtl.script.operations.join.InnerJoinSpliterator.java
public InnerJoinSpliterator(Function<L, K> leftKeyExtractor, Function<R, K> rightKeyExtractor, Comparator<K> predicate, BiFunction<L, R, O> merger, Spliterator<L> leftSpliterator, Spliterator<R> rightSpliterator) { this.leftKeyExtractor = leftKeyExtractor; this.rightKeyExtractor = rightKeyExtractor; this.predicate = checkNotNull(predicate); this.merger = checkNotNull(merger); this.leftIterator = Iterators.peekingIterator(Spliterators.iterator(leftSpliterator)); this.rightIterator = Iterators.peekingIterator(Spliterators.iterator(rightSpliterator)); }
From source file:org.apache.accumulo.examples.filedata.FileDataQuery.java
public ChunkInputStream getData(String hash) throws IOException { scanner.setRange(new Range(hash)); scanner.setBatchSize(1);//from w w w . j a va 2 s .c o m lastRefs.clear(); PeekingIterator<Entry<Key, Value>> pi = Iterators.peekingIterator(scanner.iterator()); if (pi.hasNext()) { while (!pi.peek().getKey().getColumnFamily().equals(FileDataIngest.CHUNK_CF)) { lastRefs.add(pi.peek()); pi.next(); } } cis.clear(); cis.setSource(pi); return cis; }
From source file:com.github.rinde.rinsim.geom.Graphs.java
/** * Create a path of connections on the specified {@link Graph} using the * specified {@link Point}s. If the points <code>A, B, C</code> are specified, * the two connections: <code>A -> B</code> and <code>B -> C</code> will * be added to the graph./* w w w .j av a2 s . c o m*/ * @param graph The graph to which the connections will be added. * @param path Points that will be treated as a path. * @param <E> The type of connection data. */ public static <E extends ConnectionData> void addPath(Graph<E> graph, Iterable<Point> path) { final PeekingIterator<Point> it = Iterators.peekingIterator(path.iterator()); while (it.hasNext()) { final Point n = it.next(); if (it.hasNext()) { graph.addConnection(n, it.peek()); } } }
From source file:org.gbif.dwc.record.RecordIterator.java
/** * @param replaceNulls if true record values will have literal nulls replaced with NULL. * @param replaceEntities if true html & xml entities in record values will be replaced with the interpreted value. *//*from www .ja v a2 s. c om*/ public RecordIterator(ClosableIterator<String[]> recordSource, ArchiveField id, Map<Term, ArchiveField> fields, Term rowType, boolean replaceNulls, boolean replaceEntities) { this.id = id; this.fields = fields; this.rowType = rowType; this.replaceNulls = replaceNulls; this.replaceEntities = replaceEntities; closable = recordSource; if (closable == null) { Iterator<String[]> empty = Iterators.emptyIterator(); iter = Iterators.peekingIterator(empty); } else { iter = Iterators.peekingIterator(closable); } }
From source file:org.kiji.schema.impl.KijiResultQualifierPager.java
/** * Create a Kiji qualifier pager backed by a {@code KijiResult}. * * @param result The {@code KijiResult} backing this pager. * @param layout The {@code KijiTableLayout} of the table. *///w ww.ja va2 s . c o m public KijiResultQualifierPager(final KijiResult<Object> result, final KijiTableLayout layout) { mResult = result; mCells = Iterators.peekingIterator(mResult.iterator()); mLayout = layout; final KijiDataRequest dataRequest = mResult.getDataRequest(); final Collection<Column> columnRequests = dataRequest.getColumns(); Preconditions.checkArgument(columnRequests.size() == 1, "Can not create KijiResultPager with multiple columns. Data request: %s.", dataRequest); mColumnRequest = columnRequests.iterator().next(); }
From source file:com.outerspacecat.icalendar.RecurrenceIterators.java
/** * Returns a recurrence iterator based on {@code base}. * //from ww w. j a v a2 s . co m * @param base a base iterator. Must be non {@code null}. * @param transformer a function to transform the elements in {@code base}. * Must be non {@code null}. * @return a recurrence iterator of based on {@code base}. Never {@code null}. */ static <U, V extends Comparable<V>> RecurrenceIterator<V> transform(final Iterator<U> base, final Function<U, V> transformer) { Preconditions.checkNotNull(base, "base required"); Preconditions.checkNotNull(transformer, "transformer required"); return new RecurrenceIterator<V>() { PeekingIterator<U> iter = Iterators.peekingIterator(base); @Override public boolean hasNext() { return iter.hasNext(); } @Override public V next() { if (!hasNext()) throw new NoSuchElementException(); return transformer.apply(iter.next()); } @Override public void remove() { throw new UnsupportedOperationException("remove not supported"); } @Override public void advanceTo(final V to) { Preconditions.checkNotNull(to, "to must be non null"); while (iter.hasNext()) { if (transformer.apply(iter.peek()).compareTo(to) >= 0) break; iter.next(); } } }; }
From source file:com.moz.fiji.schema.impl.FijiResultQualifierPager.java
/** * Create a Fiji qualifier pager backed by a {@code FijiResult}. * * @param result The {@code FijiResult} backing this pager. * @param layout The {@code FijiTableLayout} of the table. *//*from w w w.j a v a2 s . c om*/ public FijiResultQualifierPager(final FijiResult<Object> result, final FijiTableLayout layout) { mResult = result; mCells = Iterators.peekingIterator(mResult.iterator()); mLayout = layout; final FijiDataRequest dataRequest = mResult.getDataRequest(); final Collection<Column> columnRequests = dataRequest.getColumns(); Preconditions.checkArgument(columnRequests.size() == 1, "Can not create FijiResultPager with multiple columns. Data request: %s.", dataRequest); mColumnRequest = columnRequests.iterator().next(); }
From source file:is.illuminati.block.spyros.garmin.model.Lap.java
/** * Get a list of all pauses in the lap.// ww w. j a v a 2s . c o m * @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:io.druid.collections.OrderedMergeIterator.java
public OrderedMergeIterator(final Comparator<T> comparator, Iterator<Iterator<T>> iterators) { this.comparator = comparator; pQueue = new PriorityQueue<PeekingIterator<T>>(16, new Comparator<PeekingIterator<T>>() { @Override//from www . j ava 2 s . co m public int compare(PeekingIterator<T> lhs, PeekingIterator<T> rhs) { return comparator.compare(lhs.peek(), rhs.peek()); } }); iterOfIterators = Iterators .peekingIterator(FunctionalIterator.create(iterators).filter(new Predicate<Iterator<T>>() { @Override public boolean apply(Iterator<T> input) { return input.hasNext(); } }).transform(new Function<Iterator<T>, PeekingIterator<T>>() { @Override public PeekingIterator<T> apply(Iterator<T> input) { return Iterators.peekingIterator(input); } })); }