Example usage for com.google.common.collect Iterators transform

List of usage examples for com.google.common.collect Iterators transform

Introduction

In this page you can find the example usage for com.google.common.collect Iterators transform.

Prototype

public static <F, T> Iterator<T> transform(final Iterator<F> fromIterator,
        final Function<? super F, ? extends T> function) 

Source Link

Document

Returns an iterator that applies function to each element of fromIterator .

Usage

From source file:org.apache.mahout.common.iterator.StringRecordIterator.java

public StringRecordIterator(Iterable<String> stringIterator, String pattern) {
    this.splitter = Pattern.compile(pattern);
    delegate = Iterators.transform(stringIterator.iterator(), new Function<String, Pair<List<String>, Long>>() {
        @Override/*from w ww. j av a2s .c  o m*/
        public Pair<List<String>, Long> apply(String from) {
            String[] items = splitter.split(from);
            return new Pair<List<String>, Long>(Arrays.asList(items), ONE);
        }
    });
}

From source file:org.apache.gobblin.data.management.copy.IterableCopyableDatasetImpl.java

private static Iterator<FileSet<CopyEntity>> partitionCopyableFiles(Dataset dataset,
        Collection<? extends CopyEntity> files) {
    Map<String, FileSet.Builder<CopyEntity>> partitionBuildersMaps = Maps.newHashMap();
    for (CopyEntity file : files) {
        if (!partitionBuildersMaps.containsKey(file.getFileSet())) {
            partitionBuildersMaps.put(file.getFileSet(), new FileSet.Builder<>(file.getFileSet(), dataset));
        }//from  ww  w.  jav a2 s.c o m
        partitionBuildersMaps.get(file.getFileSet()).add(file);
    }
    return Iterators.transform(partitionBuildersMaps.values().iterator(),
            new Function<FileSet.Builder<CopyEntity>, FileSet<CopyEntity>>() {
                @Nullable
                @Override
                public FileSet<CopyEntity> apply(@Nonnull FileSet.Builder<CopyEntity> input) {
                    return input.build();
                }
            });
}

From source file:biz.ganttproject.impex.csv.CsvReaderImpl.java

@Override
public Iterator<SpreadsheetRecord> iterator() {
    return Iterators.transform(myParser.iterator(), CsvRecordImpl::new);
}

From source file:ai.grakn.graql.internal.reasoner.iterator.LazyAnswerIterator.java

public LazyAnswerIterator unify(Unifier unifier) {
    if (unifier.isEmpty())
        return this;
    Iterator<Answer> transform = Iterators.transform(iterator(), input -> {
        if (input == null)
            return null;
        return input.unify(unifier);
    });//from  www.j a v a  2 s  . com
    return new LazyAnswerIterator(transform);
}

From source file:net.automatalib.graphs.IndefiniteGraph.java

@Override
default Iterator<N> adjacentTargetsIterator(N node) {
    return Iterators.transform(outgoingEdgesIterator(node), this::getTarget);
}

From source file:com.cloudera.exhibit.mongodb.BSONFrame.java

@Override
public Iterator<Obs> iterator() {
    return Iterators.transform(records.iterator(), new Function<BSONObject, Obs>() {
        @Override/*from w w w . j  av  a2 s . c  o  m*/
        public Obs apply(BSONObject bsonObject) {
            return new BSONObs(descriptor, bsonObject);
        }
    });
}

From source file:org.sonatype.nexus.timeline.TimelineResultWrapper.java

@Override
public Iterator<Entry> iterator() {
    return Iterators.transform(result.iterator(), new Function<TimelineRecord, Entry>() {
        @Override/*  ww  w . j a  v  a2 s  . c  o m*/
        public Entry apply(@Nullable final TimelineRecord input) {
            return new TimelineRecordWrapper(input);
        }
    });
}

From source file:org.apache.gobblin.util.request_allocation.StringRequestor.java

@Override
public Iterator<StringRequest> iterator() {
    return Iterators.transform(this.strings.iterator(), new Function<String, StringRequest>() {
        @Override/*from   ww w.  j ava2 s  . c o m*/
        public StringRequest apply(String input) {
            return new StringRequest(StringRequestor.this, input);
        }
    });
}

From source file:ch.ethz.inf.vs.hypermedia.corehal.LinkList.java

public Iterable<Link> linkValues() {
    return () -> Iterators.concat(Iterators.transform(values().iterator(), (x) -> x.iterator()));
}

From source file:com.github.rinde.opt.localsearch.Insertions.java

/**
 * Creates an {@link Iterator} for a list of lists, each list contains a
 * specified number of insertions of <code>item</code> at a different position
 * in the list. Only creates insertions starting at <code>startIndex</code>.
 * @param list The original list.//from www . j a v  a  2  s  . co m
 * @param item The item to be inserted.
 * @param startIndex Must be &ge; 0 &amp;&amp; &le; list size.
 * @param numOfInsertions The number of times <code>item</code> is inserted.
 * @param <T> The list item type.
 * @return Iterator producing a list of lists of size
 *         <code>(n+1)-startIndex</code>.
 */
public static <T> Iterator<ImmutableList<T>> insertionsIterator(ImmutableList<T> list, T item, int startIndex,
        int numOfInsertions) {
    checkArgument(startIndex >= 0 && startIndex <= list.size(),
            "startIndex must be >= 0 and <= %s (list size), it is %s.", list.size(), startIndex);
    checkArgument(numOfInsertions > 0, "numOfInsertions must be positive.");
    return Iterators.transform(new InsertionIndexGenerator(numOfInsertions, list.size(), startIndex),
            new IndexToInsertionTransform<T>(list, item));
}