Example usage for com.google.common.collect Multimap asMap

List of usage examples for com.google.common.collect Multimap asMap

Introduction

In this page you can find the example usage for com.google.common.collect Multimap asMap.

Prototype

Map<K, Collection<V>> asMap();

Source Link

Document

Returns a view of this multimap as a Map from each distinct key to the nonempty collection of that key's associated values.

Usage

From source file:com.b2international.commons.graph.GraphUtilsInternal.java

/**
 * Returns with the longest path from the DAG represented as the multimap argument.
 * <p>Keys are nodes and there are a dedicated edged to each value associated with a key.  
 * @param multimap the multimap representing a DAG.
 * @return the longest path.// w  w w . jav  a2 s  . co m
 */
/*default*/ static <N> List<N> getLongestPath(final Multimap<N, N> multimap) {
    checkNotNull(multimap, "multimap");
    return getLongestPath(multimap.asMap());
}

From source file:edu.sdsc.solr.lemmatization.LemmatizationWriter.java

static void writeSynonyms(Multimap<String, String> synonyms, Writer writer) throws IOException {
    for (Entry<String, Collection<String>> entry : synonyms.asMap().entrySet()) {
        entry.getValue().add(entry.getKey());
        writer.write(Joiner.on(", ").join(entry.getValue()) + "\n");
    }//w  w  w .ja  v a  2s  .co m
}

From source file:org.sonar.server.issue.notification.DoNotFixNotificationDispatcher.java

private static void notify(String author, Context context,
        Multimap<String, NotificationChannel> subscribedRecipients) {
    for (Map.Entry<String, Collection<NotificationChannel>> channelsByRecipients : subscribedRecipients.asMap()
            .entrySet()) {/*from  w  w  w.  j av  a2  s  .c o m*/
        String login = channelsByRecipients.getKey();
        // Do not notify the person that resolved the issue
        if (!Objects.equals(author, login)) {
            for (NotificationChannel channel : channelsByRecipients.getValue()) {
                context.addUser(login, channel);
            }
        }
    }
}

From source file:com.google.devtools.build.lib.rules.objc.Xcdatamodels.java

static Iterable<Xcdatamodel> xcdatamodels(IntermediateArtifacts intermediateArtifacts,
        Iterable<Artifact> xcdatamodels) {
    ImmutableSet.Builder<Xcdatamodel> result = new ImmutableSet.Builder<>();
    Multimap<PathFragment, Artifact> artifactsByContainer = byContainer(xcdatamodels);

    for (Map.Entry<PathFragment, Collection<Artifact>> modelDirEntry : artifactsByContainer.asMap()
            .entrySet()) {/*from  ww w  .  ja  v  a 2  s. c  o m*/
        PathFragment container = modelDirEntry.getKey();
        Artifact outputZip = intermediateArtifacts.compiledMomZipArtifact(container);
        result.add(new Xcdatamodel(outputZip, ImmutableSet.copyOf(modelDirEntry.getValue()), container));
    }

    return result.build();
}

From source file:de.textmining.nerdle.utils.MapSorter.java

public static <K, V extends Comparable<? super V>> List<Map.Entry<K, Collection<String>>> multimapSortedByListSize(
        final Multimap<K, String> multiMap) {

    List<Map.Entry<K, Collection<String>>> entries = new ArrayList<Map.Entry<K, Collection<String>>>();
    entries.addAll(multiMap.asMap().entrySet());

    Collections.sort(entries, new Comparator<Map.Entry<K, Collection<String>>>() {
        // @Override
        public int compare(Map.Entry<K, Collection<String>> e1, Map.Entry<K, Collection<String>> e2) {
            return Ints.compare(e2.getValue().size(), e1.getValue().size());
        }//  w  w w  .  jav  a 2  s.c o  m
    });

    return entries;
}

From source file:com.palantir.atlasdb.table.generation.ColumnValues.java

public static <T extends Persistable, V extends Persistable> Set<Cell> toCells(Multimap<T, V> map) {
    Set<Cell> ret = Sets.newHashSetWithExpectedSize(map.size());
    for (Entry<T, Collection<V>> e : map.asMap().entrySet()) {
        byte[] rowName = e.getKey().persistToBytes();
        for (Persistable val : e.getValue()) {
            ret.add(Cell.create(rowName, val.persistToBytes()));
        }/*from   w w  w .  j  av  a 2  s .  co  m*/
    }
    return ret;
}

From source file:org.apache.abdera2.common.templates.MapContext.java

public static MapContext fromMultimap(Multimap<String, Object> multimap) {
    MapContext mc = new MapContext();
    mc.putAll(multimap.asMap());
    return mc;/*  ww w  . jav a  2 s  .  c  om*/
}

From source file:edu.sdsc.scigraph.internal.CypherUtil.java

static Map<String, Object> flattenMap(Multimap<String, Object> paramMap) {
    Map<String, Object> flatMap = new HashMap<>();
    for (Entry<String, Collection<Object>> entry : paramMap.asMap().entrySet()) {
        flatMap.put(entry.getKey(), getFirst(entry.getValue(), null));
    }//from   ww  w . ja  v  a2s .  c  om
    return flatMap;
}

From source file:ubicrypt.core.FileSynchronizer.java

/** return only files which are not in conflict */
static Multimap<UUID, FileProvenience> withoutConflicts(final Multimap<UUID, FileProvenience> all) {
    return all.asMap().entrySet().stream()
            .filter(entry -> entry.getValue().stream()
                    .filter(fp -> entry.getValue().stream()
                            .filter(fp2 -> fp.getFile().compare(fp2.getFile()) != VClock.Comparison.conflict)
                            .collect(Collectors.toList()).size() == entry.getValue().size())
                    .collect(Collectors.toList()).size() == entry.getValue().size())
            .collect(LinkedHashMultimap::create,
                    (multimap, entry) -> multimap.putAll(entry.getKey(), all.get(entry.getKey())),
                    (m1, m2) -> m1.putAll(m2));
}

From source file:ubicrypt.core.FileSynchronizer.java

/** return only files which are in conflict */
static Multimap<UUID, FileProvenience> conflicts(final Multimap<UUID, FileProvenience> all) {
    return all.asMap().entrySet().stream()
            .filter(entry -> entry.getValue().stream()
                    .filter(fp -> entry.getValue().stream()
                            .filter(fp2 -> fp.getFile().compare(fp2.getFile()) == VClock.Comparison.conflict)
                            .collect(Collectors.toList()).size() == 0)
                    .collect(Collectors.toList()).size() == 0)
            .collect(LinkedHashMultimap::create,
                    (multimap, entry) -> multimap.putAll(entry.getKey(), all.get(entry.getKey())),
                    (m1, m2) -> m1.putAll(m2));
}