List of usage examples for java.util Iterator Iterator
Iterator
From source file:io.druid.firehose.azure.StaticAzureBlobStoreFirehoseFactory.java
@Override public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException { Preconditions.checkNotNull(azureStorage, "null azureStorage"); final LinkedList<AzureBlob> objectQueue = Lists.newLinkedList(blobs); return new FileIteratingFirehose(new Iterator<LineIterator>() { @Override//from w ww.j a v a 2s . c o m public boolean hasNext() { return !objectQueue.isEmpty(); } @Override public LineIterator next() { final AzureBlob nextURI = objectQueue.poll(); final String container = nextURI.getContainer(); final String path = nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath(); try { final InputStream innerInputStream = new AzureByteSource(azureStorage, container, path) .openStream(); final InputStream outerInputStream = path.endsWith(".gz") ? CompressionUtils.gzipInputStream(innerInputStream) : innerInputStream; return IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (Exception e) { log.error(e, "Exception opening container[%s] blob[%s]", container, path); throw Throwables.propagate(e); } } @Override public void remove() { throw new UnsupportedOperationException(); } }, stringInputRowParser); }
From source file:org.apache.oodt.cas.cli.util.CmdLineIterable.java
public Iterator<T> iterator() { return new Iterator<T>() { public boolean hasNext() { return CmdLineIterable.this.hasNext(); }/*from w ww. j a v a 2s .co m*/ public T next() { if (!hasNext()) { throw new IndexOutOfBoundsException((curIndex + 1) + ""); } return incrementAndGet(); } public void remove() { // do nothing } }; }
From source file:io.druid.firehose.google.StaticGoogleBlobStoreFirehoseFactory.java
@Override public Firehose connect(StringInputRowParser stringInputRowParser) throws IOException { Preconditions.checkNotNull(storage, "null storage"); final LinkedList<GoogleBlob> objectQueue = Lists.newLinkedList(blobs); return new FileIteratingFirehose(new Iterator<LineIterator>() { @Override//from www . jav a2 s . co m public boolean hasNext() { return !objectQueue.isEmpty(); } @Override public LineIterator next() { final GoogleBlob nextURI = objectQueue.poll(); final String bucket = nextURI.getBucket(); final String path = nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath(); try { final InputStream innerInputStream = new GoogleByteSource(storage, bucket, path).openStream(); final InputStream outerInputStream = path.endsWith(".gz") ? CompressionUtils.gzipInputStream(innerInputStream) : innerInputStream; return IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (Exception e) { LOG.error(e, "Exception opening bucket[%s] blob[%s]", bucket, path); throw Throwables.propagate(e); } } @Override public void remove() { throw new UnsupportedOperationException(); } }, stringInputRowParser); }
From source file:net.collegeman.grails.e3db.GroovySqlRowSet.java
public Iterator iterator() { final GroovySqlRowSet parent = this; return new Iterator() { public boolean hasNext() { return rs.next(); }// w w w . j a v a2s.c o m public Object next() { return parent; } public void remove() { throw new IllegalStateException("Cannot remove items from a SqlRowSet."); } }; }
From source file:de.schildbach.game.BoardGeometry.java
protected Iterator<Coordinate> pieceIterator(final Board board, final int color) { final Iterator<Coordinate> boardIterator = this.coordinateIterator(); return new Iterator<Coordinate>() { Coordinate next = null;//from ww w. jav a 2 s. c o m public boolean hasNext() { if (next != null) { return true; } else { while (boardIterator.hasNext()) { next = boardIterator.next(); Piece piece = board.getPiece(next); if (piece != null && piece.getColor() == color) return true; } next = null; return false; } } public Coordinate next() { if (hasNext()) { Coordinate result = next; next = null; return result; } else throw new NoSuchElementException(); } public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:com.opengamma.engine.depgraph.OrderedRunQueue.java
@Override public Iterator<ContextRunnable> iterator() { return new Iterator<ContextRunnable>() { private int _count; @Override/*from w w w .j a va 2s . c om*/ public boolean hasNext() { return _count < size(); } @Override public ContextRunnable next() { return _buffer[_count++]; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:org.apache.pig.backend.local.executionengine.LocalJob.java
public Iterator<Tuple> getResults() throws ExecException { final LoadFunc p; try {//from w w w . ja va2s .com p = (LoadFunc) PigContext.instantiateFuncFromSpec(outFileSpec.getFuncSpec()); InputStream is = FileLocalizer.open(outFileSpec.getFileName(), pigContext); p.bindTo(outFileSpec.getFileName(), new BufferedPositionedInputStream(is), 0, Long.MAX_VALUE); } catch (Exception e) { throw new ExecException("Unable to get results for " + outFileSpec, e); } return new Iterator<Tuple>() { Tuple t; boolean atEnd; public boolean hasNext() { if (atEnd) return false; try { if (t == null) t = p.getNext(); if (t == null) atEnd = true; } catch (Exception e) { log.error(e); t = null; atEnd = true; } return !atEnd; } public Tuple next() { Tuple next = t; if (next != null) { t = null; return next; } try { next = p.getNext(); } catch (Exception e) { log.error(e); } if (next == null) atEnd = true; return next; } public void remove() { throw new RuntimeException("Removal not supported"); } }; }
From source file:org.omnaest.utils.table.impl.StripeImpl.java
/** * //w w w . ja v a 2 s .c o m */ public Iterator<E> iterator() { final int indexMax = this.size() - 1; return new Iterator<E>() { private int index = -1; @Override public boolean hasNext() { return this.index + 1 <= indexMax; } @Override public E next() { return getElement(++this.index); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:io.druid.firehose.s3.StaticS3FirehoseFactory.java
@Override public Firehose connect(StringInputRowParser firehoseParser) throws IOException { Preconditions.checkNotNull(s3Client, "null s3Client"); final LinkedList<URI> objectQueue = Lists.newLinkedList(uris); return new FileIteratingFirehose(new Iterator<LineIterator>() { @Override// w w w. j a va2 s .co m public boolean hasNext() { return !objectQueue.isEmpty(); } @Override public LineIterator next() { final URI nextURI = objectQueue.poll(); final String s3Bucket = nextURI.getAuthority(); final S3Object s3Object = new S3Object( nextURI.getPath().startsWith("/") ? nextURI.getPath().substring(1) : nextURI.getPath()); log.info("Reading from bucket[%s] object[%s] (%s)", s3Bucket, s3Object.getKey(), nextURI); try { final InputStream innerInputStream = s3Client .getObject(new S3Bucket(s3Bucket), s3Object.getKey()).getDataInputStream(); final InputStream outerInputStream = s3Object.getKey().endsWith(".gz") ? CompressionUtils.gzipInputStream(innerInputStream) : innerInputStream; return IOUtils.lineIterator( new BufferedReader(new InputStreamReader(outerInputStream, Charsets.UTF_8))); } catch (Exception e) { log.error(e, "Exception reading from bucket[%s] object[%s]", s3Bucket, s3Object.getKey()); throw Throwables.propagate(e); } } @Override public void remove() { throw new UnsupportedOperationException(); } }, firehoseParser); }
From source file:com.github.steveash.guavate.Guavate.java
/** * Creates a stream that wraps a stream with the index. * <p>/*from w ww . j a va 2 s.c o m*/ * Each input object is decorated with an {@link ObjIntPair}. * The {@code int} is the index of the element in the stream. * @param <T> the type of the stream * @param stream the stream to index * @return a stream of pairs, containing the element and index */ public static <T> Stream<ObjIntPair<T>> zipWithIndex(Stream<T> stream) { Spliterator<T> split1 = stream.spliterator(); Iterator<T> it1 = Spliterators.iterator(split1); Iterator<ObjIntPair<T>> it = new Iterator<ObjIntPair<T>>() { int index = 0; @Override public boolean hasNext() { return it1.hasNext(); } @Override public ObjIntPair<T> next() { return ObjIntPair.of(it1.next(), index++); } }; Spliterator<ObjIntPair<T>> split = Spliterators.spliterator(it, split1.getExactSizeIfKnown(), split1.characteristics()); return StreamSupport.stream(split, false); }