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

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

Introduction

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

Prototype

boolean putAll(@Nullable K key, Iterable<? extends V> values);

Source Link

Document

Stores a key-value pair in this multimap for each of values , all using the same key, key .

Usage

From source file:com.squareup.wire.schema.Linker.java

public Schema link() {
    // Register the types.
    for (ProtoFile protoFile : protoFiles) {
        for (Type type : protoFile.types()) {
            register(type);/*from w  w w  .  j  ava  2s .  c  om*/
        }
    }

    // Link extensions. This depends on type registration.
    for (ProtoFile protoFile : protoFiles) {
        Linker linker = withContext(protoFile);
        for (Extend extend : protoFile.extendList()) {
            extend.link(linker);
        }
    }

    // Link proto files and services.
    for (ProtoFile protoFile : protoFiles) {
        Linker linker = withContext(protoFile);
        for (Type type : protoFile.types()) {
            type.link(linker);
        }
        for (Service service : protoFile.services()) {
            service.link(linker);
        }
    }

    // Link options. We can't link any options until we've linked all fields!
    for (ProtoFile protoFile : protoFiles) {
        Linker linker = withContext(protoFile);
        protoFile.linkOptions(linker);
        for (Type type : protoFile.types()) {
            type.linkOptions(linker);
        }
        for (Service service : protoFile.services()) {
            service.linkOptions(linker);
        }
    }

    // Compute public imports so we know that importing a.proto also imports b.proto and c.proto.
    Multimap<String, String> publicImports = LinkedHashMultimap.create();
    for (ProtoFile protoFile : protoFiles) {
        publicImports.putAll(protoFile.location().path(), protoFile.publicImports());
    }
    // For each proto, gather its imports and its transitive imports.
    for (ProtoFile protoFile : protoFiles) {
        Collection<String> sink = imports.get(protoFile.location().path());
        addImports(sink, protoFile.imports(), publicImports);
        addImports(sink, protoFile.publicImports(), publicImports);
    }

    // Validate the linked schema.
    for (ProtoFile protoFile : protoFiles) {
        Linker linker = withContext(protoFile);
        for (Type type : protoFile.types()) {
            type.validate(linker);
        }
        for (Service service : protoFile.services()) {
            service.validate(linker);
        }
        for (Extend extend : protoFile.extendList()) {
            extend.validate(linker);
        }
    }

    if (!errors.isEmpty()) {
        throw new SchemaException(errors);
    }

    return new Schema(protoFiles);
}

From source file:org.opentestsystem.shared.security.domain.SbacUser.java

private Map<String, Collection<GrantedAuthority>> calculateAuthoritiesByTenantId(
        final Multimap<String, SbacRole> inUserRoles) {
    Multimap<String, GrantedAuthority> ret = ArrayListMultimap.create();
    if (inUserRoles != null) {
        for (SbacRole role : inUserRoles.values()) {
            if (role.isApplicableToComponent() && role.getEffectiveTenant() != null
                    && role.getPermissions() != null && role.getPermissions().size() > 0) {
                ret.putAll(role.getEffectiveTenant().getId(), role.getPermissions());
            }//from   w  w w .  j av a2s.  co  m
        }
    }
    return ret.asMap();
}

From source file:com.palantir.atlasdb.sweep.SweepTaskRunner.java

private Multimap<Cell, Long> getTimestampsFromRowResults(List<RowResult<Set<Long>>> cellsToSweep,
        SweepStrategy sweepStrategy) {/*w  w w  .ja  v  a  2 s.  c o  m*/
    Multimap<Cell, Long> cellTsMappings = HashMultimap.create();
    for (RowResult<Set<Long>> rowResult : cellsToSweep) {
        for (Map.Entry<Cell, Set<Long>> entry : rowResult.getCells()) {
            if (sweepStrategy == SweepStrategy.CONSERVATIVE) {
                cellTsMappings.putAll(entry.getKey(), Sets.difference(entry.getValue(), invalidTimestamps));
            } else {
                cellTsMappings.putAll(entry.getKey(), entry.getValue());
            }
        }
    }
    return cellTsMappings;
}

From source file:org.robotframework.ide.eclipse.main.plugin.project.LibrariesWatchHandler.java

private void handleRebuildTask(final IProgressMonitor monitor, final RebuildTask rebuildTask) {

    final Multimap<IProject, LibrarySpecification> groupedSpecifications = LinkedHashMultimap.create();
    groupedSpecifications.putAll(rebuildTask.getProject(), rebuildTask.getSpecsToRebuild());
    invokeLibrariesBuilder(monitor, groupedSpecifications);
    robotProject.clearConfiguration();//from   w  ww . j  av a  2  s  .c  o m
    robotProject.clearKwSources();

    rebuildTasksQueue.poll();

    final RebuildTask nextRebuildTask = rebuildTasksQueue.peek();
    if (nextRebuildTask != null) {
        removePossibleDuplicatedRebuildTasks(nextRebuildTask);
        handleRebuildTask(monitor, nextRebuildTask);
    }
}

From source file:eu.mondo.driver.fourstore.FourStoreGraphDriverReadWrite.java

@Override
public void insertEdges(final Multimap<String, String> edges, final String type) throws IOException {
    if (edges.isEmpty()) {
        return;/*w  w  w .j av a 2  s. co  m*/
    }

    final ArrayList<String> sourceVertices = new ArrayList<>(edges.keySet());
    final List<List<String>> sourceVerticesPartitions = Lists.partition(sourceVertices, PARTITION_SIZE);
    for (final List<String> sourceVerticesPartition : sourceVerticesPartitions) {

        final Multimap<String, String> edgePartition = ArrayListMultimap.create();
        for (final String sourceVertexURI : sourceVerticesPartition) {
            final Collection<String> targetVertexURIs = edges.get(sourceVertexURI);
            edgePartition.putAll(sourceVertexURI, targetVertexURIs);
        }

        insertEdgesPartition(edgePartition, type);
    }
}

From source file:edu.umn.msi.tropix.webgui.server.forms.validation.SchemaParserImpl.java

protected void populateTypePredicateMap(final Map<String, Predicate<String>> typePredicateMap,
        final Element rootElement) {
    final Map<String, Element> nodes = new HashMap<String, Element>();
    for (final Element node : SchemaParserImpl.getNonAnnotationChildElements(rootElement)) {
        if (!this.isSimpleTypeNode(node)) {
            continue;
        }//from   w ww . j  a v  a 2 s  . c  o m
        final NamedNodeMap attributes = node.getAttributes();
        final Node nameNode = attributes.getNamedItem("name");
        if (nameNode == null) {
            throw new IllegalStateException("Top-level simpleType element without name encountered");
        }
        final String name = nameNode.getNodeValue();
        nodes.put(name, node);
    }

    // Create DAG of type dependencies
    final Multimap<String, String> dependencyGraph = HashMultimap.create();
    for (final String typeName : nodes.keySet()) {
        dependencyGraph.putAll(typeName, this.getSimpleTypeDependencies(nodes.get(typeName)));
    }

    final Collection<String> sortedTypeNames = this.topologicalSort(dependencyGraph);
    for (final String typeName : sortedTypeNames) {
        final Element node = nodes.get(typeName);
        final Predicate<String> predicate = this.buildPredicate(node, typePredicateMap);
        typePredicateMap.put(typeName, predicate);
    }
}

From source file:eu.mondo.driver.fourstore.FourStoreGraphDriverReadWrite.java

@Override
public void insertEdgesWithVertex(final Multimap<String, String> edges, final String edgeType,
        final String targetVertexType) throws IOException {
    if (edges.isEmpty()) {
        return;/*w  ww.ja v  a2  s.  co  m*/
    }

    final ArrayList<String> sourceVertices = new ArrayList<>(edges.keySet());
    final List<List<String>> sourceVerticesPartitions = Lists.partition(sourceVertices, PARTITION_SIZE);
    for (final List<String> sourceVerticesPartition : sourceVerticesPartitions) {

        final Multimap<String, String> edgePartition = ArrayListMultimap.create();
        for (final String sourceVertexURI : sourceVerticesPartition) {
            final Collection<String> targetVertexURIs = edges.get(sourceVertexURI);
            edgePartition.putAll(sourceVertexURI, targetVertexURIs);
        }

        insertEdgesWithVertexPartition(edgePartition, edgeType, targetVertexType);
    }

}

From source file:edu.cmu.lti.oaqa.baseqa.concept.rerank.scorers.LuceneConceptScorer.java

@Override
public void prepare(JCas jcas) throws AnalysisEngineProcessException {
    uri2conf2score = HashBasedTable.create();
    uri2conf2rank = HashBasedTable.create();
    List<String> tokens = TypeUtil.getOrderedTokens(jcas).stream().map(Token::getCoveredText)
            .map(QueryParser::escape).filter(name -> !name.isEmpty() && !stoplist.contains(name.toLowerCase()))
            .collect(toList());/*w ww .j  a va 2 s .  com*/
    Multimap<String, String> ctype2names = HashMultimap.create();
    for (Concept concept : TypeUtil.getConcepts(jcas)) {
        Set<String> ctypes = TypeUtil.getConceptTypes(concept).stream().map(ConceptType::getAbbreviation)
                .collect(toSet());
        String cnames = TypeUtil.getConceptNames(concept).stream().map(LuceneConceptScorer::normalizeQuoteName)
                .distinct().collect(joining(" "));
        ctypes.stream().filter(t -> !FORBIDDEN_CTYPES.contains(t))
                .forEach(ctype -> ctype2names.put(ctype, cnames));
    }
    Multimap<String, String> ctypepre2names = HashMultimap.create();
    ctype2names.asMap().entrySet().forEach(e -> ctypepre2names.putAll(e.getKey().split(":")[0], e.getValue()));
    Multimap<String, String> ctype2mentions = HashMultimap.create();
    for (Concept concept : TypeUtil.getConcepts(jcas)) {
        Set<String> ctypes = TypeUtil.getConceptTypes(concept).stream().map(ConceptType::getAbbreviation)
                .collect(toSet());
        String cmentions = TypeUtil.getConceptMentions(concept).stream().map(ConceptMention::getMatchedName)
                .map(LuceneConceptScorer::normalizeQuoteName).distinct().collect(joining(" "));
        ctypes.stream().filter(t -> !FORBIDDEN_CTYPES.contains(t))
                .forEach(ctype -> ctype2mentions.put(ctype, cmentions));
    }
    Multimap<String, String> ctypepre2mentions = HashMultimap.create();
    ctypepre2mentions.asMap().entrySet()
            .forEach(e -> ctypepre2mentions.putAll(e.getKey().split(":")[0], e.getValue()));
    LOG.debug("Query strings");
    ExecutorService service = Executors.newCachedThreadPool();
    // execute against all tokens
    service.submit(() -> {
        String concatTokens = String.join(" ", tokens);
        LOG.debug(" - Concatenated tokens: {}", concatTokens);
        for (String field : fields) {
            searchInField(concatTokens, field, "tokens_concatenated@" + field);
        }
        searchAllField(concatTokens, "tokens_concatenated@all");
    });
    // execute against concatenated concept names
    service.submit(() -> {
        String concatCnames = String.join(" ", ctype2names.values());
        LOG.debug(" - Concatenated concept names: {}", concatCnames);
        for (String field : fields) {
            searchInField(concatCnames, field, "cnames_concatenated@" + field);
        }
        searchAllField(concatCnames, "cnames_concatenated@all");
    });
    // execute against concatenated concept mentions
    service.submit(() -> {
        String concatCmentions = String.join(" ", ctype2mentions.values());
        LOG.debug(" - Concatenated concept mentions: {}", concatCmentions);
        for (String field : fields) {
            searchInField(concatCmentions, field, "cmentions_concatenated@" + field);
        }
        searchAllField(concatCmentions, "cmentions_concatenated@");
    });
    // execute against concept names for each concept
    service.submit(() -> {
        for (String cnames : ImmutableSet.copyOf(ctype2names.values())) {
            LOG.debug(" - Concatenated concept names: {}", cnames);
            for (String field : fields) {
                searchInField(cnames, field, "cnames_individual@" + field);
            }
            searchAllField(cnames, "cnames_individual@all");
        }
    });
    // execute against concept names for each concept type
    service.submit(() -> {
        for (String ctype : ctype2names.keySet()) {
            String concatCnames = String.join(" ", ctype2names.get(ctype));
            LOG.debug(" - Concatenated concept names for {}: {}", ctype, concatCnames);
            for (String field : fields) {
                searchInField(concatCnames, field, "cnames@" + ctype + "@" + field);
            }
            searchAllField(concatCnames, "cnames@" + ctype + "@all");
        }
    });
    // execute against concept names for each concept type prefix
    service.submit(() -> {
        for (String ctypepre : ctypepre2names.keySet()) {
            String concatCnames = String.join(" ", ctypepre2names.get(ctypepre));
            LOG.debug(" - Concatenated concept names for {}: {}", ctypepre, concatCnames);
            for (String field : fields) {
                searchInField(concatCnames, field, "cnames@" + ctypepre + "@" + field);
            }
            searchAllField(concatCnames, "cnames@" + ctypepre + "@all");
        }
    });
    // execute against concept mentions for each concept
    service.submit(() -> {
        for (String cmentions : ImmutableSet.copyOf(ctype2mentions.values())) {
            LOG.debug(" - Concatenated concept mentions: {}", cmentions);
            for (String field : fields) {
                searchInField(cmentions, field, "cmentions_individual@" + field);
            }
            searchAllField(cmentions, "cmentions_individual@all");
        }
    });
    // execute against concept mentions for each concept type
    service.submit(() -> {
        for (String ctype : ctype2mentions.keySet()) {
            String concatCmentions = String.join(" ", ctype2mentions.get(ctype));
            LOG.debug(" - Concatenated concept mentions for {}: {}", ctype, concatCmentions);
            for (String field : fields) {
                searchInField(concatCmentions, field, "cmentions@" + ctype + "@" + field);
            }
            searchAllField(concatCmentions, "cmentions@" + ctype + "@all");
        }
    });
    // execute against concept mentions for each concept type prefix
    service.submit(() -> {
        for (String ctypepre : ctypepre2mentions.keySet()) {
            String concatCmentions = String.join(" ", ctypepre2mentions.get(ctypepre));
            LOG.debug(" - Concatenated concept mentions for {}: {}", ctypepre, concatCmentions);
            for (String field : fields) {
                searchInField(concatCmentions, field, "cmentions@" + ctypepre + "@" + field);
            }
            searchAllField(concatCmentions, "cmentions@" + ctypepre + "@all");
        }
    });
    service.shutdown();
    try {
        service.awaitTermination(1, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        throw new AnalysisEngineProcessException(e);
    }
    confs = uri2conf2score.columnKeySet();
}

From source file:com.textocat.textokit.morph.opencorpora.resource.YoLemmaPostProcessor.java

/**
 * {@inheritDoc}/*from www.j  a  va  2  s.  c o  m*/
 */
@Override
public boolean process(MorphDictionary dict, Lemma.Builder lemmaBuilder, Multimap<String, Wordform> wfMap) {
    Multimap<String, Wordform> additionalWfs = LinkedHashMultimap.create();
    for (String wfStr : wfMap.keySet()) {
        // alternative wordform string
        String altStr = StringUtils.replaceChars(wfStr, YO_CHARS, YO_REPLACEMENTS);
        if (Objects.equal(wfStr, altStr)) {
            continue;
        } // else wfStr contains 'yo'
        if (wfMap.containsKey(altStr)) {
            // the wordform multimap already contains string without 'yo'
            continue;
        }
        additionalWfs.putAll(altStr, wfMap.get(wfStr));
    }
    wfMap.putAll(additionalWfs);
    return true;
}

From source file:com.google.devrel.gmscore.tools.apk.arsc.ArscBlamer.java

/** Returns a multimap of keys for which there is no default resource. */
public Multimap<ResourceEntry, TypeChunk.Entry> getBaselessKeys() {
    if (baselessKeys != null) {
        return baselessKeys;
    }//from   w  ww  .ja v  a 2  s. c  o  m
    Multimap<ResourceEntry, TypeChunk.Entry> result = HashMultimap.create();
    for (Entry<ResourceEntry, Collection<TypeChunk.Entry>> entry : getResourceEntries().asMap().entrySet()) {
        Collection<TypeChunk.Entry> chunkEntries = entry.getValue();
        if (!hasBaseConfiguration(chunkEntries)) {
            result.putAll(entry.getKey(), chunkEntries);
        }
    }
    baselessKeys = result;
    return result;
}