/** * Gets an iterator that supports pushback of elements. * * @param <E> the element type * @param iterator the iterator to decorate, not null * @return a pushback iterator * @throws NullPointerException if the iterator is null * @since 4.0 */ public static <E> Iterator<E> pushbackIterator(final Iterator<? extends E> iterator) { return PushbackIterator.pushbackIterator(iterator); }
/** * Decorates the specified iterator to support one-element lookahead. * <p> * If the iterator is already a {@link PushbackIterator} it is returned directly. * * @param <E> the element type * @param iterator the iterator to decorate * @return a new peeking iterator * @throws NullPointerException if the iterator is null */ public static <E> PushbackIterator<E> pushbackIterator(final Iterator<? extends E> iterator) { if (iterator == null) { throw new NullPointerException("Iterator must not be null"); } if (iterator instanceof PushbackIterator<?>) { @SuppressWarnings("unchecked") // safe cast final PushbackIterator<E> it = (PushbackIterator<E>) iterator; return it; } return new PushbackIterator<>(iterator); }
/** * Create a shard iterator * * @param shardIterator The iterator of all shards. Order is expected to be by the shard index from Long.MAX to * Long.MIN * @param minDelta The minimum delta we allow to consider shards the same group */ public ShardEntryGroupIterator( final Iterator<Shard> shardIterator, final long minDelta, final ShardGroupCompaction shardGroupCompaction, final ApplicationScope scope, final DirectedEdgeMeta directedEdgeMeta ) { Preconditions.checkArgument( shardIterator.hasNext(), "Shard iterator must have shards present" ); this.scope = scope; this.directedEdgeMeta = directedEdgeMeta; this.sourceIterator = new PushbackIterator( shardIterator ); this.shardGroupCompaction = shardGroupCompaction; this.minDelta = minDelta; }