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

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

Introduction

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

Prototype

Collection<V> get(@Nullable K key);

Source Link

Document

Returns a view collection of the values associated with key in this multimap, if any.

Usage

From source file:am.ik.categolj2.domain.service.entry.EntryServiceImpl.java

void applyRelations(Iterable<Entry> entries) {
    List<Integer> entryIds = StreamSupport.stream(entries.spliterator(), false).map(Entry::getEntryId)
            .collect(Collectors.toList());
    if (!entryIds.isEmpty()) {
        // apply categories
        List<Category> categories = categoryRepository.findByEntryIds(entryIds);

        Multimap<Integer, Category> categoryMultimap = TreeMultimap.create();
        for (Category c : categories) {
            categoryMultimap.put(c.getEntry().getId(), c);
        }//ww  w. ja  v a2s. c om
        for (Entry entry : entries) {
            entry.setCategory(new ArrayList<>(categoryMultimap.get(entry.getId())));
        }
        // apply tags
        List<TagAndEntryId> tags = tagRepository.findByEntryIds(entryIds);
        Multimap<Integer, Tag> tagMultimap = HashMultimap.create();
        for (TagAndEntryId tag : tags) {
            tagMultimap.put(tag.getEntryId(), tag.getTag());
        }
        for (Entry entry : entries) {
            entry.setTags(new LinkedHashSet<>(tagMultimap.get(entry.getEntryId())));
        }
    }
}

From source file:de.unisb.cs.st.javalanche.mutation.analyze.html.HtmlAnalyzer.java

public HtmlReport analyze(Iterable<Mutation> mutations) {
    HtmlReport report = new HtmlReport();
    Multimap<String, Mutation> map = HashMultimap.create();
    for (Mutation m : mutations) {
        map.put(getClassName(m), m);//ww  w  .  ja v a 2s . c o  m
    }
    Set<String> keySet = map.keySet();
    for (String key : keySet) {
        Iterable<String> content = getClassContent(key);
        ClassReport classReport = ClassReportFactory.getClassReport(key, content,
                new ArrayList<Mutation>(map.get(key)));
        report.add(classReport);
    }
    return report;
}

From source file:org.artifactory.ui.rest.service.builds.buildsinfo.tabs.licenses.OverrideSelectedLicensesService.java

private void fetchLicenseToOverride(Collection<ModuleLicenseModel> viewableModels,
        Multimap<RepoPath, ModuleLicenseModel> repoPathLicenseMultimap,
        List<ModuleLicenseModel> moduleLicenseModels) {
    for (ModuleLicenseModel license : viewableModels) {
        RepoPath repoPath = InternalRepoPathFactory.create(license.getRepoKey(), license.getPath());
        Collection<ModuleLicenseModel> licenses = repoPathLicenseMultimap.get(repoPath);
        for (ModuleLicenseModel subLicense : licenses) {
            if (subLicense.getLicense().getName().equals(license.getLicense().getName())) {
                subLicense.setExtractedLicense(license.getExtractedLicense());
                moduleLicenseModels.add(subLicense);
            }/*from   w w w  . ja v a2 s. c  om*/
        }
    }
}

From source file:org.mule.util.journal.queue.LocalTxQueueTransactionRecoverer.java

/**
 * Recover all the pending transactions.
 *
 * Will undo all operations done over queues that were not commit or rolled back.
 *
 * Clears the transaction log after processing all the log entries since does entries are not longer
 * required.// w  ww .j a  v  a2  s.  com
 */
public void recover() {
    if (logger.isDebugEnabled()) {
        logger.debug("Executing transaction recovery");
    }
    Multimap<Integer, LocalQueueTxJournalEntry> allEntries = this.localTxQueueTransactionJournal
            .getAllLogEntries();
    if (logger.isDebugEnabled()) {
        logger.debug("Found " + allEntries.size() + " txs to recover");
    }
    int txRecovered = 0;
    for (Integer txId : allEntries.keySet()) {
        Collection<LocalQueueTxJournalEntry> entries = allEntries.get(txId);
        Object commitOrRollback = CollectionUtils.find(entries, new Predicate() {
            @Override
            public boolean evaluate(Object object) {
                LocalQueueTxJournalEntry logEntry = (LocalQueueTxJournalEntry) object;
                return logEntry.isCommit() || logEntry.isRollback();
            }
        });
        if (commitOrRollback != null) {
            continue;
        }
        txRecovered++;
        for (LocalQueueTxJournalEntry logEntry : entries) {
            if (logEntry.isRemove()) {
                String queueName = logEntry.getQueueName();
                RecoverableQueueStore queue = queueProvider.getRecoveryQueue(queueName);
                Serializable polledValue = logEntry.getValue();
                if (!queue.contains(polledValue)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "re-adding polled element that was not commited to queue " + queue.getName());
                    }
                    try {
                        queue.putNow(polledValue);
                    } catch (InterruptedException e) {
                        throw new MuleRuntimeException(e);
                    }
                }
            } else if (logEntry.isAdd() || logEntry.isAddFirst()) {
                Serializable offeredValue = logEntry.getValue();
                String queueName = logEntry.getQueueName();
                RecoverableQueueStore queue = queueProvider.getRecoveryQueue(queueName);
                if (queue.contains(offeredValue)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug(
                                "removing offer element that was not commited to queue " + queue.getName());
                    }
                    queue.remove(offeredValue);
                }
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Recovered " + txRecovered + " txs to recover");
    }
    this.localTxQueueTransactionJournal.clear();
}

From source file:com.google.googlejavaformat.java.RemoveUnusedImports.java

/** Construct replacements to fix unused imports. */
private static RangeMap<Integer, String> buildReplacements(String contents, JCCompilationUnit unit,
        Set<String> usedNames, Multimap<String, Range<Integer>> usedInJavadoc) {
    RangeMap<Integer, String> replacements = TreeRangeMap.create();
    for (JCImport importTree : unit.getImports()) {
        String simpleName = getSimpleName(importTree);
        if (!isUnused(unit, usedNames, usedInJavadoc, importTree, simpleName)) {
            continue;
        }//from www  . ja v a2  s. c o  m
        // delete the import
        int endPosition = importTree.getEndPosition(unit.endPositions);
        endPosition = Math.max(CharMatcher.isNot(' ').indexIn(contents, endPosition), endPosition);
        String sep = Newlines.guessLineSeparator(contents);
        if (endPosition + sep.length() < contents.length()
                && contents.subSequence(endPosition, endPosition + sep.length()).toString().equals(sep)) {
            endPosition += sep.length();
        }
        replacements.put(Range.closedOpen(importTree.getStartPosition(), endPosition), "");
        // fully qualify any javadoc references with the same simple name as a deleted
        // non-static import
        if (!importTree.isStatic()) {
            for (Range<Integer> docRange : usedInJavadoc.get(simpleName)) {
                if (docRange == null) {
                    continue;
                }
                String replaceWith = importTree.getQualifiedIdentifier().toString();
                replacements.put(docRange, replaceWith);
            }
        }
    }
    return replacements;
}

From source file:org.eclipse.viatra.transformation.runtime.emf.changemonitor.ChangeMonitor.java

/**
 * Public method used for adding new rules to the monitor. This method can be used both before and after monitoring
 * has been started.//from   w w w .  ja v a2  s  .c o  m
 * 
 * @param rule
 *            The rule to be added to the monitor
 */
public void addRule(RuleSpecification<IPatternMatch> rule) {
    rules.add(rule);
    Multimap<ActivationState, Job<IPatternMatch>> jobs = rule.getJobs();
    if (started) {
        executionSchema.addRule(rule);
    }
    for (ActivationState state : jobs.keySet()) {
        for (Job<?> job : jobs.get(state)) {
            if (started) {
                EnableJob<?> enableJob = (EnableJob<?>) job;
                enableJob.setEnabled(true);
            } else {
                allJobs.add(job);
            }
        }
    }
}

From source file:com.github.rinde.rinsim.core.model.DependencyResolver.java

ImmutableSet<Model<?>> resolve() {
    addDefaultModels();/*from   w  ww  .  j ava  2  s  .  c o m*/
    final Multimap<Dependency, Dependency> dependencyGraph = constructDependencyGraph();

    if (LOGGER.isTraceEnabled()) {
        for (final Dependency dep : dependencyGraph.keySet()) {
            final StringBuilder sb = new StringBuilder();
            for (final Dependency d : dependencyGraph.get(dep)) {
                sb.append(d.modelBuilder).append(" ");
            }
            LOGGER.trace("{} requires: {}.", dep.modelBuilder.toString(), sb);
        }
    }

    while (!dependencyGraph.isEmpty()) {
        final List<Dependency> toRemove = new ArrayList<>();
        for (final Dependency dep : dependencyGraph.keys()) {
            final Collection<Dependency> dependencies = dependencyGraph.get(dep);
            boolean allResolved = true;
            for (final Dependency dependency : dependencies) {
                allResolved &= dependency.isResolved();
            }
            if (allResolved) {
                dep.build();
                toRemove.add(dep);
            }
        }

        for (final Dependency mb : toRemove) {
            dependencyGraph.removeAll(mb);
        }
        if (toRemove.isEmpty()) {
            throw new IllegalArgumentException("Could not resolve dependencies for " + dependencyGraph.keySet()
                    + ", most likely a circular dependency was declared.");
        }
    }

    final ImmutableSet.Builder<Model<?>> builder = ImmutableSet.builder();
    for (final Dependency cmb : builders) {
        builder.add(cmb.build());
    }
    return builder.build();
}

From source file:com.squareup.osstrich.JavadocPublisher.java

private void writeIndexFiles(String groupId, Multimap<String, Artifact> artifacts) throws IOException {
    for (String majorVersion : artifacts.keySet()) {
        StringBuilder html = new StringBuilder();
        html.append("<!DOCTYPE html>\n<html><head><title>").append(groupId)
                .append("</title></head>\n<body>\n<h1>").append(groupId).append("</h1>\n<ul>\n");
        for (Artifact artifact : artifacts.get(majorVersion)) {
            html.append("<li><a href=\"").append(artifact.artifactId).append("\">").append(artifact.artifactId)
                    .append("</li>\n");
        }/* w w w  .  java 2  s  . com*/
        html.append("</ul>\n</body>\n</html>");

        File indexHtml = new File(directory + "/" + majorVersion + "/index.html");
        Files.write(html, indexHtml, UTF_8);
        gitAdd(indexHtml);
    }
}