List of usage examples for com.google.common.collect Multimap keySet
Set<K> keySet();
From source file:scoutdoc.main.check.dashboard.DashboardWriter.java
public void writeFile(PrintWriter w, String title, Multimap<OutputElement, OutputElement> content, Comparator<OutputElement> comparator, List<Column> columns) { List<OutputElement> groups = Lists.newArrayList(content.keySet()); Collections.sort(groups, comparator); Context context = new Context(); context.content = content;//from w ww .java2s.c om int max = 0; for (OutputElement groupKey : groups) { Collection<OutputElement> group = content.get(groupKey); int size = group.size(); if (max < size) { max = size; } if (size == 1) { //Replace the check in the groupKey: with the check of the singleton element (constituting the group). OutputElement element = group.iterator().next(); groupKey.setCheck(element.getCheck()); } } context.distributionMax = max; List<Column> columnsInternal; if (max == 1 && !columns.contains(Column.DETAIL)) { columnsInternal = new ArrayList<DashboardWriter.Column>(columns); columnsInternal.add(Column.DETAIL); } else { columnsInternal = columns; } writeFileBegin(w, title); w.println(TABLE_OPEN); w.println(TR_OPEN); for (Column c : columnsInternal) { c.writeHeaderCell(w); } w.println(TR_CLOSE); for (OutputElement group : groups) { w.println(TR_OPEN); for (Column c : columnsInternal) { c.writeCell(w, group, context); } w.println(TR_CLOSE); } w.println(TABLE_CLOSE); writeFileEnd(w); }
From source file:com.b2international.snowowl.snomed.exporter.server.rf2.SnomedLanguageRefSetExporter.java
@Override protected Hits<SnomedRefSetMemberIndexEntry> filter(Hits<SnomedRefSetMemberIndexEntry> allResults) throws IOException { Multimap<String, SnomedRefSetMemberIndexEntry> referencedComponentToMemberMap = ArrayListMultimap.create(); allResults.getHits().forEach(m -> referencedComponentToMemberMap.put(m.getReferencedComponentId(), m)); Query<String> query = Query.select(String.class).from(SnomedDescriptionIndexEntry.class) .fields(SnomedDescriptionIndexEntry.Fields.ID) .where(Expressions.builder() .filter(SnomedDescriptionIndexEntry.Expressions .ids(referencedComponentToMemberMap.keySet())) .filter(SnomedDescriptionIndexEntry.Expressions.languageCode(languageCode)).build()) .limit(referencedComponentToMemberMap.keySet().size()).build(); List<String> descriptionIdsWithLanguageCode = getSearcher().search(query).getHits(); List<SnomedRefSetMemberIndexEntry> filteredMembers = descriptionIdsWithLanguageCode.stream() .flatMap(id -> referencedComponentToMemberMap.get(id).stream()).collect(toList()); return new Hits<SnomedRefSetMemberIndexEntry>(filteredMembers, null, null, allResults.getLimit(), allResults.getTotal());// w ww. j a va 2s. c o m }
From source file:org.eclipse.sirius.business.internal.session.SessionEventBrokerImpl.java
@Override public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException { CompoundCommand compoundCommand = new CompoundCommand(); Multimap<ModelChangeTrigger, Notification> listenersToNotify = collectListenersToNotify( event.getNotifications());/* w w w . ja va2 s .c o m*/ if (listenersToNotify != null && !listenersToNotify.isEmpty()) { Ordering<ModelChangeTrigger> priorityOrdering = Ordering.natural() .onResultOf(SessionEventBrokerImpl.getPriorityFunction); List<ModelChangeTrigger> sortedKeys = priorityOrdering.sortedCopy(listenersToNotify.keySet()); for (ModelChangeTrigger key : sortedKeys) { Collection<Notification> notif = listenersToNotify.get(key); if (notif != null && !notif.isEmpty()) { Option<Command> triggerCmdOption = key.localChangesAboutToCommit(notif); if (triggerCmdOption.some() && triggerCmdOption.get().canExecute()) { compoundCommand.append(triggerCmdOption.get()); } } } } return compoundCommand; }
From source file:io.nuun.kernel.core.internal.scanner.disk.ClasspathScannerDisk.java
@Override public void scanClasspathForSpecification(final Specification<Class<?>> specification, final Callback callback) { // Reflections reflections = new Reflections(configurationBuilder().addUrls(computeUrls()).setScanners(new TypesScanner())); queue(new ScannerCommand() { @Override// w w w . j a va 2 s . co m public void execute(Reflections reflections) { Store store = reflections.getStore(); Multimap<String, String> multimap = store.get(TypesScanner.class); Collection<String> collectionOfString = multimap.keySet(); Collection<Class<?>> types = null; Collection<Class<?>> filteredTypes = new HashSet<Class<?>>(); // Convert String to classes if (collectionOfString.size() > 0) { types = toClasses(collectionOfString); } else { types = Collections.emptySet(); } // Filter via specification for (Class<?> candidate : types) { if (specification.isSatisfiedBy(candidate)) { filteredTypes.add(candidate); } } callback.callback(postTreatment(filteredTypes)); } @Override public Scanner scanner() { return new TypesScanner(); } }); }
From source file:com.palantir.atlasdb.keyvalue.impl.ProfilingKeyValueService.java
@Override public void delete(String tableName, Multimap<Cell, Long> keys) { if (log.isTraceEnabled()) { Stopwatch stopwatch = Stopwatch.createStarted(); delegate.delete(tableName, keys); logCellsAndSize("delete", tableName, keys.keySet().size(), byteSize(keys), stopwatch); } else {/* ww w .j a v a 2 s . co m*/ delegate.delete(tableName, keys); } }
From source file:com.google.errorprone.bugpatterns.ModifyingCollectionWithItself.java
private List<Fix> buildValidReplacements(Multimap<Integer, JCVariableDecl> potentialReplacements, Function<JCVariableDecl, Fix> replacementFunction) { if (potentialReplacements.isEmpty()) { return ImmutableList.of(); }// w ww .j ava 2 s . c o m // Take all of the potential edit-distance replacements with the same minimum distance, // then suggest them as individual fixes. return FluentIterable.from(potentialReplacements.get(Collections.min(potentialReplacements.keySet()))) .transform(replacementFunction).toList(); }
From source file:org.voltcore.agreement.AgreementSeeker.java
protected String dumpGraph(Multimap<Long, Long> mm, StringBuilder sb) { sb.append("{ "); int count = 0; for (long h : mm.keySet()) { if (count++ > 0) sb.append(", "); sb.append(CoreUtils.hsIdToString(h)).append(": ["); sb.append(CoreUtils.hsIdCollectionToString(mm.get(h))); sb.append("]"); }/* w ww .j a v a2 s.c om*/ sb.append("}"); return sb.toString(); }
From source file:org.sonarlint.intellij.actions.SonarAnalyzeScopeAction.java
@Override public void actionPerformed(AnActionEvent e) { Project p = e.getProject();/*from ww w . ja v a 2 s .c o m*/ if (p == null) { return; } SonarLintConsole console = SonarLintConsole.get(p); IssueTreeScope scope = e.getData(IssueTreeScope.SCOPE_DATA_KEY); if (scope == null) { console.error("No scope found"); return; } Collection<VirtualFile> files = scope.getAll(); if (files.isEmpty()) { console.error("No files for analysis"); return; } Multimap<Module, VirtualFile> filesByModule = HashMultimap.create(); for (VirtualFile file : files) { Module m = ModuleUtil.findModuleForFile(file, p); if (!SonarLintUtils.shouldAnalyze(file, m)) { console.info("File '" + file + "' cannot be analyzed"); continue; } filesByModule.put(m, file); } if (!filesByModule.isEmpty()) { SonarLintJobManager analyzer = SonarLintUtils.get(p, SonarLintJobManager.class); for (Module m : filesByModule.keySet()) { if (executeBackground(e)) { analyzer.submitAsync(m, filesByModule.get(m), TriggerType.ACTION); } else { analyzer.submit(m, filesByModule.get(m), TriggerType.ACTION); } } } }
From source file:org.jboss.gwt.circuit.processor.StoreProcessor.java
private void validateDAG(final String graphVizFile) { boolean cyclesFound = false; for (Map.Entry<String, Multimap<String, String>> entry : dagValidation.entrySet()) { String actionType = entry.getKey(); Multimap<String, String> dependencies = entry.getValue(); debug("Check cyclic dependencies for action [%s]", actionType); DirectedGraph<String, DefaultEdge> dg = new DefaultDirectedGraph<>(DefaultEdge.class); // vertices for (String store : dependencies.keySet()) { dg.addVertex(store);//from w ww. jav a 2 s . com } for (String store : dependencies.values()) { dg.addVertex(store); } // edges for (String store : dependencies.keySet()) { Collection<String> storeDependencies = dependencies.get(store); for (String storeDependency : storeDependencies) { dg.addEdge(store, storeDependency); } } // cycles? CycleDetector<String, DefaultEdge> detector = new CycleDetector<>(dg); List<String> cycles = new LinkedList<>(detector.findCycles()); if (!cycles.isEmpty()) { cyclesFound = true; StringBuilder cycleInfo = new StringBuilder(); for (String cycle : cycles) { cycleInfo.append(cycle).append(" -> "); } cycleInfo.append(cycles.get(0)); error("Cyclic dependencies detected for action [%s]: %s. Please review [%s] for more details.", actionType, cycleInfo, graphVizFile); } if (!cyclesFound) { debug("No cyclic dependencies found for action [%s]", actionType); } } }
From source file:no.ssb.vtl.script.operations.join.AbstractJoinOperation.java
AbstractJoinOperation(Map<String, Dataset> namedDatasets, Set<Component> identifiers) { super(Lists.newArrayList(checkNotNull(namedDatasets).values())); checkArgument(!namedDatasets.isEmpty(), ERROR_EMPTY_DATASET_LIST); this.datasets = ImmutableMap.copyOf(checkNotNull(namedDatasets)); checkNotNull(identifiers);/*from ww w . ja va2 s.c o m*/ this.joinScope = createJoinScope(namedDatasets); this.componentMapping = createComponentMapping(this.datasets.values()); Map<Component, Map<Dataset, Component>> idMap = this.componentMapping.rowMap().entrySet().stream() .filter(e -> e.getKey().isIdentifier()).filter(e -> e.getValue().size() == datasets.size()) // identifiers can be from any dataset .filter(e -> identifiers.isEmpty() || !Collections.disjoint(e.getValue().values(), identifiers)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); // No common identifier checkArgument(namedDatasets.size() == 1 || !idMap.isEmpty(), ERROR_NO_COMMON_IDENTIFIERS, namedDatasets); this.commonIdentifiers = ImmutableSet.copyOf(idMap.keySet()); // Type mismatch check List<String> typeMismatches = Lists.newArrayList(); for (Map.Entry<Component, Map<Dataset, Component>> entry : idMap.entrySet()) { Component identifier = entry.getKey(); Multimap<Class<?>, Dataset> typeMap = ArrayListMultimap.create(); entry.getValue().entrySet().forEach(datasetComponent -> { typeMap.put(datasetComponent.getValue().getType(), datasetComponent.getKey()); }); if (typeMap.keySet().size() != 1) typeMismatches.add(String.format("%s -> (%s)", identifier, typeMap)); } checkArgument(typeMismatches.isEmpty(), ERROR_INCOMPATIBLE_TYPES, String.join(", ", typeMismatches)); }