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

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

Introduction

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

Prototype

boolean put(@Nullable K key, @Nullable V value);

Source Link

Document

Stores a key-value pair in this multimap.

Usage

From source file:org.deephacks.confit.internal.hbase.HBeanPredecessors.java

public static Multimap<byte[], byte[]> getPredecessors(Multimap<String, String> predecessors,
        final UniqueIds uids) {
    final Multimap<byte[], byte[]> bytes = ArrayListMultimap.create();

    for (String schemaName : predecessors.keySet()) {
        final byte[] sid = uids.getUsid().getId(schemaName);
        Collection<String> ids = predecessors.get(schemaName);
        bytes.put(sid, HBeanReferences.getIids(new ArrayList<String>(ids), uids));
    }//w  w w. j  av  a  2 s  . c  o m
    return bytes;
}

From source file:com.google.errorprone.bugpatterns.WildcardImport.java

/** Creates a {@link Fix} that replaces wildcard imports. */
static Fix createFix(ImmutableList<ImportTree> wildcardImports, Multimap<ImportTree, TypeToImport> toFix,
        VisitorState state) {/*from w  ww. j a  v a  2s  .  co m*/
    final SuggestedFix.Builder fix = SuggestedFix.builder();
    for (ImportTree importToDelete : wildcardImports) {
        String importSpecification = importToDelete.getQualifiedIdentifier().toString();
        if (importToDelete.isStatic()) {
            fix.removeStaticImport(importSpecification);
        } else {
            fix.removeImport(importSpecification);
        }
    }
    Multimap<Symbol, TypeToImport> importsByOwner = LinkedHashMultimap.create();
    for (TypeToImport toImport : toFix.values()) {
        importsByOwner.put(toImport.owner(), toImport);
    }
    for (Map.Entry<Symbol, Collection<TypeToImport>> entries : importsByOwner.asMap().entrySet()) {
        final Symbol owner = entries.getKey();
        if (entries.getValue().size() > MAX_MEMBER_IMPORTS) {
            qualifiedNameFix(fix, owner, state);
        } else {
            for (TypeToImport toImport : toFix.values()) {
                toImport.addFix(fix);
            }
        }
    }
    return fix.build();
}

From source file:com.google.javascript.jscomp.Diagnostics.java

private static ImmutableMultimap<DiagnosticType, String> initDiagnosticGroups() {
    Multimap<DiagnosticType, String> builder = HashMultimap.create();
    for (Map.Entry<String, DiagnosticGroup> group : GROUPS.getRegisteredGroups().entrySet()) {
        for (DiagnosticType type : group.getValue().getTypes()) {
            builder.put(type, group.getKey());
        }/*from  www  . jav  a2  s.  c  om*/
    }
    return ImmutableMultimap.copyOf(builder);
}

From source file:org.jclouds.http.utils.ModifyRequest.java

@SuppressWarnings("unchecked")
public static <R extends HttpRequest> R addFormParam(R request, String key, Iterable<?> values) {
    Multimap<String, String> map = request.getPayload() != null
            ? parseQueryToMap(request.getPayload().getRawContent().toString())
            : LinkedHashMultimap.<String, String>create();
    for (Object o : values)
        map.put(key, o.toString());
    return (R) request.toBuilder().payload(newUrlEncodedFormPayload(map)).build();
}

From source file:org.sonar.scanner.issue.tracking.FileHashes.java

public static FileHashes create(InputFile f) {
    final byte[][] hashes = new byte[f.lines()][];
    FileMetadata.computeLineHashesForIssueTracking(f, (lineIdx, hash) -> hashes[lineIdx - 1] = hash);

    int size = hashes.length;
    Multimap<String, Integer> linesByHash = LinkedHashMultimap.create();
    String[] hexHashes = new String[size];
    for (int i = 0; i < size; i++) {
        String hash = hashes[i] != null ? Hex.encodeHexString(hashes[i]) : "";
        hexHashes[i] = hash;// w  w  w.  j a va 2 s. c om
        // indices in array are shifted one line before
        linesByHash.put(hash, i + 1);
    }
    return new FileHashes(hexHashes, linesByHash);
}

From source file:jflowmap.views.flowmap.VisualNodeCluster.java

public static List<List<VisualNode>> combineClusters(List<List<VisualNode>> clusters1,
        List<List<VisualNode>> clusters2) {
    Map<VisualNode, Integer> map1 = createNodeToClusterIndexMap(clusters1);
    Map<VisualNode, Integer> map2 = createNodeToClusterIndexMap(clusters2);

    Multimap<Pair<Integer, Integer>, VisualNode> newClusters = LinkedHashMultimap.create();
    for (List<VisualNode> cluster : clusters1) {
        for (VisualNode node : cluster) {
            newClusters.put(Pair.of(map1.get(node), map2.get(node)), node);
        }/*  w  w w  .  j a  v  a  2s.  c  om*/
    }

    List<List<VisualNode>> newClustersList = Lists.newArrayList();
    for (Pair<Integer, Integer> key : newClusters.asMap().keySet()) {
        newClustersList.add(ImmutableList.copyOf(newClusters.get(key)));
    }

    return newClustersList;
}

From source file:com.palantir.atlasdb.keyvalue.rocksdb.impl.RocksDbKeyValueServices.java

static void getTimestamps(RocksIterator iter, Cell cell, long timestamp, @Output Multimap<Cell, Long> results) {
    iter.seek(getKey(cell, timestamp - 1));
    for (; iter.isValid(); iter.next()) {
        Pair<Cell, Long> cellAndTs = parseCellAndTs(iter.key());
        if (!cell.equals(cellAndTs.lhSide)) {
            return;
        }/*from  w  ww  .ja v  a  2  s  . com*/
        results.put(cellAndTs.lhSide, cellAndTs.rhSide);
    }
}

From source file:org.jclouds.http.utils.ModifyRequest.java

public static Multimap<String, String> parseQueryToMap(String in) {
    Multimap<String, String> map = LinkedListMultimap.create();
    if (in == null) {
    } else if (in.indexOf('&') == -1) {
        if (in.contains("="))
            parseKeyValueFromStringToMap(in, map);
        else/*  w  w w  . j  a va  2 s .  c  o m*/
            map.put(in, null);
    } else {
        String[] parts = Strings2.urlDecode(in).split("&");
        for (String part : parts) {
            parseKeyValueFromStringToMap(part, map);
        }
    }
    return map;
}

From source file:io.scigraph.services.jersey.MultivaluedMapUtils.java

/***
 * Converts a {@link MultivaluedMap} to a {@link Multimap}.
 * /* w  ww  . ja va2s  . co  m*/
 * @param map the original map
 * @param separator an optional separator to further split the values in the map
 * @return the new multimap
 */
public static Multimap<String, Object> multivaluedMapToMultimap(MultivaluedMap<String, String> map,
        Optional<Character> separator) {
    Multimap<String, Object> merged = ArrayListMultimap.create();
    for (Entry<String, List<String>> entry : map.entrySet()) {
        for (String value : entry.getValue()) {
            if (separator.isPresent()) {
                merged.putAll(entry.getKey(), Splitter.on(separator.get()).split(value));
            } else {
                merged.put(entry.getKey(), value);
            }
        }
    }
    return merged;
}

From source file:com.google.devtools.build.android.DensitySpecificResourceFilter.java

private static Multimap<String, ResourceInfo> groupResourceInfos(final Collection<ResourceInfo> resourceInfos,
        Function<ResourceInfo, String> keyFunction) {
    Multimap<String, ResourceInfo> resourceGroups = ArrayListMultimap.create();

    for (ResourceInfo resourceInfo : resourceInfos) {
        resourceGroups.put(keyFunction.apply(resourceInfo), resourceInfo);
    }//from w w  w .j a  va  2  s .  c o m

    return ImmutableMultimap.copyOf(resourceGroups);
}