List of usage examples for com.google.common.collect Multimap entries
Collection<Map.Entry<K, V>> entries();
From source file:org.summer.dsl.model.types.util.TypeArgumentContextProvider.java
protected Map<JvmTypeParameter, JvmTypeReference> normalizedCopy(Multimap<JvmTypeParameter, ResolveInfo> map) { if (map.isEmpty()) return Collections.emptyMap(); if (map.size() == 1) { Map.Entry<JvmTypeParameter, ResolveInfo> singleElement = Iterables.getOnlyElement(map.entries()); ResolveInfo singleResolveInfo = singleElement.getValue(); JvmTypeReference reference = wildcardAwareGetReference(singleResolveInfo); return Collections.singletonMap(singleElement.getKey(), reference); }// w w w .j a v a2s . c o m Map<JvmTypeParameter, JvmTypeReference> result = createMapWithTweakedToString(); for (JvmTypeParameter boundParameter : map.keySet()) { Collection<ResolveInfo> boundTo = map.get(boundParameter); if (boundTo.size() == 1) { ResolveInfo singleResolveInfo = Iterables.getOnlyElement(boundTo); JvmTypeReference reference = wildcardAwareGetReference(singleResolveInfo); result.put(boundParameter, reference); } else { List<ResolveInfo> boundToList = Lists.newArrayList(boundTo); List<JvmTypeReference> uppers = Lists.newArrayListWithCapacity(boundToList.size()); List<ResolveInfo> lowers = Lists.newArrayListWithCapacity(boundToList.size()); boolean done = false; int lowerIndex = Integer.MAX_VALUE; int upperIndex = Integer.MAX_VALUE; for (int i = 0; i < boundToList.size(); i++) { ResolveInfo info = boundToList.get(i); if (info.kind == ResolveInfoKind.EXACT) { result.put(boundParameter, info.reference); done = true; break; } else if (info.kind == ResolveInfoKind.UPPER || info.kind == ResolveInfoKind.WC_UPPER) { if (upperIndex == Integer.MAX_VALUE) upperIndex = i; if (!lowers.isEmpty() && upperIndex < lowerIndex) { boolean conformant = true; for (ResolveInfo lower : lowers) { if (!getConformanceComputer().isConformant(info.reference, lower.reference)) { conformant = false; break; } } if (conformant) { uppers.add(info.reference); } } else { uppers.add(info.reference); } } else if (info.kind == ResolveInfoKind.LOWER || info.kind == ResolveInfoKind.WC_LOWER) { if (lowerIndex == Integer.MAX_VALUE) lowerIndex = i; lowers.add(info); } } if (!done) { JvmTypeReference reference = null; if (!uppers.isEmpty() && upperIndex < lowerIndex) { reference = conformanceComputer.getCommonSuperType(uppers); if (uppers.size() == 1 && boundToList.get(upperIndex).kind == ResolveInfoKind.WC_UPPER) { boolean useWildcard = true; for (ResolveInfo lowerResolve : lowers) { if (!conformanceComputer.isConformant(lowerResolve.reference, reference)) { useWildcard = false; break; } } if (useWildcard) { if (reference.eContainer() != null) { JvmDelegateTypeReference delegate = typesFactory .createJvmDelegateTypeReference(); delegate.setDelegate(reference); reference = delegate; } JvmWildcardTypeReference wildCard = typeReferences.wildCard(); JvmUpperBound upperBound = typesFactory.createJvmUpperBound(); wildCard.getConstraints().add(upperBound); upperBound.setTypeReference(reference); reference = wildCard; } } } else if (!lowers.isEmpty()) { boolean lowerWithWildcard = false; ResolveInfo bestResolvedLower = null; for (ResolveInfo resolvedLower : lowers) { lowerWithWildcard |= resolvedLower.kind == ResolveInfoKind.WC_LOWER; if (bestResolvedLower == null) { bestResolvedLower = resolvedLower; } else { TypeConformanceResult conformanceResult = conformanceComputer.isConformant( bestResolvedLower.reference, resolvedLower.reference, new TypeConformanceComputationArgument(false, false, true)); if (conformanceResult.isConformant() && conformanceResult.getKinds() .contains(TypeConformanceResult.Kind.SUBTYPE)) bestResolvedLower = resolvedLower; } } if (bestResolvedLower != null) { if (lowers.size() == 1 || lowerWithWildcard) { if (bestResolvedLower.kind != ResolveInfoKind.WC_LOWER) { if (!uppers.isEmpty()) { JvmTypeReference upper = conformanceComputer.getCommonSuperType(uppers); if (conformanceComputer.isConformant(bestResolvedLower.reference, upper)) reference = upper; else reference = wildcardAwareGetReference(bestResolvedLower); } else { reference = wildcardAwareGetReference(bestResolvedLower); } } else { reference = wildcardAwareGetReference(bestResolvedLower); } } else { reference = bestResolvedLower.reference; if (!uppers.isEmpty()) { JvmTypeReference upper = conformanceComputer.getCommonSuperType(uppers); if (conformanceComputer.isConformant(reference, upper)) reference = upper; } } } } if (reference != null) result.put(boundParameter, reference); } } } Map<JvmTypeParameter, JvmTypeReference> normalizedCopy = normalizedCopy(result); return normalizedCopy; }
From source file:org.glowroot.central.repo.Tools.java
private Set<GaugeValuePartitionKey> getGaugeValuePartitionKeys(int rollupLevel, String thresholdComparator, Date threshold) throws Exception { ResultSet results = session/* w ww.ja v a 2 s. c o m*/ .read("select agent_rollup, gauge_name, capture_time from" + " gauge_value_rollup_" + rollupLevel); Multimap<String, String> gaugeNames = HashMultimap.create(); for (Row row : results) { int i = 0; String agentRollupId = checkNotNull(row.getString(i++)); String gaugeName = checkNotNull(row.getString(i++)); Date captureTime = checkNotNull(row.getTimestamp(i++)); if (thresholdComparator.equals("<")) { if (captureTime.getTime() < threshold.getTime()) { gaugeNames.put(agentRollupId, gaugeName); } } else if (thresholdComparator.equals(">")) { if (captureTime.getTime() > threshold.getTime()) { gaugeNames.put(agentRollupId, gaugeName); } } else { throw new IllegalStateException("Unexpected threshold comparator: " + thresholdComparator); } } Set<GaugeValuePartitionKey> partitionKeys = new HashSet<>(); for (Map.Entry<String, String> entry : gaugeNames.entries()) { partitionKeys.add(ImmutableGaugeValuePartitionKey.builder().agentRollupId(entry.getKey()) .gaugeName(entry.getValue()).build()); } return partitionKeys; }
From source file:com.palantir.atlasdb.keyvalue.partition.PartitionedKeyValueService.java
@Override @NonIdempotent// ww w . j a v a 2 s.c o m public void putWithTimestamps(final String tableName, final Multimap<Cell, Value> cellValues) throws KeyAlreadyExistsException { runWithPartitionMap(new Function<DynamicPartitionMap, Void>() { @Override public Void apply(final DynamicPartitionMap input) { final EndpointRequestCompletionService<Void> execSvc = EndpointRequestExecutor.newService(executor); final QuorumTracker<Void, Map.Entry<Cell, Value>> tracker = QuorumTracker.of(cellValues.entries(), input.getWriteEntriesParameters(cellValues)); input.runForCellsWrite(tableName, cellValues, new Function<Pair<KeyValueService, Multimap<Cell, Value>>, Void>() { @Override public Void apply(final Pair<KeyValueService, Multimap<Cell, Value>> e) { Future<Void> future = execSvc.submit(new Callable<Void>() { @Override public Void call() throws Exception { e.lhSide.putWithTimestamps(tableName, e.rhSide); return null; } }, e.lhSide); tracker.registerRef(future, e.rhSide.entries()); return null; } }); completeWriteRequest(tracker, execSvc); return null; } }); }
From source file:annis.administration.CorpusAdministration.java
public boolean copyFromOtherInstance(File dbProperties, boolean overwrite, String mail) { if (dbProperties.isFile() && dbProperties.canRead()) { // find the corpus paths List<Map<String, Object>> corpora = listCorpusStats(dbProperties); List<String> corpusPaths = new LinkedList<>(); for (Map<String, Object> c : corpora) { String sourcePath = (String) c.get("source_path"); if (sourcePath != null) { corpusPaths.add(sourcePath); }/* w ww . j ava 2s . c o m*/ } if (corpusPaths.isEmpty()) { log.warn("No corpora found"); return true; } else { log.info("The following corpora will be imported:\n" + "---------------\n" + "{}\n" + "---------------\n", Joiner.on("\n").join(corpusPaths)); sendCopyStatusMail(mail, dbProperties.getAbsolutePath(), ImportJob.Status.RUNNING, "The following corpora will be imported:\n" + "---------------\n" + Joiner.on("\n").join(corpusPaths) + "\n" + "---------------\n"); // remember the corpus alias table Multimap<String, String> corpusAlias = administrationDao.listCorpusAlias(dbProperties); //import each corpus ImportStatus status = importCorporaSave(overwrite, null, null, false, corpusPaths); // report the successful or failure failed Set<String> successfullCorpora = new LinkedHashSet<>(corpusPaths); Set<String> failedCorpora = new LinkedHashSet<>(status.getAllThrowable().keySet()); successfullCorpora.removeAll(failedCorpora); log.info("copying corpus aliases"); for (Map.Entry<String, String> e : corpusAlias.entries()) { administrationDao.addCorpusAlias(e.getValue(), e.getKey()); } if (failedCorpora.isEmpty()) { log.info("All corpora imported without errors:\n" + "---------------\n" + "{}\n" + "---------------\n", Joiner.on("\n").join(successfullCorpora)); sendCopyStatusMail(mail, dbProperties.getAbsolutePath(), ImportJob.Status.SUCCESS, "All corpora imported without errors:\n" + "---------------\n" + Joiner.on("\n").join(corpusPaths) + "\n" + "---------------\n"); return true; } else { log.error( "Errors occured during import, not all corpora have been imported.\n" + "---------------\n" + "Success:\n" + "{}\n" + "---------------\n" + "Failed:\n" + "{}\n" + "---------------\n", Joiner.on("\n").join(successfullCorpora), Joiner.on("\n").join(failedCorpora)); sendCopyStatusMail(mail, dbProperties.getAbsolutePath(), ImportJob.Status.ERROR, "Errors occured during import, not all corpora have been imported.\n" + "---------------\n" + "Success:\n" + Joiner.on("\n").join(successfullCorpora) + "\n" + "---------------\n" + "Failed:\n" + Joiner.on("\n").join(failedCorpora) + "\n" + "---------------\n"); } } } else { log.error("Can not read the database configuration file {}", dbProperties.getAbsolutePath()); } return false; }
From source file:org.glowroot.central.repo.Tools.java
private Set<TtPartitionKey> getPartitionKeys(int rollupLevel, String thresholdComparator, Date threshold) throws Exception { ResultSet results = session.read("select agent_rollup, transaction_type, capture_time" + " from aggregate_tt_summary_rollup_" + rollupLevel); Multimap<String, String> transactionTypes = HashMultimap.create(); for (Row row : results) { int i = 0; String agentRollupId = checkNotNull(row.getString(i++)); String transactionType = checkNotNull(row.getString(i++)); Date captureTime = checkNotNull(row.getTimestamp(i++)); if (thresholdComparator.equals("<")) { if (captureTime.getTime() < threshold.getTime()) { transactionTypes.put(agentRollupId, transactionType); }/*from w w w. j a v a 2 s. c om*/ } else if (thresholdComparator.equals(">")) { if (captureTime.getTime() > threshold.getTime()) { transactionTypes.put(agentRollupId, transactionType); } } else { throw new IllegalStateException("Unexpected threshold comparator: " + thresholdComparator); } } Set<TtPartitionKey> ttPartitionKeys = new HashSet<>(); for (Map.Entry<String, String> entry : transactionTypes.entries()) { ttPartitionKeys.add(ImmutableTtPartitionKey.builder().agentRollupId(entry.getKey()) .transactionType(entry.getValue()).build()); } return ttPartitionKeys; }
From source file:com.b2international.snowowl.snomed.datastore.request.rf2.SnomedRf2ExportRequest.java
private void exportIndividualRefSets(final Path releaseDirectory, final RepositoryContext context, final String revisionRange, final String archiveEffectiveTime, final long effectiveTimeFilterStart, final long effectiveTimeFilterEnd, final Collection<String> languageCodes, final Set<String> visitedComponentEffectiveTimes) throws IOException { final Multimap<SnomedRefSetType, SnomedConcept> referenceSetsByType = FluentIterable .from(getIdentifierConcepts(context, getBranchOrRangeTarget(revisionRange))) .index(c -> c.getReferenceSet().getType()); /* //from w w w . java 2s . co m * Create single exporter instance for each reference set type - reference set concept * pair (so effectively one for each reference set) */ for (final Entry<SnomedRefSetType, SnomedConcept> entry : referenceSetsByType.entries()) { // We will handle language reference sets separately if (SnomedRefSetType.LANGUAGE.equals(entry.getKey())) { continue; } final Rf2RefSetExporter refSetExporter = new Rf2RefSetExporter(releaseType, countryNamespaceElement, namespaceFilter, transientEffectiveTime, archiveEffectiveTime, includePreReleaseContent, modules, refSetExportLayout, entry.getKey(), ImmutableSet.of(entry.getValue())); refSetExporter.exportBranch(releaseDirectory, context, revisionRange, effectiveTimeFilterStart, effectiveTimeFilterEnd, visitedComponentEffectiveTimes); } exportLanguageRefSets(releaseDirectory, context, revisionRange, archiveEffectiveTime, effectiveTimeFilterStart, effectiveTimeFilterEnd, languageCodes, referenceSetsByType.get(SnomedRefSetType.LANGUAGE), visitedComponentEffectiveTimes); }
From source file:com.palantir.atlasdb.keyvalue.partition.map.DynamicPartitionMapImpl.java
private <ValType> Map<KeyValueEndpoint, Multimap<Cell, ValType>> getServicesForCellsMultimap(String tableName, Multimap<Cell, ValType> cellMultimap, boolean isWrite) { Map<KeyValueEndpoint, Multimap<Cell, ValType>> result = Maps.newHashMap(); for (Map.Entry<Cell, ValType> e : cellMultimap.entries()) { Set<KeyValueEndpoint> services = getServicesHavingRow(e.getKey().getRowName(), isWrite); for (KeyValueEndpoint kvs : services) { if (!result.containsKey(kvs)) { result.put(kvs, HashMultimap.<Cell, ValType>create()); }/* ww w . j a va2 s . c om*/ assert !result.get(kvs).containsEntry(e.getKey(), e.getValue()); result.get(kvs).put(e.getKey(), e.getValue()); } } if (!cellMultimap.isEmpty()) { assert result.keySet().size() >= quorumParameters.getReplicationFactor(); } return result; }
From source file:com.marvinformatics.sonarpullrequestintegration.mojo.SonarPullRequestMojo.java
private void recordGit(Multimap<String, Issue> fileViolations) throws IOException { GitHubClient client = new GitHubClient().setOAuth2Token(oauth2); RepositoryService rs = new RepositoryService(client); Repository repository = rs.getRepository(repositoryOwner, repositoryName); PullRequestService pullRequestService = new PullRequestService(client); Iterator<RepositoryCommit> commits = pullRequestService.getCommits(repository, pullRequestId).iterator(); if (!commits.hasNext()) return;//from w w w. j av a 2s . co m RepositoryCommit lastCommit = commits.next(); List<CommitFile> files = pullRequestService.getFiles(repository, pullRequestId); Multimap<String, Issue> relatedFileViolations = LinkedHashMultimap.create(); Map<String, LinePositioner> linePositioners = Maps.newLinkedHashMap(); for (CommitFile commitFile : files) { Set<String> keys = fileViolations.keySet(); for (String key : keys) { if (commitFile.getFilename().contains(key)) { relatedFileViolations.putAll(commitFile.getFilename(), fileViolations.get(key)); linePositioners.put(commitFile.getFilename(), new LinePositioner(commitFile.getPatch())); } } } List<CommitComment> currentComments = pullRequestService.getComments(repository, pullRequestId); for (CommitComment comment : currentComments) { Iterator<Issue> issues = relatedFileViolations.get(comment.getPath()).iterator(); while (issues.hasNext()) { Issue issue = (Issue) issues.next(); int position = linePositioners.get(comment.getPath()).toPostion(issue.line()); if (position == comment.getPosition() && issue.message().equals(comment.getBody())) issues.remove(); } } Collection<Entry<String, Issue>> entries = relatedFileViolations.entries(); for (Entry<String, Issue> entry : entries) { CommitComment comment = new CommitComment(); comment.setBody(entry.getValue().message()); comment.setCommitId(lastCommit.getSha()); comment.setPath(entry.getKey()); int line = entry.getValue().line(); comment.setLine(line); comment.setPosition(linePositioners.get(entry.getKey()).toPostion(line)); pullRequestService.createComment(repository, pullRequestId, comment); } }
From source file:com.palantir.atlasdb.keyvalue.partition.map.DynamicPartitionMapImpl.java
@Override public <T> Map<Entry<Cell, T>, QuorumRequestParameters> getReadEntriesParameters(Multimap<Cell, T> entries) { Map<Entry<Cell, T>, QuorumRequestParameters> result = Maps.newHashMap(); Map<byte[], QuorumRequestParameters> rowsResult = getReadRowsParameters(getRows(entries.keySet())); for (Entry<Cell, T> e : entries.entries()) { result.put(e, rowsResult.get(e.getKey().getRowName())); }// ww w .j av a 2 s.co m return result; }
From source file:com.palantir.atlasdb.keyvalue.partition.map.DynamicPartitionMapImpl.java
@Override public <T> Map<Entry<Cell, T>, QuorumRequestParameters> getWriteEntriesParameters(Multimap<Cell, T> entries) { Map<Entry<Cell, T>, QuorumRequestParameters> result = Maps.newHashMap(); Map<byte[], QuorumRequestParameters> rowsResult = getWriteRowsParameters(getRows(entries.keySet())); for (Entry<Cell, T> e : entries.entries()) { result.put(e, rowsResult.get(e.getKey().getRowName())); }/*from w w w . ja va 2s. co m*/ return result; }