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.sonar.core.issue.DefaultIssueFinder.java

public List<Issue> find(IssueQuery issueQuery) {
    Collection<IssueDto> dtoList = issueDao.select(issueQuery);
    return newArrayList(Iterables.transform(dtoList, new Function<IssueDto, Issue>() {
        @Override/*ww  w . j  a v  a2s .c  o m*/
        public Issue apply(IssueDto input) {
            return toIssue(input);
        }
    }));
}

From source file:nz.co.testamation.common.util.PrefixMapNamespaceContext.java

public Iterator<String> getPrefixes(final String namespaceURI) {
    return Iterables.transform(
            Iterables.filter(prefixNamespaceMap.entrySet(), new Predicate<Map.Entry<String, String>>() {
                @Override//w  w w.  j a  v a2 s .c om
                public boolean apply(Map.Entry<String, String> entry) {
                    return namespaceURI.equals(entry.getValue());
                }
            }), new Function<Map.Entry<String, String>, String>() {
                @Override
                public String apply(Map.Entry<String, String> entry) {
                    return entry.getKey();
                }
            }).iterator();

}

From source file:net.osgiliath.features.karaf.jaxrs.web.cdi.impl.HelloServiceImpl.java

/**
 * Returns instances./*from   w  ww . j  av  a2s.  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(HelloObject input) {

            return input.getHelloMessage();
        }
    })));
}

From source file:io.druid.query.search.SearchStrategy.java

static List<DimensionSpec> getDimsToSearch(Indexed<String> availableDimensions,
        List<DimensionSpec> dimensions) {
    if (dimensions == null || dimensions.isEmpty()) {
        return ImmutableList.copyOf(Iterables.transform(availableDimensions, Druids.DIMENSION_IDENTITY));
    } else {/*from   w  w  w.j  av a 2s. c o  m*/
        return dimensions;
    }
}

From source file:com.mengge.internal.JsonToMobileElementConverter.java

/**
 * This method converts a command result.
 *
 * @param result is the result of a command execution.
 * @return the result/*from w  w w. j a v a2  s .  co  m*/
 */
public Object apply(Object result) {
    if (result instanceof Collection<?>) {
        Collection<?> results = (Collection<?>) result;
        return Lists.newArrayList(Iterables.transform(results, this));
    }

    if (result instanceof Map<?, ?>) {
        Map<?, ?> resultAsMap = (Map<?, ?>) result;
        if (resultAsMap.containsKey("ELEMENT")) {
            MobileElement element = newMobileElement();
            element.setId(String.valueOf(resultAsMap.get("ELEMENT")));
            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.eclipse.xtext.resource.impl.AbstractCompoundSelectable.java

@Override
public Iterable<IEObjectDescription> getExportedObjectsByType(final EClass type) {
    return Iterables.concat(
            Iterables.transform(getSelectables(), new Function<ISelectable, Iterable<IEObjectDescription>>() {
                @Override//from  w  ww. ja v  a2  s.c  o  m
                public Iterable<IEObjectDescription> apply(ISelectable from) {
                    if (from != null)
                        return from.getExportedObjectsByType(type);
                    return Collections.emptyList();
                }
            }));
}

From source file:org.jclouds.scriptbuilder.domain.SaveHttpResponseTo.java

/**
 * //from w  w w.  j  av  a2 s.  c o m
 * @param dir
 *           location to save file
 * @param method
 *           http method: ex GET
 * @param endpoint
 *           uri corresponding to the request
 * @param headers
 *           request headers to send
 */
public SaveHttpResponseTo(String dir, String file, String method, URI endpoint,
        Multimap<String, String> headers) {
    super(String.format("({md} %s && {cd} %s && [ ! -f %s ] && %s -C - -X %s %s %s >%s)\n", dir, dir, file,
            CURL, method, Joiner.on(' ').join(
                    Iterables.transform(headers.entries(), new Function<Map.Entry<String, String>, String>() {

                        @Override
                        public String apply(Map.Entry<String, String> from) {
                            return String.format("-H \"%s: %s\"", from.getKey(), from.getValue());
                        }

                    })),
            endpoint.toASCIIString(), file));

}

From source file:org.eclipse.che.ide.ext.java.client.project.interceptor.JavaClassInterceptor.java

@Override
public Promise<List<Node>> intercept(Node parent, List<Node> children) {
    Iterable<Node> nodes = Iterables.transform(children, intercept(parent));
    List<Node> nodeList = Lists.newArrayList(nodes);
    return Promises.resolve(nodeList);
}

From source file:com.eucalyptus.auth.policy.PolicyCondition.java

public PolicyCondition(final String type, final String key, final Set<String> values) {
    checkParam("type", type, notNullValue());
    checkParam("key", key, notNullValue());
    checkParam("values", values, notNullValue());
    this.type = PolicyUtils.intern(type);
    this.key = PolicyUtils.intern(key);
    this.values = ImmutableSet.copyOf(Iterables.transform(values, PolicyUtils.internString()));
}

From source file:org.openqa.selenium.remote.html5.AddDatabaseStorage.java

public InterfaceImplementation getImplementation(Object value) {
    return new InterfaceImplementation() {
        public Object invoke(ExecuteMethod executeMethod, Object self, Method method, Object... args) {
            String databaseName = (String) args[0];
            String query = (String) args[1];
            Object[] arguments = (Object[]) args[2];

            query = query.replaceAll("\"", "\\\"");
            Iterable<Object> convertedArgs = Iterables.transform(Lists.newArrayList(arguments),
                    new WebElementToJsonConverter());

            Map<String, ?> params = ImmutableMap.of("dbName", databaseName, "query", query, "args",
                    Lists.newArrayList(convertedArgs));

            Map<Object, Object> resultAsMap = (Map<Object, Object>) executeMethod
                    .execute(DriverCommand.EXECUTE_SQL, params);
            ResultSet rs = new ResultSet(((Long) resultAsMap.get("insertId")).intValue(),
                    ((Long) resultAsMap.get("rowsAffected")).intValue(),
                    new ResultSetRows((List<Map<String, Object>>) resultAsMap.get("rows")));
            return rs;
        }//from  ww w  .j a  v a2s .co m
    };
}