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.twitter.common.args.parsers.ListParser.java

@Override
List<?> doParse(final ParserOracle parserOracle, String raw, final List<Type> typeParams) {
    final Type listType = typeParams.get(0);
    final Parser<?> parser = parserOracle.get(TypeToken.of(listType));
    return ImmutableList.copyOf(
            Iterables.transform(Parsers.MULTI_VALUE_SPLITTER.split(raw), new Function<String, Object>() {
                @Override// ww w .java 2 s .  c om
                public Object apply(String raw) {
                    return parser.parse(parserOracle, listType, raw);
                }
            }));
}

From source file:com.github.rodionmoiseev.c10n.tools.search.DefaultC10NInterfaceSearch.java

private Set<URL> getPackageURLs(String... packagePrefixes) {
    Iterable<URL> packages = Iterables
            .concat(Iterables.transform(Arrays.asList(packagePrefixes), new Function<String, Set<URL>>() {
                @Override/*from w ww  .j  ava 2 s.  c om*/
                public Set<URL> apply(String prefix) {
                    return ClasspathHelper.forPackage(prefix);
                }
            }));

    return Sets.newHashSet(packages);
}

From source file:com.facebook.buck.model.BuildFileTree.java

private static Iterable<String> collectBasePaths(Collection<BuildTarget> targets) {
    Preconditions.checkNotNull(targets);

    return Iterables.transform(targets, new Function<BuildTarget, String>() {
        @Override//from  w w  w . j  a  v a2 s  .co m
        public String apply(BuildTarget buildTarget) {
            return buildTarget.getBasePath();
        }
    });
}

From source file:org.nickelproject.util.testUtil.ClasspathUtil.java

/**
 * Find classes annotated with one or more of the arguments.
 *
 * @param pAnnotations/*from   ww w  . j  av a 2  s .c  o  m*/
 *            The annotations to look for
 * @return An iterable of class names
 */
public static Iterable<String> getAnnotatedClasses(final Class<?>... pAnnotations) {
    final String[] vAnnotationNames = new String[pAnnotations.length];
    for (int i = 0; i < vAnnotationNames.length; i++) {
        vAnnotationNames[i] = pAnnotations[i].getName();
    }
    final Iterable<String> vAllClasses = Iterables.transform(getResourcesOnClassPath("class"),
            new Function<String, String>() {
                @Override
                public String apply(final String pInput) {
                    return FilenameUtils.getBaseName(pInput);
                }
            });
    return Iterables.filter(vAllClasses, Predicates.and(getIsConcrete(), new HasAnnotation(vAnnotationNames)));
}

From source file:sf.net.experimaestro.manager.scripting.MethodFunction.java

@Override
protected Iterable<MethodDeclaration> declarations() {
    return Iterables.concat(new AbstractList<Iterable<MethodDeclaration>>() {
        @Override/*  w  w w . ja v a 2  s.co m*/
        public Iterable<MethodDeclaration> get(final int index) {
            Group group = groups.get(index);
            return Iterables.transform(group.methods, m -> new MethodDeclaration(group.thisObject, m));
        }

        @Override
        public int size() {
            return groups.size();
        }
    });
}

From source file:org.summer.dsl.builder.clustering.CopiedResourceDescription.java

public CopiedResourceDescription(IResourceDescription original) {
    this.uri = original.getURI();
    this.exported = ImmutableList.copyOf(Iterables.transform(original.getExportedObjects(),
            new Function<IEObjectDescription, IEObjectDescription>() {
                public IEObjectDescription apply(IEObjectDescription from) {
                    if (from.getEObjectOrProxy().eIsProxy()) {
                        return from;
                    }//from   w  w w. j a  v  a  2 s . c om
                    InternalEObject result = (InternalEObject) EcoreUtil.create(from.getEClass());
                    result.eSetProxyURI(from.getEObjectURI());
                    Map<String, String> userData = null;
                    for (final String key : from.getUserDataKeys()) {
                        if (userData == null) {
                            userData = Maps.newHashMapWithExpectedSize(2);
                        }
                        userData.put(key, from.getUserData(key));
                    }
                    return EObjectDescription.create(from.getName(), result, userData);
                }
            }));
}

From source file:org.ow2.petals.cloud.manager.core.puppet.InstallPackagesScriptBuilder.java

@Override
protected Object getScope(Node node, Context context) {
    return ImmutableMap.of("packages",
            Iterables.transform(getPackages(node, context), new Function<String, Map<String, String>>() {
                public Map<String, String> apply(String input) {
                    return ImmutableMap.of("package", input);
                }/*from  w  w  w.  ja v  a2s . c  o  m*/
            }));
}

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

/**
 * //from w  ww  .  java2s  . co  m
 * @param toExec
 *           what to invoke
 * @param method
 *           http method: ex GET
 * @param endpoint
 *           uri corresponding to the request
 * @param headers
 *           request headers to send
 */
public PipeHttpResponseTo(Statement toExec, String method, URI endpoint, Multimap<String, String> headers) {
    super(String.format("%s -X %s %s %s |(%s)\n", SaveHttpResponseTo.CURL, method, Joiner.on(' ')
            .join(Iterables.transform(headers.entries(), new Function<Entry<String, String>, String>() {

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

            })), endpoint.toASCIIString(), toExec.render(OsFamily.UNIX)));
}

From source file:com.twitter.common.args.parsers.SetParser.java

@Override
Set<?> doParse(final ParserOracle parserOracle, String raw, List<Type> typeParams) {
    final Type setType = typeParams.get(0);
    final Parser<?> parser = parserOracle.get(TypeToken.of(setType));

    return ImmutableSet.copyOf(
            Iterables.transform(Parsers.MULTI_VALUE_SPLITTER.split(raw), new Function<String, Object>() {
                @Override/*from w  w w. jav  a 2s .  c o m*/
                public Object apply(String raw) {
                    return parser.parse(parserOracle, setType, raw);
                }
            }));
}

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

@Override
public Iterable<String> systemIncludeArgs(Iterable<String> includeRoots) {
    return Iterables.transform(includeRoots, WindowsPreprocessor::prependIncludeFlag);
}