Example usage for java.util Iterator Iterator

List of usage examples for java.util Iterator Iterator

Introduction

In this page you can find the example usage for java.util Iterator Iterator.

Prototype

Iterator

Source Link

Usage

From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram1D.java

@Override
public Iterable<IScan1D> subsetByScanAcquisitionTime(double startSat, double stopSat) {
    final int startIndex = getIndexFor(startSat);
    if (startIndex < 0) {
        throw new ArrayIndexOutOfBoundsException(startIndex);
    }/*w w w.  j ava 2 s. co  m*/
    final int stopIndex = getIndexFor(stopSat);
    if (stopIndex > getNumberOfScans() - 1) {
        throw new ArrayIndexOutOfBoundsException(stopIndex);
    }
    final Iterator<IScan1D> iter = new Iterator<IScan1D>() {
        private int currentPos = startIndex;

        @Override
        public boolean hasNext() {
            return this.currentPos < stopIndex;
        }

        @Override
        public IScan1D next() {
            return getScan(this.currentPos++);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Can not remove scans with iterator!");
        }
    };
    return new Iterable<IScan1D>() {
        @Override
        public Iterator<IScan1D> iterator() {
            return iter;
        }
    };
}

From source file:oculus.aperture.common.JSONProperties.java

@Override
public Iterable<Float> getFloats(String key) {
    try {/*from   w w  w .  j  ava  2  s. c  om*/
        final JSONArray array = obj.getJSONArray(key);

        return new Iterable<Float>() {
            @Override
            public Iterator<Float> iterator() {
                return new Iterator<Float>() {
                    private final int n = array.length();
                    private int i = 0;

                    @Override
                    public boolean hasNext() {
                        return n > i;
                    }

                    @Override
                    public Float next() {
                        try {
                            return (n > i) ? (float) array.getDouble(i++) : null;
                        } catch (JSONException e) {
                            return null;
                        }
                    }

                    @Override
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }
        };

    } catch (JSONException e) {
        return EmptyIterable.instance();
    }
}

From source file:org.briljantframework.array.AbstractComplexArray.java

@Override
public Stream<Complex> stream() {
    return StreamSupport.stream(Spliterators.spliterator(new Iterator<Complex>() {
        int current = 0;

        @Override//from   w  w  w. j a  v a 2 s  .  c  o  m
        public boolean hasNext() {
            return current < size();
        }

        @Override
        public Complex next() {
            return get(current++);
        }
    }, size(), Spliterator.SIZED), false);
}

From source file:com.aliyun.odps.mapred.local.LocalTaskContext.java

@Override
public Iterator<Record> readResourceTable(String tbl) throws IOException {
    if (StringUtils.isEmpty(tbl)) {
        throw new IOException("Table resouce name is empty or null");
    }//from w  w  w.j  a v a2  s.c  o m

    if (!jobDirecotry.hasResource(tbl)) {
        String project = SessionState.get().getOdps().getDefaultProject();
        try {
            WareHouse.getInstance().copyResource(project, tbl, jobDirecotry.getResourceDir(),
                    WareHouse.getInstance().getLimitDownloadRecordCount(),
                    WareHouse.getInstance().getInputColumnSeperator());
        } catch (OdpsException e) {
        }
    }

    File dir = new File(jobDirecotry.getResourceDir(), tbl);
    LOG.info("Reading resource table from " + dir);
    final List<File> datafiles = new ArrayList<File>();

    LocalRunUtils.listAllDataFiles(dir, datafiles);

    final TableMeta tableMeta = SchemaUtils.readSchema(dir);

    return new Iterator<Record>() {
        RecordReader reader;
        Record current;
        boolean fetched;

        @Override
        public boolean hasNext() {
            if (fetched) {
                return current != null;
            }
            // Fetch new one
            try {
                fetch();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return current != null;

        }

        private void fetch() throws IOException {

            // first time
            if (reader == null) {
                if (datafiles.isEmpty()) {
                    current = null;
                    fetched = true;
                    return;
                }

                File f = datafiles.remove(0);
                reader = new CSVRecordReader(new FileSplit(f, tableMeta.getCols(), 0, f.getTotalSpace()),
                        tableMeta, LocalJobRunner.EMPTY_COUNTER, LocalJobRunner.EMPTY_COUNTER, counters,
                        WareHouse.getInstance().getInputColumnSeperator());
                current = reader.read();
                fetched = true;
                return;
            }

            current = reader.read();
            if (current == null && !datafiles.isEmpty()) {
                File f = datafiles.remove(0);
                reader = new CSVRecordReader(new FileSplit(f, tableMeta.getCols(), 0, f.getTotalSpace()),
                        tableMeta, LocalJobRunner.EMPTY_COUNTER, LocalJobRunner.EMPTY_COUNTER, counters,
                        WareHouse.getInstance().getInputColumnSeperator());
                current = reader.read();
                fetched = true;
                return;
            }

            fetched = true;
        }

        @Override
        public Record next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            fetched = false;
            return current;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }

    };
}

From source file:org.libreplan.business.planner.chart.ContiguousDaysLine.java

@Override
public Iterator<OnDay<T>> iterator() {
    final Iterator<T> iterator = values.iterator();
    return new Iterator<OnDay<T>>() {

        private LocalDate current = startInclusive;

        @Override//from   w  w w. j  a va  2  s.c o  m
        public boolean hasNext() {
            return iterator.hasNext();
        }

        @Override
        public OnDay<T> next() {
            T next = iterator.next();
            OnDay<T> result = new OnDay<T>(current, next);
            current = current.plusDays(1);
            return result;
        }

        @Override
        public void remove() throws UnsupportedOperationException {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:org.briljantframework.array.AbstractBooleanArray.java

@Override
public Stream<Boolean> stream() {
    return StreamSupport.stream(Spliterators.spliterator(new Iterator<Boolean>() {
        int current = 0;

        @Override//from www. j a v  a  2s.c o m
        public boolean hasNext() {
            return current < size();
        }

        @Override
        public Boolean next() {
            return get(current++);
        }
    }, size(), Spliterator.SIZED), false);
}

From source file:com.oltpbenchmark.util.CollectionUtil.java

/**
 * Wrap an Iterable around an Enumeration
 * @param <T>//  www . j a v a 2s .c om
 * @param e
 * @return
 */
public static <T> Iterable<T> iterable(final Enumeration<T> e) {
    return (new Iterable<T>() {
        @Override
        public Iterator<T> iterator() {
            return new Iterator<T>() {
                @Override
                public boolean hasNext() {
                    return (e.hasMoreElements());
                }

                @Override
                public T next() {
                    return (e.nextElement());
                }

                @Override
                public void remove() {
                    throw new NotImplementedException();
                }
            };
        }
    });
}

From source file:org.apache.taverna.scufl2.translator.t2flow.t23activities.ExternalToolActivityParser.java

@SuppressWarnings("unused")
private Iterable<Element> elementIter(final NodeList nodeList) {
    return new Iterable<Element>() {
        @Override/*from  w  w  w  . j a  v  a2  s  .c om*/
        public Iterator<Element> iterator() {
            return new Iterator<Element>() {
                int position = 0;

                @Override
                public boolean hasNext() {
                    return nodeList.getLength() > position;
                }

                @Override
                public Element next() {
                    return (Element) nodeList.item(position++);
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException();
                }
            };
        }
    };
}

From source file:org.apache.spark.sql.execution.vectorized.ColumnarBatch.java

/**
 * Returns an iterator over the rows in this batch. This skips rows that are filtered out.
 *///from   ww w  .  java  2 s. co m
public Iterator<Row> rowIterator() {
    final int maxRows = ColumnarBatch.this.numRows();
    final Row row = new Row(this);
    return new Iterator<Row>() {
        int rowId = 0;

        @Override
        public boolean hasNext() {
            while (rowId < maxRows && ColumnarBatch.this.filteredRows[rowId]) {
                ++rowId;
            }
            return rowId < maxRows;
        }

        @Override
        public Row next() {
            while (rowId < maxRows && ColumnarBatch.this.filteredRows[rowId]) {
                ++rowId;
            }
            if (rowId >= maxRows) {
                throw new NoSuchElementException();
            }
            row.rowId = rowId++;
            return row;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:net.sf.maltcms.chromaui.project.spi.descriptors.CachingChromatogram1D.java

@Override
public Iterable<IScan1D> subsetByScanIndex(final int startIndex, final int stopIndex) {
    if (startIndex < 0) {
        throw new ArrayIndexOutOfBoundsException(startIndex);
    }//from  w w  w.  j  a v  a  2s. co  m
    if (stopIndex > getNumberOfScans() - 1) {
        throw new ArrayIndexOutOfBoundsException(stopIndex);
    }
    final Iterator<IScan1D> iter = new Iterator<IScan1D>() {
        private int currentPos = startIndex;

        @Override
        public boolean hasNext() {
            return this.currentPos < stopIndex;
        }

        @Override
        public IScan1D next() {
            return getScan(this.currentPos++);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Can not remove scans with iterator!");
        }
    };
    return new Iterable<IScan1D>() {
        @Override
        public Iterator<IScan1D> iterator() {
            return iter;
        }
    };
}