List of usage examples for com.google.common.collect ImmutableListMultimap get
@Override
public ImmutableList<V> get(@Nullable K key)
From source file:com.b2international.snowowl.snomed.exporter.server.dsv.SnomedSimpleTypeRefSetDSVExporter.java
private SnomedRelationships mapToSourceConcepts(SnomedRelationships relationships, SnomedConcepts concepts) { ImmutableListMultimap<String, SnomedRelationship> relationshipsBySourceId = Multimaps .index(relationships.getItems(), (relationship) -> relationship.getSourceId()); concepts.forEach(concept -> {//from w w w.ja va2s . c o m List<SnomedRelationship> collection = relationshipsBySourceId.get(concept.getId()); concept.setRelationships( new SnomedRelationships(collection, null, null, collection.size(), collection.size())); }); return relationships; }
From source file:com.b2international.snowowl.snomed.exporter.server.dsv.SnomedSimpleTypeRefSetDSVExporter.java
private SnomedDescriptions mapToConcepts(SnomedConcepts concepts, SnomedDescriptions resultDescriptions) { ImmutableListMultimap<String, SnomedDescription> descriptionsByOwnerConceptId = Multimaps .index(resultDescriptions.getItems(), description -> description.getConceptId()); concepts.forEach(concept -> {/* ww w. ja v a 2 s . c o m*/ List<SnomedDescription> descriptions = descriptionsByOwnerConceptId.get(concept.getId()); concept.setDescriptions( new SnomedDescriptions(descriptions, null, null, descriptions.size(), descriptions.size())); }); return resultDescriptions; }
From source file:com.google.devtools.build.lib.rules.objc.MultiArchBinarySupport.java
/** * Registers actions to create a multi-arch Apple binary. * * @param platform the platform for which the binary is targeted * @param extraLinkArgs the extra linker args to add to link actions linking single-architecture * binaries together/*from w w w . j a va2s . c om*/ * @param configurationToObjcProvider a map from from dependency configuration to the * {@link ObjcProvider} which comprises all information about the dependencies in that * configuration. Can be obtained via {@link #objcProviderByDepConfiguration} * @param extraLinkInputs the extra linker inputs to be made available during link actions * @param configToDepsCollectionMap a multimap from dependency configuration to the * list of provider collections which are propagated from the dependencies of that * configuration * @param outputLipoBinary the artifact (lipo'ed binary) which should be output as a result of * this support * @throws RuleErrorException if there are attribute errors in the current rule context */ public void registerActions(Platform platform, ExtraLinkArgs extraLinkArgs, Map<BuildConfiguration, ObjcProvider> configurationToObjcProvider, Iterable<Artifact> extraLinkInputs, ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap, Artifact outputLipoBinary) throws RuleErrorException, InterruptedException { NestedSetBuilder<Artifact> binariesToLipo = NestedSetBuilder.<Artifact>stableOrder(); for (BuildConfiguration childConfig : configurationToObjcProvider.keySet()) { IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig); ImmutableList.Builder<J2ObjcMappingFileProvider> j2ObjcMappingFileProviders = ImmutableList.builder(); J2ObjcEntryClassProvider.Builder j2ObjcEntryClassProviderBuilder = new J2ObjcEntryClassProvider.Builder(); for (TransitiveInfoCollection dep : configToDepsCollectionMap.get(childConfig)) { if (dep.getProvider(J2ObjcMappingFileProvider.class) != null) { j2ObjcMappingFileProviders.add(dep.getProvider(J2ObjcMappingFileProvider.class)); } if (dep.getProvider(J2ObjcEntryClassProvider.class) != null) { j2ObjcEntryClassProviderBuilder.addTransitive(dep.getProvider(J2ObjcEntryClassProvider.class)); } } J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider .union(j2ObjcMappingFileProviders.build()); J2ObjcEntryClassProvider j2ObjcEntryClassProvider = j2ObjcEntryClassProviderBuilder.build(); binariesToLipo.add(intermediateArtifacts.strippedSingleArchitectureBinary()); ObjcProvider objcProvider = configurationToObjcProvider.get(childConfig); CompilationArtifacts compilationArtifacts = CompilationSupport.compilationArtifacts(ruleContext, ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig)); CompilationSupport.createForConfig(ruleContext, childConfig) .registerCompileAndArchiveActions(compilationArtifacts, objcProvider) .registerLinkActions(objcProvider, j2ObjcMappingFileProvider, j2ObjcEntryClassProvider, extraLinkArgs, extraLinkInputs, DsymOutputType.APP) .validateAttributes(); ruleContext.assertNoErrors(); } new LipoSupport(ruleContext).registerCombineArchitecturesAction(binariesToLipo.build(), outputLipoBinary, platform); }
From source file:org.apache.hadoop.hdfs.server.namenode.JournalSet.java
/** * Return a manifest of what finalized edit logs are available. All available * edit logs are returned starting from the transaction id passed. If * 'fromTxId' falls in the middle of a log, that log is returned as well. * /*from ww w . ja va2 s .c o m*/ * @param fromTxId Starting transaction id to read the logs. * @return RemoteEditLogManifest object. */ public synchronized RemoteEditLogManifest getEditLogManifest(long fromTxId) { // Collect RemoteEditLogs available from each FileJournalManager List<RemoteEditLog> allLogs = Lists.newArrayList(); for (JournalAndStream j : journals) { if (j.getManager() instanceof FileJournalManager) { FileJournalManager fjm = (FileJournalManager) j.getManager(); try { allLogs.addAll(fjm.getRemoteEditLogs(fromTxId, false)); } catch (Throwable t) { LOG.warn("Cannot list edit logs in " + fjm, t); } } } // Group logs by their starting txid ImmutableListMultimap<Long, RemoteEditLog> logsByStartTxId = Multimaps.index(allLogs, RemoteEditLog.GET_START_TXID); long curStartTxId = fromTxId; List<RemoteEditLog> logs = Lists.newArrayList(); while (true) { ImmutableList<RemoteEditLog> logGroup = logsByStartTxId.get(curStartTxId); if (logGroup.isEmpty()) { // we have a gap in logs - for example because we recovered some old // storage directory with ancient logs. Clear out any logs we've // accumulated so far, and then skip to the next segment of logs // after the gap. SortedSet<Long> startTxIds = Sets.newTreeSet(logsByStartTxId.keySet()); startTxIds = startTxIds.tailSet(curStartTxId); if (startTxIds.isEmpty()) { break; } else { if (LOG.isDebugEnabled()) { LOG.debug("Found gap in logs at " + curStartTxId + ": " + "not returning previous logs in manifest."); } logs.clear(); curStartTxId = startTxIds.first(); continue; } } // Find the one that extends the farthest forward RemoteEditLog bestLog = Collections.max(logGroup); logs.add(bestLog); // And then start looking from after that point curStartTxId = bestLog.getEndTxId() + 1; } RemoteEditLogManifest ret = new RemoteEditLogManifest(logs); if (LOG.isDebugEnabled()) { LOG.debug("Generated manifest for logs since " + fromTxId + ":" + ret); } return ret; }
From source file:org.obiba.opal.web.gwt.app.client.magma.view.SummaryTabView.java
private void renderTextSummary(SummaryStatisticsDto dto) { TextSummaryDto textSummaryDto = dto.getExtension(TextSummaryDto.SummaryStatisticsDtoExtensions.textSummary) .cast();// w w w . j a va 2s .c o m final double[] totals = { 0d, 0d }; ImmutableListMultimap<Boolean, FrequencyDto> valuesByMissing = Multimaps.index( JsArrays.toIterable(textSummaryDto.getFrequenciesArray()), new Function<FrequencyDto, Boolean>() { @Nullable @Override public Boolean apply(@Nullable FrequencyDto input) { if (input != null && !input.getMissing()) { totals[0] += input.getFreq(); return false; } totals[1] += input == null ? 0 : input.getFreq(); return true; } }); summary.add(new TextSummaryView(textSummaryDto, valuesByMissing.get(false), valuesByMissing.get(true), totals[0], totals[1], textSummaryDto.getOtherFrequency(), DEFAULT_MAX_TEXT_RESULTS)); }
From source file:org.apache.hadoop.hive.ql.stats.BasicStatsNoJobTask.java
private int updatePartitions(Hive db, List<FooterStatCollector> scs, Table table) throws InvalidOperationException, HiveException { String tableFullName = table.getFullyQualifiedName(); if (scs.isEmpty()) { return 0; }/*from ww w .ja va2 s. c om*/ if (work.isStatsReliable()) { for (FooterStatCollector statsCollection : scs) { if (statsCollection.result == null) { LOG.debug("Stats requested to be reliable. Empty stats found: {}", statsCollection.partish.getSimpleName()); return -1; } } } List<FooterStatCollector> validColectors = Lists.newArrayList(); for (FooterStatCollector statsCollection : scs) { if (statsCollection.isValid()) { validColectors.add(statsCollection); } } EnvironmentContext environmentContext = new EnvironmentContext(); environmentContext.putToProperties(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE); ImmutableListMultimap<String, FooterStatCollector> collectorsByTable = Multimaps.index(validColectors, FooterStatCollector.SIMPLE_NAME_FUNCTION); LOG.debug("Collectors.size(): {}", collectorsByTable.keySet()); if (collectorsByTable.keySet().size() < 1) { LOG.warn("Collectors are empty! ; {}", tableFullName); } // for now this should be true... assert (collectorsByTable.keySet().size() <= 1); LOG.debug("Updating stats for: {}", tableFullName); for (String partName : collectorsByTable.keySet()) { ImmutableList<FooterStatCollector> values = collectorsByTable.get(partName); if (values == null) { throw new RuntimeException("very intresting"); } if (values.get(0).result instanceof Table) { db.alterTable(tableFullName, (Table) values.get(0).result, environmentContext, true); LOG.debug("Updated stats for {}.", tableFullName); } else { if (values.get(0).result instanceof Partition) { List<Partition> results = Lists.transform(values, FooterStatCollector.EXTRACT_RESULT_FUNCTION); db.alterPartitions(tableFullName, results, environmentContext, true); LOG.debug("Bulk updated {} partitions of {}.", results.size(), tableFullName); } else { throw new RuntimeException("inconsistent"); } } } LOG.debug("Updated stats for: {}", tableFullName); return 0; }
From source file:org.carrot2.text.clustering.MultilingualClustering.java
/** * Clusters documents in each language separately. */// w ww .j a v a 2s .c o m private Map<LanguageCode, Cluster> clusterByLanguage(List<Document> documents, IMonolingualClusteringAlgorithm algorithm) { // Partition by language first. As Multimaps.index() does not handle null // keys, we'd need to index by LanguageCode string and have a dedicated empty // string for the null language. final ImmutableListMultimap<String, Document> documentsByLanguage = Multimaps.index(documents, new Function<Document, String>() { public String apply(Document document) { final LanguageCode language = document.getLanguage(); return language != null ? language.name() : ""; } }); // For each language, perform clustering. Please note that implementations of // IMonolingualClusteringAlgorithm.cluster() are not guaranteed to be thread-safe // and hence the method must NOT be called concurrently. final Map<LanguageCode, Cluster> clusters = Maps.newHashMap(); for (String language : documentsByLanguage.keySet()) { final ImmutableList<Document> languageDocuments = documentsByLanguage.get(language); final LanguageCode languageCode = language.equals("") ? null : LanguageCode.valueOf(language); final Cluster languageCluster = new Cluster( languageCode != null ? languageCode.toString() : "Unknown Language"); languageCounts.put(languageCode != null ? languageCode.getIsoCode() : "", languageDocuments.size()); // Perform clustering final LanguageCode currentLanguage = languageCode != null ? languageCode : defaultLanguage; logger.debug("Performing monolingual clustering in: " + currentLanguage); final List<Cluster> clustersForLanguage = algorithm.process(languageDocuments, currentLanguage); if (clustersForLanguage.size() == 0 || clustersForLanguage.size() == 1 && clustersForLanguage.get(0).isOtherTopics()) { languageCluster.addDocuments(languageDocuments); } else { languageCluster.addSubclusters(clustersForLanguage); } clusters.put(languageCode, languageCluster); } return clusters; }
From source file:org.obiba.opal.web.gwt.app.client.magma.view.SummaryTabView.java
private void renderContinuousSummary(SummaryStatisticsDto dto) { ContinuousSummaryDto continuous = dto .getExtension(ContinuousSummaryDto.SummaryStatisticsDtoExtensions.continuous).cast(); final double[] totals = { 0d, 0d }; ImmutableListMultimap<Boolean, FrequencyDto> frequenciesByMissing = Multimaps.index( JsArrays.toIterable(continuous.getFrequenciesArray()), new Function<FrequencyDto, Boolean>() { @Nullable// ww w . j a v a 2s. c o m @Override public Boolean apply(@Nullable FrequencyDto input) { // when boolean, is missing is not set if (input != null && !input.getMissing()) { totals[0] += input.getFreq(); return false; } totals[1] += input == null ? 0 : input.getFreq(); return true; } }); summary.add(new ContinuousSummaryView(continuous, frequenciesByMissing.get(false), frequenciesByMissing.get(true), totals[0], totals[1])); }
From source file:org.obiba.opal.web.gwt.app.client.magma.view.SummaryTabView.java
private void renderGeoSummary(SummaryStatisticsDto dto) { GeoSummaryDto geoSummaryDto = dto.getExtension(GeoSummaryDto.SummaryStatisticsDtoExtensions.geoSummary) .cast();/* w w w . jav a 2s .c o m*/ final double[] totals = { 0d, 0d }; ImmutableListMultimap<Boolean, FrequencyDto> valuesByMissing = Multimaps.index( JsArrays.toIterable(geoSummaryDto.getFrequenciesArray()), new Function<FrequencyDto, Boolean>() { @Nullable @Override public Boolean apply(@Nullable FrequencyDto input) { if (input != null && !input.getMissing()) { input.setValue(translations.notEmpty()); totals[0] += input.getFreq(); return false; } totals[1] += input == null ? 0 : input.getFreq(); return true; } }); summary.add(new GeoSummaryView(geoSummaryDto, valuesByMissing.get(false), valuesByMissing.get(true), totals[0], totals[1])); }
From source file:org.ow2.authzforce.core.pdp.impl.ModularAttributeProvider.java
protected ModularAttributeProvider( final ImmutableListMultimap<AttributeFqn, NamedAttributeProvider> attributeProviderModulesByAttributeId, final Set<AttributeDesignatorType> selectedAttributeSupport, final boolean strictAttributeIssuerMatch) { assert attributeProviderModulesByAttributeId != null; if (selectedAttributeSupport == null) { designatorModsByAttrId = attributeProviderModulesByAttributeId; } else {/*www. ja v a2 s. c o m*/ final ListMultimap<AttributeFqn, NamedAttributeProvider> mutableModsByAttrIdMap = ArrayListMultimap .create(selectedAttributeSupport.size(), 1); for (final AttributeDesignatorType requiredAttr : selectedAttributeSupport) { final AttributeFqn requiredAttrGUID = AttributeFqns.newInstance(requiredAttr); final ImmutableList<NamedAttributeProvider> requiredAttrProviderMods = attributeProviderModulesByAttributeId .get(requiredAttrGUID); /* * According to doc, a non-null empty list is returned if no mappings */ assert requiredAttrProviderMods != null; /* * Empty requiredAttrProviderMod means it should be provided by the request context (in the initial request from PEP) */ if (!requiredAttrProviderMods.isEmpty()) { mutableModsByAttrIdMap.putAll(requiredAttrGUID, requiredAttrProviderMods); } } designatorModsByAttrId = ImmutableListMultimap.copyOf(mutableModsByAttrIdMap); } this.issuedToNonIssuedAttributeCopyMode = strictAttributeIssuerMatch ? ISSUED_TO_NON_ISSUED_ATTRIBUTE_COPY_DISABLED_MODE : ISSUED_TO_NON_ISSUED_ATTRIBUTE_COPY_ENABLED_MODE; }