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:com.yahoo.yqlplus.engine.sources.BatchKeySource.java

@Query
public Iterable<Person> lookupAll(@Key("id") List<String> ids, final int score) {
    return Iterables.transform(ids, new Function<String, Person>() {
        @Nullable/*from w w w  . j ava  2 s.c o  m*/
        @Override
        public Person apply(@Nullable String input) {
            return new Person(input, input, score);
        }
    });
}

From source file:org.sonar.server.computation.qualityprofile.QPMeasureData.java

public static QPMeasureData fromJson(String json) {
    return new QPMeasureData(Iterables.transform(new JsonParser().parse(json).getAsJsonArray(),
            JsonElementToQualityProfile.INSTANCE));
}

From source file:com.google.gerrit.acceptance.rest.project.BranchAssert.java

private static Iterable<String> refs(Iterable<BranchInfo> infos) {
    return Iterables.transform(infos, new Function<BranchInfo, String>() {
        @Override/*  w  w  w  .j  a  va2  s .co  m*/
        public String apply(BranchInfo in) {
            return in.ref;
        }
    });
}

From source file:uk.ac.stfc.isis.ibex.synoptic.SynopticInfo.java

public static Collection<String> names(Collection<SynopticInfo> infos) {
    if (infos == null) {
        return Collections.emptyList();
    }//ww w.  j  av a 2s. c  o m

    return Lists.newArrayList(Iterables.transform(infos, new Function<SynopticInfo, String>() {
        @Override
        public String apply(SynopticInfo info) {
            return info.name();
        }
    }));
}

From source file:brooklyn.rest.transform.EffectorTransformer.java

public static EffectorSummary effectorSummary(final EntityLocal entity, Effector<?> effector) {
    String applicationUri = "/v1/applications/" + entity.getApplicationId();
    String entityUri = applicationUri + "/entities/" + entity.getId();
    return new EffectorSummary(effector.getName(), effector.getReturnTypeName(),
            ImmutableSet.copyOf(Iterables.transform(effector.getParameters(),
                    new Function<ParameterType<?>, EffectorSummary.ParameterSummary<?>>() {
                        @Override
                        public EffectorSummary.ParameterSummary<?> apply(
                                @Nullable ParameterType<?> parameterType) {
                            return parameterSummary(entity, parameterType);
                        }/*from   w w w .ja va2s .com*/
                    })),
            effector.getDescription(),
            ImmutableMap.of("self", URI.create(entityUri + "/effectors/" + effector.getName()), "entity",
                    URI.create(entityUri), "application", URI.create(applicationUri)));
}

From source file:org.eclipse.xtext.mwe.UrlClassLoaderClasspathEntriesProvider.java

@Override
public Iterable<String> getAllPathes(ClassLoader classloader) {
    if (classloader instanceof URLClassLoader) {
        List<URL> urls = Arrays.asList(((URLClassLoader) classloader).getURLs());
        return Iterables.transform(urls, new Function<URL, String>() {
            @Override/*from   w  w  w.  j a v a 2  s  . c  o  m*/
            public String apply(URL from) {
                return from.toString();
            }
        });
    }
    throw new IllegalArgumentException("expected an URLClassLoader but received " + classloader);
}

From source file:com.facebook.buck.rules.coercer.MapConcatenatingCoercer.java

@Override
public Object concat(Iterable<Object> elements) {
    @SuppressWarnings("unchecked")
    Iterable<Set<Entry<Object, Object>>> maps = Iterables.transform(elements,
            map -> ((Map<Object, Object>) map).entrySet());
    return ImmutableMap.copyOf(Iterables.concat(maps));
}

From source file:org.apache.kylin.common.util.ZooKeeperUtil.java

public static String getZKConnectStringFromHBase() {
    Configuration hconf = null;/*w  w  w. jav  a 2  s.  c o  m*/
    try {
        Class<? extends Object> hbaseConnClz = ClassUtil
                .forName("org.apache.kylin.storage.hbase.HBaseConnection", Object.class);
        hconf = (Configuration) hbaseConnClz.getMethod("getCurrentHBaseConfiguration").invoke(null);
    } catch (Throwable ex) {
        logger.warn("Failed to get zookeeper connect string from HBase configuration", ex);
        return null;
    }

    final String serverList = hconf.get("hbase.zookeeper.quorum");
    final String port = hconf.get("hbase.zookeeper.property.clientPort");
    return StringUtils
            .join(Iterables.transform(Arrays.asList(serverList.split(",")), new Function<String, String>() {
                @Nullable
                @Override
                public String apply(String input) {
                    return input + ":" + port;
                }
            }), ",");
}

From source file:org.wikimedia.cassandra.metrics.Filter.java

public Filter(FilterConfig config) {
    blacklist = Lists.newArrayList(Iterables.transform(config.getBlacklist(), new Function<String, Pattern>() {
        @Override//w  w w  . ja  v a2 s .c  o  m
        public Pattern apply(String input) {
            return Pattern.compile(input);
        }
    }));

    whitelist = Lists.newArrayList(Iterables.transform(config.getWhitelist(), new Function<String, Pattern>() {
        @Override
        public Pattern apply(String input) {
            return Pattern.compile(input);
        }
    }));
}

From source file:ivorius.ivtoolkit.tools.Pairs.java

public static <L, R> Iterable<Pair<L, R>> pairLeft(final L left, Iterable<R> right) {
    return Iterables.transform(right, new Function<R, Pair<L, R>>() {
        @Nullable//  www  . j a  v a2s . c o  m
        @Override
        public Pair<L, R> apply(R input) {
            return Pair.of(left, input);
        }
    });
}