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:alluxio.worker.block.evictor.LRFUEvictor.java

@Override
protected Iterator<Long> getBlockIterator() {
    return Iterators.transform(getSortedCRF().iterator(), new Function<Map.Entry<Long, Double>, Long>() {
        @Override//from   www. j  ava2s.  c  o  m
        public Long apply(Entry<Long, Double> input) {
            return input.getKey();
        }
    });
}

From source file:org.geogit.geotools.plumbing.ExportOp.java

/**
 * Executes the export operation using the parameters that have been specified.
 * //w  ww  . jav a2  s. c  o  m
 * @return a FeatureCollection with the specified features
 */
@SuppressWarnings("deprecation")
@Override
public SimpleFeatureStore call() {

    if (filterFeatureTypeId != null) {
        RevObject filterType = database.getIfPresent(filterFeatureTypeId);
        checkArgument(filterType instanceof RevFeatureType, "Provided filter feature type is does not exist");
    }

    final SimpleFeatureStore targetStore = getTargetStore();

    final String refspec = resolveRefSpec();
    final String treePath = refspec.substring(refspec.indexOf(':') + 1);
    final RevTree rootTree = resolveRootTree(refspec);
    final NodeRef typeTreeRef = resolTypeTreeRef(refspec, treePath, rootTree);

    final ObjectId defaultMetadataId = typeTreeRef.getMetadataId();

    final RevTree typeTree = database.getTree(typeTreeRef.objectId());

    final ProgressListener progressListener = getProgressListener();

    progressListener.started();
    progressListener.setDescription("Exporting " + path + "... ");

    FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection = new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() {

        @Override
        public FeatureIterator<SimpleFeature> features() {

            final Iterator<SimpleFeature> plainFeatures = getFeatures(typeTree, database, defaultMetadataId,
                    progressListener);

            Iterator<SimpleFeature> adaptedFeatures = adaptToArguments(plainFeatures, defaultMetadataId);

            Iterator<Optional<Feature>> transformed = Iterators.transform(adaptedFeatures,
                    ExportOp.this.function);

            Iterator<SimpleFeature> filtered = Iterators
                    .filter(Iterators.transform(transformed, new Function<Optional<Feature>, SimpleFeature>() {
                        @Override
                        public SimpleFeature apply(Optional<Feature> input) {
                            return (SimpleFeature) (input.isPresent() ? input.get() : null);
                        }
                    }), Predicates.notNull());

            return new DelegateFeatureIterator<SimpleFeature>(filtered);
        }
    };

    // add the feature collection to the feature store
    final Transaction transaction;
    if (transactional) {
        transaction = new DefaultTransaction("create");
    } else {
        transaction = Transaction.AUTO_COMMIT;
    }
    try {
        targetStore.setTransaction(transaction);
        try {
            targetStore.addFeatures(asFeatureCollection);
            transaction.commit();
        } catch (final Exception e) {
            if (transactional) {
                transaction.rollback();
            }
            Throwables.propagateIfInstanceOf(e, GeoToolsOpException.class);
            throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
        } finally {
            transaction.close();
        }
    } catch (IOException e) {
        throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD);
    }

    progressListener.complete();

    return targetStore;

}

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

private void concatRdfTypes() throws RepositoryException {
    final ImmutableList.Builder<NodeType> nodeTypesB = ImmutableList.<NodeType>builder();

    final NodeType primaryNodeType = node.getPrimaryNodeType();
    nodeTypesB.add(primaryNodeType);/*  w  w  w  . j  av a 2s. com*/

    if (primaryNodeType != null && primaryNodeType.getSupertypes() != null) {
        final Set<NodeType> primarySupertypes = ImmutableSet.<NodeType>builder()
                .add(primaryNodeType.getSupertypes()).build();
        nodeTypesB.addAll(primarySupertypes);
    }

    final NodeType[] mixinNodeTypesArr = node.getMixinNodeTypes();

    if (mixinNodeTypesArr != null) {
        final Set<NodeType> mixinNodeTypes = ImmutableSet.<NodeType>builder().add(mixinNodeTypesArr).build();
        nodeTypesB.addAll(mixinNodeTypes);

        final ImmutableSet.Builder<NodeType> mixinSupertypes = ImmutableSet.<NodeType>builder();
        for (final NodeType mixinNodeType : mixinNodeTypes) {
            mixinSupertypes.addAll(ImmutableSet.<NodeType>builder().add(mixinNodeType.getSupertypes()).build());
        }

        nodeTypesB.addAll(mixinSupertypes.build());
    }

    final ImmutableList<NodeType> nodeTypes = nodeTypesB.build();
    final Iterator<NodeType> nodeTypesIt = nodeTypes.iterator();

    concat(Iterators.transform(nodeTypesIt, nodetype2triple()));
}

From source file:jflowmap.views.flowmap.VisualNodeCluster.java

public static FlowMapGraph createClusteredFlowMap(FlowMapAttrSpec flowMapAttrSpec,
        List<VisualNodeCluster> clusters) {
    FlowMapGraphBuilder builder = new FlowMapGraphBuilder(null, flowMapAttrSpec).withCumulatedEdges()
            .addNodeAttr(JOINED_FLOW_MAP_CLUSTER_ATTR, VisualNodeCluster.class);

    // Create (visualNode->cluster node) mapping
    Map<VisualNode, Node> visualToNode = Maps.newHashMap();
    for (VisualNodeCluster cluster : clusters) {
        Point centroid = GeomUtils
                .centroid(Iterators.transform(cluster.iterator(), VisualNode.TRANSFORM_NODE_TO_POSITION));
        Node node = builder.addNode(centroid, makeNodeClusterLabel(cluster));
        node.set(JOINED_FLOW_MAP_CLUSTER_ATTR, cluster);
        for (VisualNode visualNode : cluster) {
            visualToNode.put(visualNode, node);
        }/*from   w  w w  .  j a va  2 s  .c o m*/
    }

    // Edges between clusters
    for (VisualNodeCluster cluster : clusters) {
        for (VisualNode node : cluster) {
            for (VisualEdge visualEdge : node.getEdges()) {
                builder.addEdge(visualToNode.get(visualEdge.getSourceNode()),
                        visualToNode.get(visualEdge.getTargetNode()), visualEdge.getEdgeWeight());
            }
        }
    }

    return builder.build();
}

From source file:qdg.view.MixedGraphAsBiDiGraph.java

@Override
public Iterator<Edge> getOutArcIterator(Node node) {
    Iterator<Edge> forwardArcs = Iterators.transform(g.getOutArcIterator(node), forwardEdge);
    Iterator<Edge> backwardArcs = Iterators.transform(g.getInArcIterator(node), backwardEdge);
    Iterator<Edge> uEdges = new OutArcIterator(node);
    return Iterators.concat(forwardArcs, backwardArcs, uEdges);
}

From source file:org.apache.jackrabbit.oak.jcr.delegate.UserManagerDelegator.java

@Override
public Iterator<Authorizable> findAuthorizables(final String relPath, final String value)
        throws RepositoryException {
    return sessionDelegate
            .perform(new UserManagerOperation<Iterator<Authorizable>>(sessionDelegate, "findAuthorizables") {
                @Nonnull// w  w  w. j  a v  a  2  s  .c  o  m
                @Override
                public Iterator<Authorizable> perform() throws RepositoryException {
                    Iterator<Authorizable> authorizables = userManagerDelegate.findAuthorizables(relPath,
                            value);
                    return Iterators.transform(authorizables, new Function<Authorizable, Authorizable>() {
                        @Nullable
                        @Override
                        public Authorizable apply(Authorizable authorizable) {
                            return AuthorizableDelegator.wrap(sessionDelegate, authorizable);
                        }
                    });
                }
            });
}

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

@Override
public Iterable<Operation<String>> getOperationsWithInput(String inputInstance) {
    final Collection<XMLService> services = inputIndex.get(inputInstance);
    return new Iterable<Operation<String>>() {
        @Override//from   w  ww.  j  av a 2 s  .  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);
                }
            });
        }
    };
}

From source file:bammerbom.ultimatecore.bukkit.resources.utils.AttributeUtil.java

public Iterable<Attribute> values() {
    return new Iterable<Attribute>() {
        @Override//w w w .  j a  va 2s  .co m
        public Iterator<Attribute> iterator() {
            return Iterators.transform(attributes.iterator(), new Function<Object, Attribute>() {
                @Override
                public Attribute apply(@Nullable Object element) {
                    return new Attribute((NbtFactory.NbtCompound) element);
                }
            });
        }
    };
}

From source file:org.caleydo.vis.lineup.model.MultiCategoricalRankColumnModel.java

@Override
public String getValue(IRow row) {
    Set<CATEGORY_TYPE> value = getCatValue(row);
    if (value == null || value.isEmpty())
        return labelNA;
    return StringUtils.join(Iterators.transform(value.iterator(), cat2label), ',');
}

From source file:com.joyveb.dbpimpl.cass.prepare.core.DefaultSchemaOperations.java

@Override
public IngestOperation createIndexes(String tableName, Class<?> entityClass) {
    Assert.notNull(entityClass);/*from ww w.  j a v  a 2s . c o  m*/
    CassandraPersistentEntity<?> entity = this.getPersistentEntity(entityClass);
    List<CreateIndexSpecification> specList = converter.getCreateIndexSpecifications(entity);
    Iterator<Statement> queryIterator = Iterators.transform(specList.iterator(),
            new Function<CreateIndexSpecification, Statement>() {
                @Override
                public Statement apply(CreateIndexSpecification spec) {
                    String cql = new CreateIndexCqlGenerator(spec).toCql();
                    return new SimpleStatement(cql);
                }
            });
    return new DefaultIngestOperation(session, queryIterator);

}