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.geogit.cli.plumbing.WalkGraph.java

@Override
public void runInternal(GeogitCLI cli) throws IOException {
    String ref;/* w  w w  . j  a v  a 2s.c o m*/
    if (refList.isEmpty()) {
        ref = null;
    } else {
        ref = refList.get(0);
    }
    Deduplicator deduplicator = cli.getGeogit().command(CreateDeduplicator.class).call();
    try {
        Iterator<RevObject> iter = cli.getGeogit() //
                .command(WalkGraphOp.class).setReference(ref) //
                .setDeduplicator(deduplicator) //
                // .setStrategy(lsStrategy) //
                .call();

        final ConsoleReader console = cli.getConsole();
        if (!iter.hasNext()) {
            if (ref == null) {
                console.println("The working tree is empty");
            } else {
                console.println("The specified path is empty");
            }
            return;
        }

        Function<RevObject, CharSequence> printFunctor = new Function<RevObject, CharSequence>() {
            @Override
            public CharSequence apply(RevObject input) {
                if (verbose) {
                    return String.format("%s: %s %s", input.getId(), input.getType(), input);
                } else {
                    return String.format("%s: %s", input.getId(), input.getType());
                }
            }
        };

        Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);

        while (lines.hasNext()) {
            console.println(lines.next());
        }
        console.flush();
    } finally {
        deduplicator.release();
    }
}

From source file:com.google.cloud.genomics.dataflow.utils.PairGenerator.java

/**
 * * Generates all combinations (not permutations) of pairs of the elements in the iterable.
 *
 * The pairs are often used as keys for results in many n^2 analyses where we end up with
 * (n*(n-1))/2 or ((n*(n-1))/2)+n results.
 *
 * @param list/*  w w w .j av a2  s  . c o m*/
 * @param comparator - used to enforce an order upon the elements within each pair
 * @return the pairs
 */
public <X, L extends List<? extends X> & RandomAccess> FluentIterable<KV<X, X>> allPairs(final L list,
        final Comparator<? super X> comparator) {
    return FluentIterable
            .from(ContiguousSet.create(Range.closedOpen(0, list.size()), DiscreteDomain.integers()))
            .transformAndConcat(new Function<Integer, Iterable<KV<X, X>>>() {
                @Override
                public Iterable<KV<X, X>> apply(final Integer i) {
                    return new Iterable<KV<X, X>>() {
                        @Override
                        public Iterator<KV<X, X>> iterator() {
                            int iteratorIndex = i;
                            if (!withReplacement) {
                                iteratorIndex++;
                            }
                            return Iterators.transform(list.listIterator(iteratorIndex),
                                    new Function<X, KV<X, X>>() {

                                        private final X key = list.get(i);

                                        @Override
                                        public KV<X, X> apply(X value) {
                                            boolean swap = 0 < comparator.compare(key, value);
                                            return KV.of(swap ? value : key, swap ? key : value);
                                        }
                                    });
                        }
                    };
                }
            });
}

From source file:io.crate.metadata.RoutineInfos.java

private Iterator<RoutineInfo> builtInCharFilters() {
    return Iterators.transform(ftResolver.getBuiltInCharFilters().iterator(),
            new Function<String, RoutineInfo>() {
                @Nullable/*from w ww.  j a  va2 s  .c o m*/
                @Override
                public RoutineInfo apply(@Nullable String input) {
                    return new RoutineInfo(input, RoutineType.CHAR_FILTER.getName());
                }
            });
}

From source file:com.thinkbiganalytics.metadata.modeshape.sla.JcrObligationGroup.java

@Override
public List<Obligation> getObligations() {
    try {//w  w w. j a v a  2  s  .c om
        @SuppressWarnings("unchecked")
        Iterator<Node> itr = (Iterator<Node>) this.node.getNodes("tba:obligations");

        return Lists.newArrayList(Iterators.transform(itr, (obNode) -> {
            return JcrUtil.createJcrObject(obNode, JcrObligation.class, JcrObligationGroup.this);
        }));
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException("Failed to retrieve the obligation nodes", e);
    }

}

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

private Iterator<Triple> zipPropertiesToTriples(final Iterator<Property> propertyIterator,
        final Iterator<Property> propertyIteratorCopy) {
    return Iterators.concat(new ZippingIterator<>(Iterators.transform(propertyIterator, property2values),
            Iterators.transform(propertyIteratorCopy, property2triple)));
}

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

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

            //Constructing ProfileInfo
            final String queryID = input.getKey();
            String profileJson;
            try {
                profileJson = new String(profileSerializer.serialize(input.getValue()));
            } catch (IOException e) {
                logger.debug("Failed to serialize profile for: " + queryID, e);
                profileJson = "{ 'message' : 'error (unable to serialize profile: " + queryID + ")' }";
            }

            return new ProfileJson(queryID, profileJson);
        }
    });
}

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

private Iterator<Triple> triplesFromProperties(final FedoraResource n) throws RepositoryException {
    LOGGER.trace("Creating triples for node: {}", n);

    final Iterator<Property> allProperties;
    if (n instanceof FedoraBinary) {
        final FedoraResource description = ((FedoraBinary) n).getDescription();
        allProperties = Iterators.concat(n.getNode().getProperties(), description.getNode().getProperties());
    } else {/*from   www. j ava 2s .  c  om*/
        allProperties = n.getNode().getProperties();
    }

    final UnmodifiableIterator<Property> properties = Iterators.filter(allProperties, not(isInternalProperty));
    return Iterators.concat(Iterators.transform(properties, property2triple));

}

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

/**
 * Ordinary constructor./*from www .  j  a  v a2  s. c  o  m*/
 *
 * @param resource the resource
 * @param idTranslator the id translator
 * @param blobs the blobs
 * @param digest the digest uri
 * @param size the size
 */
public FixityRdfContext(final FedoraResource resource,
        final IdentifierConverter<Resource, FedoraResource> idTranslator, final Iterable<FixityResult> blobs,
        final URI digest, final long size) {
    super(resource, idTranslator);

    concat(Iterators.concat(Iterators.transform(blobs.iterator(),
            new FixityResultIteratorFunction(resource, idTranslator, digest, size))));
}

From source file:org.javersion.util.AbstractTrieSet.java

@SuppressWarnings("unchecked")
public Iterator<E> iterator() {
    return Iterators.transform(doIterator(), ENTRY_TO_ELEMENT);
}

From source file:nz.ac.massey.cs.guery.adapters.blueprints.BlueprintsAdapter.java

@Override
public Iterator<Edge> getInEdges(Vertex vertex) {
    return Iterators.transform(vertex.getEdges(Direction.IN).iterator(), this.edgeCaching);
}