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:Mersenne.java

public static Iterable<Mersenne> iterator() {
    return new Iterable<Mersenne>() {
        public Iterator<Mersenne> iterator() {
            return new MersenneIter();
        }//from  w w  w  .j a v  a  2  s  .  co  m
    };
}

From source file:org.apache.kylin.job.hadoop.invertedindex.IICLI.java

public static Iterable<IIRow> readSequenceKVs(Configuration hconf, String path) throws IOException {
    final Reader reader = new Reader(hconf, SequenceFile.Reader.file(new Path(path)));
    return new Iterable<IIRow>() {
        @Override/*from w  w  w .jav a2s  .  c  o  m*/
        public Iterator<IIRow> iterator() {
            return new Iterator<IIRow>() {
                ImmutableBytesWritable k = new ImmutableBytesWritable();
                ImmutableBytesWritable v = new ImmutableBytesWritable();
                IIRow pair = new IIRow(k, v, null);

                @Override
                public boolean hasNext() {
                    boolean hasNext = false;
                    try {
                        hasNext = reader.next(k, v);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    } finally {
                        if (hasNext == false) {
                            IOUtils.closeQuietly(reader);
                        }
                    }
                    return hasNext;
                }

                @Override
                public IIRow next() {
                    return pair;
                }

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

From source file:org.structr.rest.common.CsvHelper.java

public static Iterable<JsonInput> cleanAndParseCSV(final SecurityContext securityContext, final Reader input,
        final Class type, final Character fieldSeparator, final Character quoteCharacter, final String range,
        final Map<String, String> propertyMapping, final boolean strictQuotes)
        throws FrameworkException, IOException {

    final CSVReader reader;

    if (quoteCharacter == null) {

        reader = new CSVReader(input, fieldSeparator);

    } else {//from w  ww. j a  v a 2  s. co  m

        reader = new CSVReader(input, fieldSeparator, quoteCharacter, strictQuotes);
    }

    final String[] propertyNames = reader.readNext();

    return new Iterable<JsonInput>() {

        @Override
        public Iterator<JsonInput> iterator() {

            final Iterator<JsonInput> iterator = new CsvIterator(reader, propertyNames, propertyMapping, type,
                    securityContext.getUser(false).getName());

            if (StringUtils.isNotBlank(range)) {

                return new RangesIterator<>(iterator, range);

            } else {

                return iterator;
            }
        }
    };
}

From source file:org.grouplens.lenskit.collections.CollectionUtils.java

/**
 * Use the fast iterator of an iterable, if available.
 *
 * @param <E>  The type of object to iterate.
 * @param iter An iterable to wrap/*w  w w  . j  av a2 s .c  o m*/
 * @return An iterable using the underlying iterable's fast iterator, if present,
 *         to do iteration. Fast iteration is detected by looking for a {@code fastIterator()}
 *         method, like is present in {@link FastEntrySet}.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <E> Iterable<E> fast(final Iterable<E> iter) {
    if (iter instanceof FastIterable) {
        return new Iterable<E>() {
            @Override
            public Iterator<E> iterator() {
                return ((FastIterable) iter).fastIterator();
            }
        };
    } else if (iter instanceof Cursor) {
        return ((Cursor<E>) iter).fast();
    } else {
        Optional<Method> fastMethod = fastIteratorMethods.getUnchecked(iter.getClass());
        if (fastMethod.isPresent()) {
            final Method method = fastMethod.get();
            return new Iterable<E>() {
                @Override
                public Iterator<E> iterator() {
                    try {
                        return (Iterator<E>) method.invoke(iter);
                    } catch (IllegalAccessException e) {
                        return iter.iterator();
                    } catch (InvocationTargetException e) {
                        throw Throwables.propagate(e.getCause());
                    }
                }
            };
        } else {
            return iter;
        }
    }
}

From source file:org.eknet.neoswing.loader.DefaultGraphLoaderManager.java

@Override
public Iterable<String> getRegisteredLoaders() {
    return new Iterable<String>() {
        @Override//w w  w .  j  a v  a 2 s.c o m
        public Iterator<String> iterator() {
            return new FilterIterator<String>(loaders.keySet().iterator(), new Predicate<String>() {
                @Override
                public boolean evaluate(String s) {
                    GraphLoader gl = loaders.get(s);
                    return gl != null && gl.isSupported();
                }
            });
        }
    };
}

From source file:ch.systemsx.cisd.openbis.generic.server.business.bo.datasetlister.DatasetSetListingQueryFullTableScan.java

public Iterable<DatasetRecord> getDatasets(final LongSet datasetIds) {
    return new Iterable<DatasetRecord>() {
        public Iterator<DatasetRecord> iterator() {
            return new FilterIterator<DatasetRecord>(query.getDatasets(databaseInstanceId),
                    new Predicate<DatasetRecord>() {
                        public boolean evaluate(DatasetRecord dataset) {
                            return datasetIds.contains(dataset.id);
                        }// w  w w  .  java2  s. c o  m
                    });
        }
    };
}

From source file:org.opencastproject.oaipmh.harvester.ListRecordsResponse.java

/**
 * Get all records performing a complete request resuming any partial responses.
 *///from   w w  w  . ja v a  2s  .  com
public static Iterable<Node> getAllRecords(final ListRecordsResponse first,
        final OaiPmhRepositoryClient client) {
    return new Iterable<Node>() {
        @Override
        public Iterator<Node> iterator() {
            return new ResponseIterator(first) {
                @Override
                protected OaiPmhRepositoryClient getClient() {
                    return client;
                }

                @Override
                protected NodeList extractNodes(ListRecordsResponse response) {
                    return response.getRecords();
                }
            };
        }
    };
}

From source file:org.dataconservancy.archive.impl.elm.fs.FsMetadataStore.java

public Iterable<Metadata> getAll(final String... types) {

    final List<String> accepted = Arrays.asList(types);

    return new Iterable<Metadata>() {

        @SuppressWarnings("unchecked")
        public Iterator<Metadata> iterator() {

            final Iterator<File> fileIterator = FileUtils.iterateFiles(new File(getBaseDir()), getSuffix(),
                    true);/*from w ww  . j a v a  2  s  .  c  o m*/

            return new Iterator<Metadata>() {

                private Metadata next;

                {
                    advanceNext();
                }

                public boolean hasNext() {
                    return next != null;
                }

                public Metadata next() {
                    Metadata toReturn = next;
                    advanceNext();
                    return toReturn;
                }

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

                private void advanceNext() {

                    while (fileIterator.hasNext()) {
                        File candidate = fileIterator.next();
                        Metadata m = new FsMetadata(candidate);
                        if (accepted.isEmpty() || accepted.contains(m.getType())) {
                            next = m;
                            return;
                        }
                    }
                    next = null;
                }
            };
        }
    };
}

From source file:org.lenskit.util.math.Vectors.java

public static Iterable<Long2DoubleMap.Entry> fastEntries(final Long2DoubleMap map) {
    return new Iterable<Long2DoubleMap.Entry>() {
        @Override/*w w w .ja  v  a2s .  c o  m*/
        public Iterator<Long2DoubleMap.Entry> iterator() {
            return fastEntryIterator(map);
        }
    };
}

From source file:org.sybila.parasim.util.Iterables.java

public static <T> Iterable<T> concat(final Iterable<T>... iterables) {
    Validate.notNull(iterables);//  w w w  .j a v a 2  s.  c  o m
    if (iterables.length == 0) {
        throw new IllegalArgumentException("At least one iterable has to be given.");
    }
    return new Iterable<T>() {
        @Override
        public Iterator<T> iterator() {
            return new Iterator<T>() {

                private int currentIndex = 0;

                private Iterator<T> currentIterator = iterables[0].iterator();

                @Override
                public boolean hasNext() {
                    if (currentIterator.hasNext()) {
                        return true;
                    }
                    while (currentIndex < iterables.length - 1) {
                        currentIndex++;
                        currentIterator = iterables[currentIndex].iterator();
                        if (currentIterator.hasNext()) {
                            return true;
                        }
                    }
                    return false;
                }

                @Override
                public T next() {
                    if (hasNext()) {
                        return currentIterator.next();
                    }
                    return null;
                }

                @Override
                public void remove() {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            };
        }
    };
}