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:com.manning.siia.kitchen.Cook.java

private ArrayList<Product> productsFromMessages(List<Message<?>> group) {
    return new ArrayList<Product>(Collections2.transform(group, new Function<Message<?>, Product>() {
        public Product apply(Message<?> from) {
            return (Product) from.getPayload();
        }//from   w ww. j  a  v a  2 s .c  o m
    }));
}

From source file:org.caleydo.core.data.datadomain.GroupingDataDomainActionFactory.java

@Override
public Collection<Pair<String, Runnable>> create(IDataDomain dataDomain, Object sender) {
    Collection<Pair<String, ? extends AEvent>> r = new ArrayList<>(4);
    if (dataDomain instanceof ATableBasedDataDomain) {
        ATableBasedDataDomain d = (ATableBasedDataDomain) dataDomain;

        r.add(Pair.make("Load Grouping for " + d.getDimensionIDCategory().getCategoryName(),
                new LoadGroupingEvent(d, d.getDimensionIDCategory()).from(sender)));
        r.add(Pair.make("Load Grouping for " + d.getRecordIDCategory().getCategoryName(),
                new LoadGroupingEvent(d, d.getRecordIDCategory()).from(sender)));
        r.add(Pair.make(/*  w  w  w. j a  va 2s  .  c  o  m*/
                "Create Grouping for " + d.getDimensionIDCategory().getCategoryName() + " using Clustering",
                new CreateClusteringEvent(d, true).from(sender)));
        r.add(Pair.make(
                "Create Grouping for " + d.getRecordIDCategory().getCategoryName() + " using Clustering",
                new CreateClusteringEvent(d, false).from(sender)));
    }
    return Collections2.transform(r, Runnables.SEND_EVENTS);
}

From source file:com.censoredsoftware.infractions.bukkit.legacy.compat.LegacyDossier.java

public LegacyDossier(UUID mojangId, Set<Infraction> infractions) {
    this.mojangid = mojangId;
    this.infractions = Sets.newHashSet(Collections2.transform(infractions, new Function<Infraction, String>() {
        @Override/* w w w . ja va2 s .  c  o  m*/
        public String apply(Infraction infraction) {
            String id = MiscUtil.getInfractionId(infraction);
            DataManager.getManager().getMapFor(LegacyInfraction.class).put(MiscUtil.getInfractionId(infraction),
                    LegacyInfraction.of(infraction));
            return id;
        }
    }));
    this.ipAddresses = Sets.newHashSet();
}

From source file:org.opendaylight.yangtools.yang.data.api.schema.tree.NormalizedNodeDataTreeCandidateNode.java

@Nonnull
@Override//from www.java 2  s.c  o m
public Collection<DataTreeCandidateNode> getChildNodes() {
    if (data instanceof NormalizedNodeContainer) {
        return Collections2.transform(((NormalizedNodeContainer<?, ?, ?>) data).getValue(), FACTORY_FUNCTION);
    }
    return ImmutableList.of();
}

From source file:brooklyn.rest.resources.ActivityResource.java

@Override
public List<TaskSummary> children(String taskId) {
    Task<?> t = mgmt().getExecutionManager().getTask(taskId);
    if (t == null)
        throw WebResourceUtils.notFound("Cannot find task '%s'", taskId);
    if (!(t instanceof HasTaskChildren))
        return Collections.emptyList();
    return new LinkedList<TaskSummary>(Collections2
            .transform(Lists.newArrayList(((HasTaskChildren) t).getChildren()), TaskTransformer.FROM_TASK));
}

From source file:ninja.leaping.permissionsex.backend.file.FileOptionSubjectData.java

private static Set<Entry<String, String>> contextsFrom(ConfigurationNode node) {
    Set<Entry<String, String>> contexts = Collections.emptySet();
    ConfigurationNode contextsNode = node.getNode(KEY_CONTEXTS);
    if (contextsNode.hasMapChildren()) {
        contexts = ImmutableSet.copyOf(Collections2.transform(contextsNode.getChildrenMap().entrySet(),
                new Function<Map.Entry<Object, ? extends ConfigurationNode>, Entry<String, String>>() {
                    @Nullable/*from w w  w . j  a va 2  s. c o  m*/
                    @Override
                    public Entry<String, String> apply(Map.Entry<Object, ? extends ConfigurationNode> ent) {
                        return Maps.immutableEntry(ent.getKey().toString(),
                                String.valueOf(ent.getValue().getValue()));
                    }
                }));
    }
    return contexts;
}

From source file:com.sun.tools.hat.internal.server.RefsByTypeQuery.java

@Override
public void run() {
    ClassResolver resolver = new ClassResolver(snapshot, true);
    JavaClass clazz = resolver.apply(query);
    Collection<JavaClass> referrers = Collections2.transform(params.get("referrer"), resolver);
    ImmutableSetMultimap.Builder<JavaClass, JavaHeapObject> rfrBuilder = ImmutableSetMultimap.builder();
    final ImmutableSetMultimap.Builder<JavaClass, JavaHeapObject> rfeBuilder = ImmutableSetMultimap.builder();
    for (final JavaHeapObject instance : Misc.getInstances(clazz, false, referrers)) {
        if (instance.getId() == -1) {
            continue;
        }/*  www.j a va  2 s  .c om*/
        for (JavaHeapObject ref : instance.getReferers()) {
            JavaClass cl = ref.getClazz();
            if (cl == null) {
                System.out.println("null class for " + ref);
                continue;
            }
            rfrBuilder.put(cl, instance);
        }
        instance.visitReferencedObjects(obj -> rfeBuilder.put(obj.getClazz(), instance));
    } // for each instance

    startHtml("References by Type");
    out.println("<p align='center'>");
    printClass(clazz);
    if (clazz.getId() != -1) {
        println("[" + clazz.getIdString() + "]");
    }
    out.println("</p>");
    printBreadcrumbs(path, null, null, clazz, referrers, null);

    ImmutableMultiset<JavaClass> referrersStat = rfrBuilder.build().keys();
    if (!referrersStat.isEmpty()) {
        out.println("<h3 align='center'>Referrers by Type</h3>");
        print(referrersStat, clazz, referrers, true);
    }

    ImmutableMultiset<JavaClass> refereesStat = rfeBuilder.build().keys();
    if (!refereesStat.isEmpty()) {
        out.println("<h3 align='center'>Referees by Type</h3>");
        print(refereesStat, clazz, referrers, false);
    }

    endHtml();
}

From source file:com.textocat.textokit.ml.LemmaFeatureExtractor.java

@Override
public List<Feature> extract(JCas view, Annotation focusAnnotation) throws CleartkExtractorException {
    Word focusWord = PUtils.getWordAnno(view, focusAnnotation);
    if (focusWord == null || focusWord.getWordforms() == null) {
        return ImmutableList.of();
    }//  w  w  w  .j  a v a 2s  . c om
    Collection<Wordform> wfs = FSCollectionFactory.create(focusWord.getWordforms(), Wordform.class);
    Set<String> lemmas = Sets.newHashSet();
    for (Wordform wf : wfs) {
        if (wf.getLemma() != null) {
            lemmas.add(wf.getLemma());
        }
    }
    return Lists.newArrayList(Collections2.transform(lemmas, lemma2Feature));
}

From source file:com.qcadoo.model.api.utils.EntityUtils.java

public static Collection<Long> getIdsView(final Collection<Entity> entities) {
    return Collections2.transform(entities, getIdExtractor());
}

From source file:org.apache.kylin.job.streaming.Kafka10DataLoader.java

public void loadIntoKafka(List<String> messages) {

    KafkaClusterConfig clusterConfig = kafkaClusterConfigs.get(0);
    String brokerList = StringUtils.join(
            Collections2.transform(clusterConfig.getBrokerConfigs(), new Function<BrokerConfig, String>() {
                @Nullable/*from  w  w  w .  j  a va  2s.co  m*/
                @Override
                public String apply(BrokerConfig brokerConfig) {
                    return brokerConfig.getHost() + ":" + brokerConfig.getPort();
                }
            }), ",");

    KafkaProducer producer = getKafkaProducer(brokerList, null);

    for (int i = 0; i < messages.size(); i++) {
        ProducerRecord<String, String> keyedMessage = new ProducerRecord<String, String>(
                clusterConfig.getTopic(), String.valueOf(i), messages.get(i));
        producer.send(keyedMessage);
    }
    logger.info("sent " + messages.size() + " messages to " + this.toString());
    producer.close();
}