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.fluo.recipes.core.export.ExportObserverImpl.java

@Override
public void process(TransactionBase tx, Bytes row, Column col) throws Exception {
    ExportBucket bucket = new ExportBucket(tx, row);

    Bytes continueRow = bucket.getContinueRow();

    Iterator<ExportEntry> input = bucket.getExportIterator(continueRow);
    MemLimitIterator memLimitIter = new MemLimitIterator(input, memLimit, 8 + queueId.length());

    Iterator<SequencedExport<K, V>> exportIterator = Iterators.transform(memLimitIter,
            ee -> new SequencedExport<>(serializer.deserialize(ee.key, keyType),
                    serializer.deserialize(ee.value, valType), ee.seq));

    exportIterator = Iterators.consumingIterator(exportIterator);

    exporter.export(exportIterator);// w  ww . j  a  va 2s . co  m

    if (input.hasNext() || continueRow != null) {
        // not everything was processed so notify self OR new data may have been inserted above the
        // continue row
        bucket.notifyExportObserver();
    }

    if (input.hasNext()) {
        if (!memLimitIter.hasNext()) {
            // stopped because of mem limit... set continue key
            bucket.setContinueRow(input.next());
            continueRow = null;
        }
    }

    if (continueRow != null) {
        bucket.clearContinueRow();
    }
}

From source file:org.hashtrees.manager.HashTreesManagerObserverNotifier.java

private void notifyObservers(Function<HashTreesManagerObserver, Void> function) {
    Iterator<Void> itr = Iterators.transform(observers.iterator(), function);
    while (itr.hasNext())
        itr.next();//from w  ww.  ja  v  a  2s  .  co  m
}

From source file:org.apache.drill.exec.store.sys.ProfileInfoIterator.java

/**
 * Iterating persistentStore as a iterator of {@link org.apache.drill.exec.store.sys.ProfileInfoIterator.ProfileInfo}.
 *//*from   w w  w .  j  a  va 2  s.co  m*/
private Iterator<ProfileInfo> transform(Iterator<Entry<String, UserBitShared.QueryProfile>> all) {
    return Iterators.transform(all, new Function<Entry<String, UserBitShared.QueryProfile>, ProfileInfo>() {
        @Nullable
        @Override
        public ProfileInfo apply(@Nullable Entry<String, UserBitShared.QueryProfile> input) {
            if (input == null || input.getValue() == null) {
                return ProfileInfo.getDefault();
            }

            //Constructing ProfileInfo
            final String queryID = input.getKey();
            final QueryProfile profile = input.getValue();
            //For cases where query was never queued
            final long assumedQueueEndTime = profile.getQueueWaitEnd() > 0 ? profile.getQueueWaitEnd()
                    : profile.getPlanEnd();
            return new ProfileInfo(queryID, new Timestamp(profile.getStart()),
                    profile.getForeman().getAddress(), profile.getTotalFragments(), profile.getUser(),
                    profile.getQueueName(), computeDuration(profile.getStart(), profile.getPlanEnd()),
                    computeDuration(profile.getPlanEnd(), assumedQueueEndTime),
                    computeDuration(assumedQueueEndTime, profile.getEnd()), profile.getState().name(),
                    profile.getQuery());
        }
    });
}

From source file:net.myrrix.online.candidate.ExampleCandidateFilter.java

@Override
public Collection<Iterator<FastByIDMap.MapEntry<float[]>>> getCandidateIterator(float[][] userVectors) {
    Lock readLock = lock.readLock();
    readLock.lock();/*  w w w .java 2s. c o  m*/
    try {
        return Collections
                .singleton(Iterators.transform(someCurrentIDs.iterator(), new RetrieveEntryFunction()));
    } finally {
        readLock.unlock();
    }
}

From source file:com.comphenix.protocol.wrappers.nbt.ConvertedCollection.java

@Override
public Iterator<VOuter> iterator() {
    return Iterators.transform(inner.iterator(), getOuterConverter());
}

From source file:org.fcrepo.kernel.rdf.impl.FixityRdfContext.java

/**
 * Ordinary constructor.//from www  . j av a 2s .co  m
 *
 * @param node
 * @param graphSubjects
 * @param blobs
 * @throws RepositoryException
 */
public FixityRdfContext(final Node node, final IdentifierTranslator graphSubjects,
        final Iterable<FixityResult> blobs) throws RepositoryException {
    super(node, graphSubjects);

    concat(Iterators
            .concat(Iterators.transform(blobs.iterator(), new Function<FixityResult, Iterator<Triple>>() {

                @Override
                public Iterator<Triple> apply(final FixityResult blob) {
                    final com.hp.hpl.jena.graph.Node resultSubject = getTransientFixitySubject();
                    final ImmutableSet.Builder<Triple> b = builder();
                    try {
                        b.add(create(resultSubject, RDF.type.asNode(), FIXITY_TYPE.asNode()));
                        b.add(create(graphSubjects.getSubject(node.getPath()).asNode(),
                                HAS_FIXITY_RESULT.asNode(), resultSubject));
                        final String storeIdentifier = blob.getStoreIdentifier();
                        final com.hp.hpl.jena.graph.Node contentLocation = createResource(storeIdentifier)
                                .asNode();
                        b.add(create(resultSubject, HAS_CONTENT_LOCATION.asNode(), contentLocation));
                        b.add(create(contentLocation, RDF.type.asNode(), CONTENT_LOCATION_TYPE.asNode()));
                        b.add(create(contentLocation, HAS_CONTENT_LOCATION_VALUE.asNode(),
                                createLiteral(storeIdentifier)));

                        for (final FixityResult.FixityState state : blob.getStatus()) {
                            b.add(create(resultSubject, HAS_FIXITY_STATE.asNode(),
                                    createLiteral(state.toString())));
                        }
                        final String checksum = blob.getComputedChecksum().toString();
                        b.add(create(resultSubject, HAS_MESSAGE_DIGEST.asNode(), createURI(checksum)));
                        b.add(create(resultSubject, HAS_SIZE.asNode(),
                                createTypedLiteral(blob.getComputedSize()).asNode()));
                        return b.build().iterator();
                    } catch (final RepositoryException e) {
                        throw propagate(e);
                    }
                }
            })));
}

From source file:org.grouplens.lenskit.util.table.RowImpl.java

@Override
public Iterator<Object> iterator() {
    return Iterators.transform(layout.getColumns().iterator(), VALUE_FUNCTION);
}

From source file:de.cosmocode.palava.workqueue.ConfigurableDelayQueue.java

@Override
public Iterator<E> iterator() {
    return Iterators.transform(queue.iterator(), extractor);
}

From source file:io.druid.java.util.common.guava.FunctionalIterator.java

public <RetType> FunctionalIterator<RetType> keep(Function<T, RetType> fn) {
    return new FunctionalIterator<>(Iterators.filter(Iterators.transform(delegate, fn), Predicates.notNull()));
}

From source file:net.automatalib.commons.smartcollections.AbstractSmartCollection.java

@Override
public Iterator<E> iterator() {
    return Iterators.transform(referenceIterator(), this::get);
}