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:qdg.StaticMixedGraph.java

@Override
public Iterator<Edge> getUEdgeIterator() {
    return Iterators.transform(new IndexIterator<EdgeData>(uEdges), constructUEdge);
}

From source file:org.geogit.remote.BinaryPackedObjects.java

private ImmutableList<ObjectId> reachableContentIds(ImmutableList<ObjectId> needsPrevisit,
        Deduplicator deduplicator) {/*  ww  w .java 2  s  .c o m*/
    Function<RevObject, ObjectId> getIdTransformer = new Function<RevObject, ObjectId>() {
        @Override
        @Nullable
        public ObjectId apply(@Nullable RevObject input) {
            return input == null ? null : input.getId();
        }
    };

    Iterator<ObjectId> reachable = Iterators.transform( //
            PostOrderIterator.contentsOf(needsPrevisit, database, deduplicator), //
            getIdTransformer);
    return ImmutableList.copyOf(reachable);
}

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

/**
 * Get the member relations assert on the subject by the given node
 * @param container//w ww. ja va  2s.c  om
 * @return
 * @throws RepositoryException
 */
private Iterator<Triple> memberRelations(final FedoraResource container) throws RepositoryException {
    final com.hp.hpl.jena.graph.Node memberRelation;

    if (container.hasProperty(LDP_HAS_MEMBER_RELATION)) {
        final Property property = container.getProperty(LDP_HAS_MEMBER_RELATION);
        memberRelation = createURI(property.getString());
    } else if (container.hasType(LDP_BASIC_CONTAINER)) {
        memberRelation = LDP_MEMBER.asNode();
    } else {
        return emptyIterator();
    }

    final String insertedContainerProperty;

    if (container.hasType(LDP_INDIRECT_CONTAINER)) {
        if (container.hasProperty(LDP_INSERTED_CONTENT_RELATION)) {
            insertedContainerProperty = container.getProperty(LDP_INSERTED_CONTENT_RELATION).getString();
        } else {
            return emptyIterator();
        }
    } else {
        insertedContainerProperty = MEMBER_SUBJECT.getURI();
    }

    final Iterator<FedoraResource> memberNodes = container.getChildren();

    return Iterators.concat(Iterators.transform(memberNodes,
            new FedoraResourceTripleFunction(insertedContainerProperty, memberRelation)));
}

From source file:org.eclipse.viatra.integration.gmf.GMFModelConnector.java

@Override
protected Collection<EObject> getSelectedEObjects(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        Iterator<IGraphicalEditPart> selectionIterator = Iterators
                .filter((((IStructuredSelection) selection).iterator()), IGraphicalEditPart.class);
        return Lists.newArrayList(Iterators
                .filter(Iterators.transform(selectionIterator, new Function<IGraphicalEditPart, EObject>() {

                    @Override/*from w w w . java2 s . c  om*/
                    public EObject apply(IGraphicalEditPart input) {
                        return input.resolveSemanticElement();
                    }
                }), Predicates.notNull()));
    } else {
        return super.getSelectedEObjects();
    }
}

From source file:org.kiji.schema.impl.hbase.HBaseMaterializedKijiResult.java

/** {@inheritDoc} */
@Override// ww  w  . j  a  v a2s .  c  o m
public Iterator<KijiCell<T>> iterator() {
    final List<Iterator<KijiCell<T>>> columnIterators = Lists.newArrayListWithCapacity(mColumnResults.size());

    for (Map.Entry<KijiColumnName, List<KeyValue>> entry : mColumnResults.entrySet()) {
        final Function<KeyValue, KijiCell<T>> decoder = ResultDecoders.getDecoderFunction(entry.getKey(),
                mLayout, mColumnTranslator, mDecoderProvider);

        columnIterators.add(Iterators.transform(entry.getValue().iterator(), decoder));
    }
    return Iterators.concat(columnIterators.iterator());
}

From source file:com.moz.fiji.schema.impl.hbase.HBaseMaterializedFijiResult.java

/** {@inheritDoc} */
@Override// w ww.  j  av a2 s . c  o m
public Iterator<FijiCell<T>> iterator() {
    final List<Iterator<FijiCell<T>>> columnIterators = Lists.newArrayListWithCapacity(mColumnResults.size());

    for (Map.Entry<FijiColumnName, List<KeyValue>> entry : mColumnResults.entrySet()) {
        final Function<KeyValue, FijiCell<T>> decoder = ResultDecoders.getDecoderFunction(entry.getKey(),
                mLayout, mColumnTranslator, mDecoderProvider);

        columnIterators.add(Iterators.transform(entry.getValue().iterator(), decoder));
    }
    return Iterators.concat(columnIterators.iterator());
}

From source file:io.crate.analyze.InsertFromSubQueryAnalyzer.java

/**
 * validate that result columns from subquery match explicit insert columns
 * or complete table schema/* ww  w .j av  a2 s  .  c o m*/
 */
private static void validateColumnsAndAddCastsIfNecessary(List<Reference> targetColumns, QuerySpec querySpec) {
    if (targetColumns.size() != querySpec.outputs().size()) {
        Joiner commaJoiner = Joiner.on(", ");
        throw new IllegalArgumentException(String.format(
                "Number of target columns (%s) of insert statement doesn't match number of source columns (%s)",
                commaJoiner.join(Iterables.transform(targetColumns, Reference.TO_COLUMN_NAME)),
                commaJoiner.join(Iterables.transform(querySpec.outputs(), SymbolPrinter.FUNCTION))));
    }

    int failedCastPosition = querySpec
            .castOutputs(Iterators.transform(targetColumns.iterator(), Symbols.TYPES_FUNCTION));
    if (failedCastPosition >= 0) {
        Symbol failedSource = querySpec.outputs().get(failedCastPosition);
        Reference failedTarget = targetColumns.get(failedCastPosition);
        throw new IllegalArgumentException(String.format(Locale.ENGLISH,
                "Type of subquery column %s (%s) does not match is not convertable to the type of table column %s (%s)",
                failedSource, failedSource.valueType(), failedTarget.ident().columnIdent().fqn(),
                failedTarget.valueType()));
    }
}

From source file:org.eclipse.viatra.integration.graphiti.GraphitiModelConnector.java

@Override
protected Collection<EObject> getSelectedEObjects(ISelection selection) {
    if (selection instanceof IStructuredSelection) {
        //XXX after Graphiti 0.9 GraphitiShapeEditPart would be the related type, but that is not available in 0.8
        Iterator<ContainerShapeEditPart> selectionIterator = Iterators
                .filter((((IStructuredSelection) selection).iterator()), ContainerShapeEditPart.class);
        return Lists.newArrayList(Iterators
                .filter(Iterators.transform(selectionIterator, new Function<ContainerShapeEditPart, EObject>() {

                    @Override/*w w  w . j  a  v  a 2s  .  c  om*/
                    public EObject apply(ContainerShapeEditPart input) {
                        return Graphiti.getLinkService()
                                .getBusinessObjectForLinkedPictogramElement(input.getPictogramElement());
                    }
                }), Predicates.notNull()));
    } else {
        return super.getSelectedEObjects();
    }
}

From source file:org.locationtech.geogig.plumbing.DeepCopy.java

private void copyTree(final ObjectId treeId, final ObjectStore from, final ObjectStore to,
        final Set<ObjectId> metadataIds) {
    if (to.exists(treeId)) {
        return;//from   w  w  w .  j av  a  2  s.c  o  m
    }
    Supplier<Iterator<NodeRef>> refs = command(LsTreeOp.class).setReference(treeId.toString())
            .setStrategy(Strategy.DEPTHFIRST_ONLY_FEATURES);

    Supplier<Iterator<Node>> nodes = Suppliers.compose(//
            (it) -> Iterators.transform(it, (ref) -> ref.getNode())//
            , refs);

    // move all features, recursively as given by the LsTreeOp strategy
    copyObjects(from, to, nodes, metadataIds);

    // iterator that traverses the tree,all its subtrees, an bucket trees
    Iterator<RevTree> allSubtreesAndBuckets = new AllTrees(treeId, from);

    to.putAll(allSubtreesAndBuckets);
}

From source file:es.usc.citius.composit.wsc08.data.WSCXMLServiceProvider.java

@Override
public Iterable<Operation<String>> getOperationsWithOutput(String outputInstance) {
    final Collection<XMLService> services = outputIndex.get(outputInstance);
    return new Iterable<Operation<String>>() {
        @Override/*from   w ww  .  j a v  a  2s  .c o m*/
        public Iterator<Operation<String>> iterator() {
            return Iterators.transform(services.iterator(), new Function<XMLService, Operation<String>>() {
                @Override
                public Operation<String> apply(XMLService service) {
                    return getOperation(service.getName() + operationSuffix);
                }
            });
        }
    };
}