Example usage for java.lang Iterable Iterable

List of usage examples for java.lang Iterable Iterable

Introduction

In this page you can find the example usage for java.lang Iterable Iterable.

Prototype

Iterable

Source Link

Usage

From source file:com.wavemaker.commons.io.store.StoredFolder.java

@Override
public Resources<Resource> list() {
    if (!exists()) {
        return new ResourcesCollection<Resource>(this);
    }/*from w w  w. ja  va 2  s  .  c  o m*/
    return new ChildResources(new Iterable<Resource>() {

        @Override
        public Iterator<Resource> iterator() {
            return new ChildResourceIterator(StoredFolder.this);
        }
    });
}

From source file:org.grouplens.lenskit.vectors.Vectors.java

/**
 * Iterate over the intersection of two vectors without the overhead of object creation.
 * @param v1 The first vector.//  w  w w . ja v a 2 s .  c  o m
 * @param v2 The second vector.
 * @return A fast iterator over the common keys of the two vectors.
 * @see #intersect(SparseVector, SparseVector)
 */
public static Iterable<Pair<VectorEntry, VectorEntry>> fastIntersect(final SparseVector v1,
        final SparseVector v2) {
    return new Iterable<Pair<VectorEntry, VectorEntry>>() {
        @Override
        public Iterator<Pair<VectorEntry, VectorEntry>> iterator() {
            return new FastIntersectIterImpl(v1, v2);
        }
    };
}

From source file:org.springframework.boot.actuate.metrics.reader.MetricRegistryMetricReader.java

@Override
public Iterable<Metric<?>> findAll() {
    return new Iterable<Metric<?>>() {
        @Override/*from  w w w .  j  a v  a 2  s. co m*/
        public Iterator<Metric<?>> iterator() {
            Set<Metric<?>> metrics = new HashSet<Metric<?>>();
            for (String name : MetricRegistryMetricReader.this.names.keySet()) {
                Metric<?> metric = findOne(name);
                if (metric != null) {
                    metrics.add(metric);
                }
            }
            return metrics.iterator();
        }
    };
}

From source file:org.apache.tez.runtime.library.common.ValuesIterator.java

public Iterable<VALUE> getValues() {
    return new Iterable<VALUE>() {

        @Override//from   ww  w .jav  a 2  s .  c  o m
        public Iterator<VALUE> iterator() {

            return new Iterator<VALUE>() {

                private final int keyNumber = keyCtr;

                @Override
                public boolean hasNext() {
                    return hasMoreValues;
                }

                @Override
                public VALUE next() {
                    if (!hasMoreValues) {
                        throw new NoSuchElementException("iterate past last value");
                    }
                    Preconditions.checkState(keyNumber == keyCtr,
                            "Cannot use values iterator on the previous K-V pair after moveToNext has been invoked to move to the next K-V pair");

                    try {
                        readNextValue();
                        readNextKey();
                    } catch (IOException ie) {
                        throw new RuntimeException("problem advancing post rec#" + keyCtr, ie);
                    }
                    inputValueCounter.increment(1);
                    return value;
                }

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

From source file:com.wavemaker.commons.io.store.StoredFolder.java

@Override
public Resources<Resource> find() {
    if (!exists()) {
        return new ResourcesCollection<Resource>(this);
    }/*from ww w .j  av a2s  .  c om*/
    return new ChildResources(new Iterable<Resource>() {

        @Override
        public Iterator<Resource> iterator() {
            return new RecursiveChildResourceIterator(StoredFolder.this);
        }
    });
}

From source file:org.pentaho.platform.plugin.services.importexport.legacy.DbSolutionRepositoryImportSource.java

/**
 * @return/*from   w ww . jav  a2  s  . c o m*/
 */
public Iterable<IRepositoryFileBundle> getFiles() {
    Assert.hasLength(requiredCharset);
    return new Iterable<IRepositoryFileBundle>() {
        public Iterator<IRepositoryFileBundle> iterator() {
            return new RepositoryFileBundleIterator();
        }
    };
}

From source file:org.broadinstitute.gatk.utils.pileup.PileupElementTracker.java

public Iterable<PE> unorderedIterable() {
    return new Iterable<PE>() {
        @Override// w ww.  j a  v  a2  s  .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.vafer.jdependency.Clazzpath.java

public ClazzpathUnit addClazzpathUnit(final InputStream pInputStream, final String pId) throws IOException {
    final JarInputStream inputStream = new JarInputStream(pInputStream);
    try {/*from  w w  w.  j a va2  s  .c om*/
        final JarEntry[] entryHolder = new JarEntry[1];

        return addClazzpathUnit(new Iterable<Resource>() {

            public Iterator<Resource> iterator() {
                return new Iterator<Resource>() {

                    public boolean hasNext() {
                        try {
                            do {
                                entryHolder[0] = inputStream.getNextJarEntry();
                            } while (entryHolder[0] != null && !Resource.isValidName(entryHolder[0].getName()));
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                        return entryHolder[0] != null;
                    }

                    public Resource next() {
                        return new Resource(entryHolder[0].getName()) {

                            @Override
                            InputStream getInputStream() {
                                return inputStream;
                            }
                        };
                    }

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

                };
            }
        }, pId, false);
    } finally {
        inputStream.close();
    }
}

From source file:org.apache.camel.processor.Splitter.java

@SuppressWarnings("unchecked")
private Iterable<ProcessorExchangePair> createProcessorExchangePairsIterable(final Exchange exchange,
        final Object value) {
    final Iterator iterator = ObjectHelper.createIterator(value);
    return new Iterable() {
        // create a copy which we use as master to copy during splitting
        // this avoids any side effect reflected upon the incoming exchange
        private final Exchange copy = ExchangeHelper.createCopy(exchange, true);
        private final RouteContext routeContext = exchange.getUnitOfWork() != null
                ? exchange.getUnitOfWork().getRouteContext()
                : null;//from   ww w  . ja  v  a2 s . c  om

        public Iterator iterator() {
            return new Iterator() {
                private int index;
                private boolean closed;

                public boolean hasNext() {
                    if (closed) {
                        return false;
                    }

                    boolean answer = iterator.hasNext();
                    if (!answer) {
                        // we are now closed
                        closed = true;
                        // nothing more so we need to close the expression value in case it needs to be
                        if (value instanceof Closeable) {
                            IOHelper.close((Closeable) value, value.getClass().getName(), LOG);
                        } else if (value instanceof Scanner) {
                            // special for Scanner as it does not implement Closeable
                            ((Scanner) value).close();
                        }
                    }
                    return answer;
                }

                public Object next() {
                    Object part = iterator.next();
                    // create a correlated copy as the new exchange to be routed in the splitter from the copy
                    // and do not share the unit of work
                    Exchange newExchange = ExchangeHelper.createCorrelatedCopy(copy, false);
                    if (part instanceof Message) {
                        newExchange.setIn((Message) part);
                    } else {
                        Message in = newExchange.getIn();
                        in.setBody(part);
                    }
                    return createProcessorExchangePair(index++, getProcessors().iterator().next(), newExchange,
                            routeContext);
                }

                public void remove() {
                    throw new UnsupportedOperationException("Remove is not supported by this iterator");
                }
            };
        }

    };
}

From source file:com.facebook.hive.orc.ReaderImpl.java

@Override
public Iterable<StripeInformation> getStripes() {
    return new Iterable<com.facebook.hive.orc.StripeInformation>() {

        @Override//  w ww .  ja  v  a  2  s. 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");
                }
            };
        }
    };
}