List of usage examples for java.util Iterator Iterator
Iterator
From source file:org.broadinstitute.gatk.utils.pileup.PileupElementTracker.java
public Iterable<PE> unorderedIterable() { return new Iterable<PE>() { @Override//from www. j av a 2s . c o m public Iterator<PE> iterator() { return new Iterator<PE>() { final private IteratorChain chain = new IteratorChain(); { // initialize the chain with the unordered iterators of the per sample pileups for (PileupElementTracker<PE> pet : pileup.values()) { chain.addIterator(pet.unorderedIterator()); } } @Override public boolean hasNext() { return chain.hasNext(); } @Override public PE next() { return (PE) chain.next(); } @Override public void remove() { throw new UnsupportedOperationException("Cannot remove"); } }; } }; }
From source file:org.broadinstitute.gatk.utils.MathUtilsUnitTest.java
@DataProvider(name = "log10OneMinusPow10Data") public Iterator<Object[]> log10OneMinusPow10Data() { final double[] inValues = new double[] { Double.NaN, 10, 1, 0, -1, -3, -10, -30, -100, -300, -1000, -3000 }; return new Iterator<Object[]>() { private int i = 0; @Override/*from w ww . ja v a 2 s . c om*/ public boolean hasNext() { return i < inValues.length; } @Override public Object[] next() { final double input = inValues[i++]; final double output = Math.log10(1 - Math.pow(10, input)); return new Object[] { input, output }; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:backup.store.local.LocalBackupStore.java
private Iterator<ExtendedBlock> getExtendedBlocks(File pool) { List<File> list = Arrays.asList(pool.listFiles((FileFilter) pathname -> pathname.getName().endsWith(DATA))); Iterator<File> iterator = list.iterator(); return new Iterator<ExtendedBlock>() { @Override/*from www. j a v a 2s .c o m*/ public boolean hasNext() { return iterator.hasNext(); } @Override public ExtendedBlock next() { return toExtendedBlock(iterator.next()); } }; }
From source file:MicroMap.java
/** * @see java.util.Map#keySet()//from w w w .j a v a2 s . c o m */ public Set<K> keySet() { return new AbstractSet<K>() { @Override public Iterator<K> iterator() { return new Iterator<K>() { public boolean hasNext() { return index < MicroMap.this.size(); } public K next() { if (!hasNext()) { throw new NoSuchElementException(); } index++; return key; } public void remove() { MicroMap.this.clear(); } int index; }; } @Override public int size() { return MicroMap.this.size(); } }; }
From source file:org.apache.phoenix.index.PhoenixTransactionalIndexer.java
private static Iterator<Mutation> getMutationIterator( final MiniBatchOperationInProgress<Mutation> miniBatchOp) { return new Iterator<Mutation>() { private int i = 0; @Override/*from w ww. ja v a 2s .c o m*/ public boolean hasNext() { return i < miniBatchOp.size(); } @Override public Mutation next() { return miniBatchOp.getOperation(i++); } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
From source file:org.jiemamy.entity.io.meta.EntityMeta.java
/** * ?????????{@link Iterable}??//from www . jav a2s. co m * * @return ?????????{@link Iterable} */ public Iterable<PropertyMeta> getAllColumnPropertyMeta() { return new Iterable<PropertyMeta>() { public Iterator<PropertyMeta> iterator() { return new Iterator<PropertyMeta>() { private int i; public boolean hasNext() { return i < columnPropertyMetas.size(); } public PropertyMeta next() { return columnPropertyMetas.get(i++); } public void remove() { throw new UnsupportedOperationException(); } }; } }; }
From source file:org.apache.sling.pipes.JsonPipe.java
/** * in case there is no successful retrieval of some JSON data, we cut the pipe here * @return/* w ww. ja v a 2 s . c om*/ */ public Iterator<Resource> getOutput() { Iterator<Resource> output = EMPTY_ITERATOR; binding = null; String jsonString = retrieveJSONString(); if (StringUtils.isNotBlank(jsonString)) { try { JSONTokener tokener = new JSONTokener(jsonString); char firstChar = tokener.next(); if (firstChar == '[') { binding = array = new JSONArray(jsonString); index = 0; output = new Iterator<Resource>() { @Override public boolean hasNext() { return index < array.length(); } @Override public Resource next() { try { binding = array.get(index); } catch (Exception e) { logger.error("Unable to retrieve {}nth item of jsonarray", index, e); } index++; return getInput(); } }; } else if (firstChar == '{') { binding = new JSONObject(jsonString); output = super.getOutput(); } else { //simple string binding = jsonString; output = super.getOutput(); } } catch (JSONException e) { logger.error("unable to parse JSON {} ", jsonString, e); } } return output; }
From source file:edu.dfci.cccb.mev.hcl.domain.simple.SimpleTwoDimensionalHclBuilder.java
private Node cluster(final Dataset dataset, Dimension dimension, Metric metric, Linkage linkage) throws DatasetException { final Type dimensionType = dimension.type(); final RealMatrix original = toRealMatrix(dataset); final int size = dimensionType == ROW ? original.getRowDimension() : original.getColumnDimension(); final int other = dimensionType == COLUMN ? original.getRowDimension() : original.getColumnDimension(); Iterator<Integer> enumerator = new Iterator<Integer>() { private int counter = -1; @Override/*from ww w . j ava 2 s . com*/ public boolean hasNext() { return true; } @Override public Integer next() { counter--; if (counter > 0) counter = -1; return counter; } @Override public void remove() { throw new UnsupportedOperationException(); } }; final double[][] distances = new double[size][size]; log.debug("Populating node hash"); final Map<Integer, Node> genehash = new HashMap<Integer, Node>() { private static final long serialVersionUID = 1L; { for (int index = size; --index >= 0; put(index, nodeBuilder().leaf(dataset.dimension(dimensionType).keys().get(index)))) ; } }; TreeMap<Double, int[]> sorted = new TreeMap<>(); log.debug("Populating distance matrix"); for (int i = 0; i < size; i++) { for (int j = i + 1; j < size; j++) { double distance = metric.distance(new AbstractList<Double>() { private int i; @Override public Double get(int index) { return dimensionType == ROW ? original.getEntry(i, index) : original.getEntry(index, i); } @Override public int size() { return other; } private List<Double> initializeProjection(int i) { this.i = i; return this; } }.initializeProjection(i), new AbstractList<Double>() { private int j; @Override public Double get(int index) { return dimensionType == ROW ? original.getEntry(j, index) : original.getEntry(index, j); } @Override public int size() { return other; } private List<Double> initializeProjection(int j) { this.j = j; return this; } }.initializeProjection(j)); distances[i][j] = distance; distances[j][i] = distance; int[] genePair = { i, j }; // Enter the distance calculated and the genes measured into a // treemap. Will be automatically sorted. sorted.put(distance, genePair); } } log.debug("Aggregating"); while (true) { // Get the first key of the TreeMap. Will be the shortest distance de // facto. final double minkey = (Double) sorted.firstKey(); int[] minValues = (int[]) sorted.firstEntry().getValue(); final int value1 = minValues[0], value2 = minValues[1]; // find Node cluster = nodeBuilder().branch(minkey, genehash.get(value1), genehash.get(value2)); int id = enumerator.next(); genehash.put(id, cluster); genehash.remove(value1); genehash.remove(value2); if (genehash.size() <= 1) break; // Iterate over all the current clusters to remeasure distance with the // previously clustered group. for (Entry<Integer, Node> e : genehash.entrySet()) { Node c = e.getValue(); // Skip measuring the new cluster with itself. if (c == cluster) continue; List<Double> aggregation = new ArrayList<>(); // Get genes from each cluster. Distance is measured from each element // to every element. for (int current : traverse(dimension.keys(), c)) for (int created : traverse(dimension.keys(), cluster)) aggregation.add(distances[current][created]); int[] valuePair = { e.getKey(), id }; sorted.put(linkage.aggregate(aggregation), valuePair); } // Get the shortest distance. // Check to make sure shortest distance does not include a gene pair // that // has already had its elements clustered. boolean minimized = false; while (!minimized) { double mk = sorted.firstKey(); minValues = sorted.firstEntry().getValue(); // If the gene pair is not present in the current gene set, remove // this distance. if (!genehash.containsKey(minValues[0]) || !genehash.containsKey(minValues[1])) sorted.remove(mk); else minimized = true; } } Node result = genehash.entrySet().iterator().next().getValue(); log.debug("Clustered " + result); return result; }
From source file:com.px100systems.util.CsvParser.java
/** * Parsing into a list of lists (headerless) * * @param is input stream/*from w w w . j av a 2 s . c o m*/ * @return a List of Lists of (String) fields */ @SuppressWarnings("unused") public Iterator<List<String>> parseHeaderlessAsMap(InputStream is) { final CSVParser parser = new CSVParser(new BufferedReader(new InputStreamReader(is)), csvStrategy); return new Iterator<List<String>>() { @Override public boolean hasNext() { try { currentLine = parser.getLine(); return currentLine != null; } catch (Exception e) { throw new RuntimeException(e); } } @Override public List<String> next() { return Arrays.asList(currentLine); } }; }
From source file:com.facebook.hive.orc.ReaderImpl.java
@Override public Iterable<StripeInformation> getStripes() { return new Iterable<com.facebook.hive.orc.StripeInformation>() { @Override// w w w .j a va 2s . c o m public Iterator<com.facebook.hive.orc.StripeInformation> iterator() { return new Iterator<com.facebook.hive.orc.StripeInformation>() { private final Iterator<OrcProto.StripeInformation> inner = footer.getStripesList().iterator(); @Override public boolean hasNext() { return inner.hasNext(); } @Override public com.facebook.hive.orc.StripeInformation next() { return new StripeInformationImpl(inner.next()); } @Override public void remove() { throw new UnsupportedOperationException("remove unsupported"); } }; } }; }