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:net.osgiliath.features.karaf.jaxrs.cdi.impl.HelloServiceImpl.java

/**
 * Returns registered instances./*  w w w.  j a  v a 2  s.c o m*/
 * 
 * @return all instances
 */
@Override
public Hellos getHellos() {
    return new Hellos(Lists.newArrayList(Iterables.transform(this.objects, new Function<HelloObject, String>() {
        @Override
        public String apply(final HelloObject input) {
            return input.getHelloMessage();
        }
    })));
}

From source file:org.openqa.selenium.remote.internal.JsonToWebElementConverter.java

public Object apply(Object result) {
    if (result instanceof Collection<?>) {
        Collection<?> results = (Collection<?>) result;
        return Lists.newArrayList(Iterables.transform(results, this));
    }// ww w  .  ja  v  a  2 s .com

    if (result instanceof Map<?, ?>) {
        Map<?, ?> resultAsMap = (Map<?, ?>) result;
        if (resultAsMap.containsKey("ELEMENT")) {
            RemoteWebElement element = newRemoteWebElement();
            element.setId(String.valueOf(resultAsMap.get("ELEMENT")));
            element.setFileDetector(driver.getFileDetector());
            return element;
        } else if (resultAsMap.containsKey("element-6066-11e4-a52e-4f735466cecf")) {
            RemoteWebElement element = newRemoteWebElement();
            element.setId(String.valueOf(resultAsMap.get("element-6066-11e4-a52e-4f735466cecf")));
            element.setFileDetector(driver.getFileDetector());
            return element;
        } else {
            return Maps.transformValues(resultAsMap, this);
        }
    }

    if (result instanceof Number) {
        if (result instanceof Float || result instanceof Double) {
            return ((Number) result).doubleValue();
        }
        return ((Number) result).longValue();
    }

    return result;
}

From source file:org.jclouds.openstack.swift.blobstore.functions.ContainerToResourceList.java

public PageSet<? extends StorageMetadata> apply(PageSet<ObjectInfo> from) {
    return new PageSetImpl<StorageMetadata>(Iterables.transform(Iterables.transform(from, object2blobMd),
            new Function<BlobMetadata, StorageMetadata>() {
                public StorageMetadata apply(BlobMetadata input) {
                    if (input.getContentMetadata().getContentType().equals("application/directory")) {
                        return new StorageMetadataImpl(StorageType.RELATIVE_PATH, input.getProviderId(),
                                input.getName(), input.getLocation(), input.getUri(), input.getETag(),
                                input.getCreationDate(), input.getLastModified(), input.getUserMetadata());
                    }//from w w w .  jav  a2s  .  c om
                    return input;
                }
            }), from.getNextMarker());

}

From source file:org.apache.aurora.common.net.http.handlers.VarsHandler.java

@GET
@Produces(MediaType.TEXT_PLAIN)// w w  w .j  a va  2  s .com
public String getVars() {
    List<String> lines = Lists.newArrayList(Iterables.transform(statSupplier.get(), VAR_PRINTER));
    Collections.sort(lines);
    return Joiner.on("\n").join(lines);
}

From source file:com.iamcontent.robot.arm.edge.RoboticEdgeArmCommandLineDriver.java

private Iterable<Command> commands() {
    return Iterables.transform(commandStrings(), parsingFunction);
}

From source file:com.facebook.buck.cxx.toolchain.ClangPreprocessor.java

@Override
public final Iterable<String> systemIncludeArgs(Iterable<String> includeRoots) {
    return MoreIterables.zipAndConcat(Iterables.cycle("-isystem"),
            Iterables.transform(includeRoots, MorePaths::pathWithUnixSeparators));
}

From source file:com.github.fhuss.storm.cassandra.bolt.GroupingBatchBuilder.java

private Iterable<PairBatchStatementTuples> build() {
    Iterable<List<PairStatementTuple>> partition = Iterables.partition(statements, batchSizeRows);
    return Iterables.transform(partition, new Function<List<PairStatementTuple>, PairBatchStatementTuples>() {
        @Override//from w  w w .  j  av a  2  s .  co  m
        public PairBatchStatementTuples apply(List<PairStatementTuple> l) {
            final List<Tuple> inputs = new LinkedList<>();
            final BatchStatement batch = new BatchStatement(BatchStatement.Type.UNLOGGED);
            for (PairStatementTuple pair : l) {
                batch.add(pair.getStatement());
                inputs.add(pair.getTuple());
            }
            return new PairBatchStatementTuples(inputs, batch);
        }
    });
}

From source file:azkaban.flow.GroupedFlow.java

@Override
public String getName() {
    return StringUtils.join(Iterables.transform(Arrays.asList(flows), new Function<Flow, String>() {
        @Override//from  w ww. j  a  va 2s  .  c om
        public String apply(Flow flow) {
            return flow.getName();
        }
    }).iterator(), " + ");
}

From source file:clocker.docker.networking.entity.sdn.DockerNetworkAgentSshDriver.java

@Override
public void createSubnet(String subnetId, Cidr subnetCidr) {
    Iterable<String> opts = Iterables.transform(getDockerNetworkCreateOpts(),
            StringFunctions.prepend("--opt "));
    getEntity().sensors().get(SdnAgent.DOCKER_HOST)
            .runDockerCommand(String.format("network create --driver %s %s --subnet=%s %s",
                    getDockerNetworkDriver(), Joiner.on(' ').join(opts), subnetCidr, subnetId));
}

From source file:net.middell.combo.TextResourceResolver.java

/**
 * Maps an ordered sequence of paths to a combination of text-based resources.
 *
 * @param paths the list of paths to be mapped
 * @return a new resource combo containing the mapped resources
 * @throws IllegalArgumentException in case a path cannot be mapped, e.g. because a specified path cannot be
 *                                  dereferenced
 *//*from   w  w  w .j a v  a 2s  .  c  om*/
public TextResourceCombo resolve(Iterable<String> paths) throws IllegalArgumentException {
    return new TextResourceCombo(Iterables.transform(paths, this));
}