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

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

Introduction

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

Prototype

@CheckReturnValue
public static <F, T> Iterable<T> transform(final Iterable<F> fromIterable,
        final Function<? super F, ? extends T> function) 

Source Link

Document

Returns an iterable that applies function to each element of fromIterable .

Usage

From source file:org.openrdf.sail.elasticsearch.ElasticsearchQuery.java

@Override
public Iterable<? extends DocumentScore> query(Resource resource) throws IOException {
    SearchHits hits;// w  w  w .  j  av  a2 s .  c  o  m
    if (resource != null) {
        hits = index.search(resource, request, qb);
    } else {
        hits = index.search(request, qb);
    }
    return Iterables.transform(hits, new Function<SearchHit, DocumentScore>() {
        @Override
        public DocumentScore apply(SearchHit hit) {
            return new ElasticsearchDocumentScore(hit, null);
        }
    });
}

From source file:com.facebook.presto.orc.metadata.OrcMetadataReader.java

private static List<StripeStatistics> toStripeStatistics(List<OrcProto.StripeStatistics> types) {
    return ImmutableList.copyOf(Iterables.transform(types, OrcMetadataReader::toStripeStatistics));
}

From source file:org.jclouds.azureblob.blobstore.functions.ResourceToListBlobsResponse.java

public ListBlobsResponse apply(PageSet<? extends StorageMetadata> list) {

    Iterable<BlobProperties> contents = Iterables
            .transform(Iterables.filter(list, new Predicate<StorageMetadata>() {

                public boolean apply(StorageMetadata input) {
                    return input.getType() == StorageType.BLOB;
                }/*from  www .j  ava2s  .  c  o  m*/

            }), new Function<StorageMetadata, BlobProperties>() {

                public MutableBlobProperties apply(StorageMetadata from) {
                    return blob2ObjectMd.apply((BlobMetadata) from);
                }

            });

    SortedSet<String> commonPrefixes = Sets
            .newTreeSet(Iterables.transform(Iterables.filter(list, new Predicate<StorageMetadata>() {

                public boolean apply(StorageMetadata input) {
                    return input.getType() == StorageType.RELATIVE_PATH;
                }

            }), new Function<StorageMetadata, String>() {

                public String apply(StorageMetadata from) {
                    return from.getName();
                }

            }));
    return new HashSetListBlobsResponse(contents, null, null, null, null, list.getNextMarker(), "/",
            commonPrefixes);
}

From source file:org.killbill.billing.jaxrs.json.RolledUpUsageJson.java

public RolledUpUsageJson(final RolledUpUsage input) {
    this(input.getSubscriptionId().toString(), input.getStart(), input.getEnd(), ImmutableList.copyOf(
            Iterables.transform(input.getRolledUpUnits(), new Function<RolledUpUnit, RolledUpUnitJson>() {
                @Override/*from   www .  ja  va 2  s.  c om*/
                public RolledUpUnitJson apply(final RolledUpUnit input) {
                    return new RolledUpUnitJson(input);
                }
            })));
}

From source file:org.jclouds.slicehost.compute.suppliers.SlicehostHardwareSupplier.java

@Override
public Set<? extends Hardware> get() {
    final Set<Hardware> hardware;
    logger.debug(">> providing hardware");
    hardware = Sets.newLinkedHashSet(Iterables.transform(sync.listFlavors(), flavorToHardware));
    logger.debug("<< hardware(%d)", hardware.size());
    return hardware;
}

From source file:com.metamx.collections.spatial.search.GutmanSearchStrategy.java

public Iterable<ImmutablePoint> depthFirstSearch(ImmutableNode node, final Bound bound) {
    if (node.isLeaf()) {
        return bound
                .filter(Iterables.transform(node.getChildren(), new Function<ImmutableNode, ImmutablePoint>() {
                    @Override/*w  w w.j  a  va 2s.com*/
                    public ImmutablePoint apply(ImmutableNode tNode) {
                        return new ImmutablePoint(tNode);
                    }
                }));
    } else {
        return Iterables.concat(
                Iterables.transform(Iterables.filter(node.getChildren(), new Predicate<ImmutableNode>() {
                    @Override
                    public boolean apply(ImmutableNode child) {
                        return bound.overlaps(child);
                    }
                }), new Function<ImmutableNode, Iterable<ImmutablePoint>>() {
                    @Override
                    public Iterable<ImmutablePoint> apply(ImmutableNode child) {
                        return depthFirstSearch(child, bound);
                    }
                }));
    }
}

From source file:org.polarsys.reqcycle.types.impl.TypesManager.java

@Override
public IType getType(final String id) {
    IType result = allTypes.get(id);//from   ww w .j a  v a  2s.c om
    if (result == null) {
        result = Iterables.find(Iterables.concat(Iterables.transform(providers, new ProviderToITypes())),
                new Predicate<IType>() {
                    public boolean apply(IType t) {
                        return id.equals(t.getId());
                    }
                }, null);
    }
    return result;
}

From source file:co.cask.cdap.cli.command.GetDatasetInstancePropertiesCommand.java

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    DatasetId instance = cliConfig.getCurrentNamespace()
            .dataset(arguments.get(ArgumentName.DATASET.toString()));

    Map<String, String> properties = datasetClient.getProperties(instance);
    Table table = Table.builder().setHeader("property", "value").setRows(
            Iterables.transform(properties.entrySet(), new Function<Map.Entry<String, String>, List<String>>() {
                @Nullable//from w ww .  j  av  a  2 s .c om
                @Override
                public List<String> apply(Map.Entry<String, String> entry) {
                    return ImmutableList.of(entry.getKey(), entry.getValue());
                }
            })).build();
    cliConfig.getTableRenderer().render(cliConfig, output, table);
}

From source file:co.cask.cdap.cli.command.metadata.GetMetadataTagsCommand.java

@Override
public void perform(Arguments arguments, PrintStream output) throws Exception {
    EntityId entity = EntityId.fromString(arguments.get(ArgumentName.ENTITY.toString()));
    String scope = arguments.getOptional(ArgumentName.METADATA_SCOPE.toString());
    Set<String> tags = scope == null ? client.getTags(entity.toId())
            : client.getTags(entity.toId(), MetadataScope.valueOf(scope.toUpperCase()));

    Table table = Table.builder().setHeader("tags")
            .setRows(Iterables.transform(tags, new Function<String, List<String>>() {
                @Nullable// w w w . j a  va  2 s.  c  o  m
                @Override
                public List<String> apply(@Nullable String tag) {
                    return Lists.newArrayList(tag);
                }
            })).build();

    cliConfig.getTableRenderer().render(cliConfig, output, table);
}

From source file:edu.sabanciuniv.sentilab.sare.controllers.entitymanagers.PersistentDocumentController.java

/**
 * Gets all UUIDs for {@link PersistentDocument} objects that are associated with a particular {@link PersistentDocumentStore}.
 * @param em the {@link EntityManager} to use.
 * @param storeId the ID of the store to look for.
 * @return a {@link List} containing {@link String} representations of the UUIDs.
 *///www .  ja  v  a  2 s  .  c om
public List<String> getAllUuids(EntityManager em, String storeId) {
    Validate.notNull(em, CannedMessages.NULL_ARGUMENT, "em");
    Validate.notNull(storeId, CannedMessages.NULL_ARGUMENT, "storeId");

    PersistentDocumentStore store = em.find(PersistentDocumentStore.class, UuidUtils.toBytes(storeId));
    return Lists
            .newArrayList(Iterables.transform(store.getDocumentIds(em), UuidUtils.uuidBytesToStringFunction()));
}