Example usage for com.google.common.collect Collections2 transform

List of usage examples for com.google.common.collect Collections2 transform

Introduction

In this page you can find the example usage for com.google.common.collect Collections2 transform.

Prototype

public static <F, T> Collection<T> transform(Collection<F> fromCollection, Function<? super F, T> function) 

Source Link

Document

Returns a collection that applies function to each element of fromCollection .

Usage

From source file:org.eclipse.viatra.transformation.runtime.emf.rules.TransformationRuleGroup.java

public Set<RuleSpecification<?>> getRuleSpecifications() {
    return Sets.newHashSet(Collections2.transform(this, new RuleTransformerFunction()));
}

From source file:org.caleydo.view.tourguide.api.model.AVirtualArrayScoreRow.java

@Override
public Collection<GroupInfo> getGroupInfos() {
    return Collections2.transform(getGroups(), new Function<Group, GroupInfo>() {
        @Override//from   w  w  w. java  2 s .c  o m
        public GroupInfo apply(Group in) {
            return new GroupInfo(in.getLabel(), in.getSize(), null);
        }
    });
}

From source file:ezbake.data.elastic.common.VisibilityFilterConfig.java

public String getRequiredPermsString() {
    if (requiredPerms == null) {
        return null;
    }/*from  www  .  j  a  va2 s  . c  om*/

    final Collection<String> permStrings = Collections2.transform(requiredPerms,
            new Function<Permission, String>() {
                @Override
                public String apply(Permission input) {
                    return input.name();
                }
            });

    return Joiner.on(',').join(permStrings);
}

From source file:com.vilt.minium.impl.ClosureCompressor.java

@Override
public String compress(ClassLoader classLoader, Collection<String> jsResources) {
    try {//from   w  ww  .  j  ava2 s  . com
        Collection<SourceFile> sourceFiles = Collections2.transform(jsResources,
                new ClasspathFileToSourceFileFunction());

        Compiler compiler = new Compiler();
        compiler.disableThreads();

        CompilerOptions options = new CompilerOptions();
        CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
        compiler.compile(CommandLineRunner.getDefaultExterns(), Lists.newArrayList(sourceFiles), options);
        return compiler.toSource();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.isis.core.progmodel.facets.collections.collection.JavaCollectionFacet.java

@Override
@SuppressWarnings("unchecked")
public Collection<ObjectAdapter> collection(final ObjectAdapter wrappedCollection) {
    final Collection<?> collectionOfUnderlying = collectionOfUnderlying(wrappedCollection);
    return Collections2.transform(collectionOfUnderlying, new ObjectToAdapterFunction(getAdapterManager()));
}

From source file:org.polymap.biotop.model.TierComposite.java

public static void updateEntity(BiotopComposite biotop, Collection<TierComposite> coll) {
    biotop.tiere().set(Collections2.transform(coll, new Function<TierComposite, TierValue>() {
        public TierValue apply(TierComposite input) {
            return input.value();
        }//  w ww.  ja v  a 2 s. c o m
    }));
}

From source file:org.apache.isis.core.metamodel.facets.collections.collection.JavaCollectionFacet.java

@Override
@SuppressWarnings("unchecked")
public Collection<ObjectAdapter> collection(final ObjectAdapter wrappedCollection) {
    final Collection<?> collectionOfUnderlying = collectionOfUnderlying(wrappedCollection);
    return Collections2.transform(collectionOfUnderlying,
            ObjectAdapter.Functions.adapterForUsing(getAdapterManager()));
}

From source file:org.polymap.biotop.model.PilzComposite.java

public static void updateEntity(BiotopComposite biotop, Collection<PilzComposite> coll) {
    biotop.pilze().set(Collections2.transform(coll, new Function<PilzComposite, PilzValue>() {
        public PilzValue apply(PilzComposite input) {
            return input.value();
        }//from  ww w.  j  a  v a 2 s .c  om
    }));
}

From source file:org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractDataTreeCandidateNode.java

static Collection<DataTreeCandidateNode> deltaChildren(
        @Nullable final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
        @Nullable final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData) {
    Preconditions.checkArgument(newData != null || oldData != null,
            "No old or new data, modification type should be NONE and deltaChildren() mustn't be called.");
    if (newData == null) {
        return Collections2.transform(oldData.getValue(), AbstractRecursiveCandidateNode::deleteNode);
    }/*from  w  w w  .jav  a2  s  .c o m*/
    if (oldData == null) {
        return Collections2.transform(newData.getValue(), AbstractRecursiveCandidateNode::writeNode);
    }

    /*
     * This is slightly inefficient, as it requires N*F(M)+M*F(N) lookup operations, where
     * F is dependent on the implementation of NormalizedNodeContainer.getChild().
     *
     * We build the return collection by iterating over new data and looking each child up
     * in old data. Based on that we construct replaced/written nodes. We then proceed to
     * iterate over old data and looking up each child in new data.
     */
    final Collection<DataTreeCandidateNode> result = new ArrayList<>();
    for (NormalizedNode<?, ?> child : newData.getValue()) {
        final DataTreeCandidateNode node;
        final Optional<NormalizedNode<?, ?>> maybeOldChild = oldData.getChild(child.getIdentifier());

        if (maybeOldChild.isPresent()) {
            // This does not find children which have not in fact been modified, as doing that
            // reliably would require us running a full equals() on the two nodes.
            node = AbstractRecursiveCandidateNode.replaceNode(maybeOldChild.get(), child);
        } else {
            node = AbstractRecursiveCandidateNode.writeNode(child);
        }

        result.add(node);
    }

    // Process removals next, looking into new data to see if we processed it
    for (NormalizedNode<?, ?> child : oldData.getValue()) {
        if (!newData.getChild(child.getIdentifier()).isPresent()) {
            result.add(AbstractRecursiveCandidateNode.deleteNode(child));
        }
    }

    return result;
}

From source file:io.druid.server.lookup.cache.LookupNodeDiscovery.java

public Collection<HostAndPortWithScheme> getNodesInTier(String tier) {
    return Collections2.transform(
            Collections2.filter(druidNodeDiscovery.getAllNodes(), new Predicate<DiscoveryDruidNode>() {
                @Override//from  w  w  w  .java2 s.co m
                public boolean apply(@Nullable DiscoveryDruidNode node) {
                    return tier.equals(((LookupNodeService) node.getServices()
                            .get(LookupNodeService.DISCOVERY_SERVICE_KEY)).getLookupTier());
                }
            }), new Function<DiscoveryDruidNode, HostAndPortWithScheme>() {
                @Override
                public HostAndPortWithScheme apply(@Nullable DiscoveryDruidNode input) {
                    return HostAndPortWithScheme.fromString(input.getDruidNode().getServiceScheme(),
                            input.getDruidNode().getHostAndPortToUse());
                }
            });
}