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:models.documentStore.AspectLexiconModel.java

public AspectLexiconModel(AspectLexicon lexicon, boolean expandChildren) {
    super(lexicon);

    if (lexicon != null) {
        if (lexicon.getBaseCorpus() != null) {
            this.baseCorpus = (DocumentCorpusModel) createViewModel(lexicon.getBaseCorpus());
        }//from  w  w w  .  j  a v  a2  s . c o  m

        if (Iterables.size(lexicon.getDerivedStores()) == 0) {
            this.children = null;
        } else {
            this.children = expandChildren ? Lists.newArrayList(
                    Iterables.transform(Iterables.filter(lexicon.getDerivedStores(), AspectLexicon.class),
                            new Function<AspectLexicon, AspectLexiconModel>() {
                                @Override
                                @Nullable
                                public AspectLexiconModel apply(@Nullable AspectLexicon input) {
                                    return new AspectLexiconModel(input, false);
                                }
                            }))
                    : Lists.<AspectLexiconModel>newArrayList();
        }

        if (lexicon.getBaseStore() instanceof AspectLexicon) {
            this.parent = new AspectLexiconModel((AspectLexicon) lexicon.getBaseStore(), false);
        }
    }
}

From source file:edu.harvard.med.screensaver.db.NoSuchEntityException.java

private NoSuchEntityException(Class<? extends Entity> entityClass, Map<String, Object> propertyValues) {
    super("no such " + entityClass.getSimpleName() + " for "
            + Joiner.on(", ").join(Iterables.transform(propertyValues.entrySet(), ToPropertyValueString)));
    _propertyValues = propertyValues;//from w w  w. j ava  2 s. c o m
}

From source file:org.estatio.dom.communicationchannel.PostalAddresses.java

@Programmatic
public PostalAddress findByAddress(final CommunicationChannelOwner owner, final String address1,
        final String postalCode, final String city, final Country country) {

    final List<CommunicationChannelOwnerLink> links = communicationChannelOwnerLinks
            .findByOwnerAndCommunicationChannelType(owner, CommunicationChannelType.POSTAL_ADDRESS);
    final Iterable<PostalAddress> postalAddresses = Iterables.transform(links,
            CommunicationChannelOwnerLink.Functions.communicationChannel(PostalAddress.class));
    final Optional<PostalAddress> postalAddressIfFound = Iterables.tryFind(postalAddresses,
            PostalAddress.Predicates.equalTo(address1, postalCode, city, country));
    return postalAddressIfFound.orNull();
}

From source file:org.openqa.selenium.remote.server.handler.internal.ResultConverter.java

public Object apply(Object result) {
    if (result instanceof WebElement) {
        String elementId = knownElements.add((WebElement) result);
        return ImmutableMap.of("ELEMENT", elementId);
    }// w  w w .ja va2  s. com

    if (result instanceof List) {
        @SuppressWarnings("unchecked")
        List<Object> resultAsList = (List<Object>) result;
        return Lists.newArrayList(Iterables.transform(resultAsList, this));
    }

    if (result instanceof Map<?, ?>) {
        Map<?, ?> resultAsMap = (Map<?, ?>) result;
        Map<Object, Object> converted = Maps.newHashMapWithExpectedSize(resultAsMap.size());
        for (Map.Entry<?, ?> entry : resultAsMap.entrySet()) {
            converted.put(entry.getKey(), apply(entry.getValue()));
        }
        return converted;
    }

    return result;
}

From source file:serializr.ast.SequenceNode.java

@Override
public Iterable<? extends RoleRef> getRoleRefs() {
    Tree roleRefs = getChild(2);/*www . java  2s.c o  m*/
    return Iterables.transform(new TreeChildrenIterable(roleRefs), toRoleRefCast());
}

From source file:org.locationtech.geogig.plumbing.MapRef.java

@Override
protected List<Ref> _call() {
    checkState(remote != null, "remote not provided");
    checkState(toRemote != null, "must indicate whether to convert refs to local or remotes namespace");

    Function<Ref, Ref> function = (r) -> toRemote.booleanValue() ? toRemote(r) : toLocal(r);
    return Lists.newArrayList(Iterables.transform(refs, function));
}

From source file:com.palantir.lock.impl.LockClientIndices.java

Iterable<LockClient> fromIndices(Iterable<Integer> indices) {
    return Iterables.transform(indices, new Function<Integer, LockClient>() {
        @Override//from w  w w.  jav a  2s  .  c o m
        public LockClient apply(Integer index) {
            return fromIndex(index);
        }
    });
}

From source file:co.cask.cdap.common.lang.ClassPathResources.java

/**
 * Returns the base set of resources needed to load the specified {@link Class} using the
 * specified {@link ClassLoader}. Also traces and includes the dependencies for the specified class.
 *
 * @param classLoader the {@link ClassLoader} to use to generate the set of resources
 * @param classz the {@link Class} to generate the set of resources for
 * @return the set of resources needed to load the specified {@link Class} using the specified {@link ClassLoader}
 * @throws IOException//from ww w  . j a v  a2s .c om
 */
public static Set<String> getResourcesWithDependencies(ClassLoader classLoader, Class<?> classz)
        throws IOException {
    ClassPath classPath = getClassPath(classLoader, classz);

    // Add everything in the classpath as visible resources
    Set<String> result = Sets
            .newHashSet(Iterables.transform(classPath.getResources(), RESOURCE_INFO_TO_RESOURCE_NAME));
    // Trace dependencies for all classes in the classpath
    findClassDependencies(classLoader, Iterables.transform(classPath.getAllClasses(), CLASS_INFO_TO_CLASS_NAME),
            result);

    return result;
}

From source file:org.jclouds.location.suppliers.derived.ZoneIdsFromRegionIdToZoneIdsValues.java

@Override
public Set<String> get() {
    Collection<Supplier<Set<String>>> zones = regionIdToZoneIdsSupplier.get().values();
    return ImmutableSet
            .copyOf(Iterables.concat(Iterables.transform(zones, Suppliers.<Set<String>>supplierFunction())));
}

From source file:hudson.plugins.depgraph_view.model.graph.GraphCalculator.java

public static Iterable<ProjectNode> abstractProjectSetToProjectNodeSet(
        Iterable<? extends AbstractProject<?, ?>> projects) {
    return Iterables.transform(projects, new Function<AbstractProject<?, ?>, ProjectNode>() {
        @Override//  w  w w.j  ava2  s  .c om
        public ProjectNode apply(AbstractProject<?, ?> input) {
            return node(input);
        }
    });
}