List of usage examples for com.google.common.collect ImmutableSetMultimap copyOf
@Beta public static <K, V> ImmutableSetMultimap<K, V> copyOf( Iterable<? extends Entry<? extends K, ? extends V>> entries)
From source file:com.opengamma.strata.pricer.calibration.ImmutableRatesProviderGenerator.java
/** * Creates an instance.//from ww w. j a v a2 s. c o m * * @param knownProvider the underlying known provider * @param curveDefinitions the curve definitions * @param discountCurveNames the map of discount curves * @param forwardCurveNames the map of index forward curves */ private ImmutableRatesProviderGenerator(ImmutableRatesProvider knownProvider, List<NodalCurveDefinition> curveDefinitions, SetMultimap<CurveName, Currency> discountCurveNames, SetMultimap<CurveName, Index> forwardCurveNames) { this.knownProvider = ArgChecker.notNull(knownProvider, "knownProvider"); this.curveDefinitions = ImmutableList.copyOf(ArgChecker.notNull(curveDefinitions, "curveDefinitions")); this.discountCurveNames = ImmutableSetMultimap .copyOf(ArgChecker.notNull(discountCurveNames, "discountCurveNames")); this.forwardCurveNames = ImmutableSetMultimap .copyOf(ArgChecker.notNull(forwardCurveNames, "forwardCurveNames")); }
From source file:org.opendaylight.yangtools.yang.model.util.FilteringSchemaContextProxy.java
/** * Filters SchemaContext for yang modules * * @param delegate original SchemaContext * @param rootModules modules (yang schemas) to be available and all their dependencies (modules importing rootModule and whole chain of their imports) * @param additionalModuleIds (additional) modules (yang schemas) to be available and whole chain of their imports * *///from ww w. j av a 2 s . c o m public FilteringSchemaContextProxy(final SchemaContext delegate, final Collection<ModuleId> rootModules, final Set<ModuleId> additionalModuleIds) { Preconditions.checkArgument(rootModules != null, "Base modules cannot be null."); Preconditions.checkArgument(additionalModuleIds != null, "Additional modules cannot be null."); final Builder<Module> filteredModulesBuilder = new Builder<>(); final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); ImmutableMap.Builder<ModuleIdentifier, String> identifiersToSourcesBuilder = ImmutableMap.builder(); //preparing map to get all modules with one name but difference in revision final TreeMultimap<String, Module> nameToModulesAll = getStringModuleTreeMultimap(); nameToModulesAll.putAll(getStringModuleMap(delegate)); //in case there is a particular dependancy to view filteredModules/yang models //dependancy is checked for module name and imports processForRootModules(delegate, rootModules, filteredModulesBuilder); //adding additional modules processForAdditionalModules(delegate, additionalModuleIds, filteredModulesBuilder); filteredModulesBuilder.addAll( getImportedModules(Maps.uniqueIndex(delegate.getModules(), ModuleId.MODULE_TO_MODULE_ID::apply), filteredModulesBuilder.build(), nameToModulesAll)); /** * Instead of doing this on each invocation of getModules(), pre-compute * it once and keep it around -- better than the set we got in. */ this.filteredModules = filteredModulesBuilder.build(); for (final Module module : filteredModules) { nameMap.put(module.getName(), module); nsMap.put(module.getNamespace(), module); identifiersToSourcesBuilder.put(module, module.getSource()); } namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); nameToModules = ImmutableSetMultimap.copyOf(nameMap); identifiersToSources = identifiersToSourcesBuilder.build(); }
From source file:org.ambraproject.wombat.freemarker.ReplaceParametersDirective.java
@VisibleForTesting static Multimap<String, String> replaceParameters(SimpleHash parameterMap, Multimap<String, TemplateModel> replacements) throws TemplateException { Multimap<String, String> result = HashMultimap.create(); // The map is passed in as a Map<String, String[]>, but Freemarker doesn't support generics // (and wraps the map in its own data structure). Map map = parameterMap.toMap(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); String[] values = (String[]) entry.getValue(); for (String value : values) { result.put((String) entry.getKey(), value); }/*from w w w. j av a 2 s .c o m*/ } for (Map.Entry<String, Collection<TemplateModel>> replacementEntry : replacements.asMap().entrySet()) { Collection<String> replacementValues = Collections2.transform(replacementEntry.getValue(), Object::toString); result.replaceValues(replacementEntry.getKey(), replacementValues); } return ImmutableSetMultimap.copyOf(result); }
From source file:org.onos.yangtools.yang.model.util.FilteringSchemaContextProxy.java
/** * Filters SchemaContext for yang modules * * @param delegate original SchemaContext * @param rootModules modules (yang schemas) to be available and all their dependencies (modules importing rootModule and whole chain of their imports) * @param additionalModuleIds (additional) modules (yang schemas) to be available and whole chain of their imports * *//*from ww w.ja v a 2 s .c o m*/ public FilteringSchemaContextProxy(final SchemaContext delegate, final Collection<ModuleId> rootModules, final Set<ModuleId> additionalModuleIds) { Preconditions.checkArgument(rootModules != null, "Base modules cannot be null."); Preconditions.checkArgument(additionalModuleIds != null, "Additional modules cannot be null."); final Builder<Module> filteredModulesBuilder = new Builder<>(); final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<URI, Collection<Module>>(), MODULE_SET_SUPPLIER); final SetMultimap<String, Module> nameMap = Multimaps .newSetMultimap(new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER); ImmutableMap.Builder<ModuleIdentifier, String> identifiersToSourcesBuilder = ImmutableMap.builder(); //preparing map to get all modules with one name but difference in revision final TreeMultimap<String, Module> nameToModulesAll = getStringModuleTreeMultimap(); nameToModulesAll.putAll(getStringModuleMap(delegate)); //in case there is a particular dependancy to view filteredModules/yang models //dependancy is checked for module name and imports processForRootModules(delegate, rootModules, filteredModulesBuilder); //adding additional modules processForAdditionalModules(delegate, additionalModuleIds, filteredModulesBuilder); filteredModulesBuilder .addAll(getImportedModules(Maps.uniqueIndex(delegate.getModules(), ModuleId.MODULE_TO_MODULE_ID), filteredModulesBuilder.build(), nameToModulesAll)); /** * Instead of doing this on each invocation of getModules(), pre-compute * it once and keep it around -- better than the set we got in. */ this.filteredModules = filteredModulesBuilder.build(); for (final Module module : filteredModules) { nameMap.put(module.getName(), module); nsMap.put(module.getNamespace(), module); identifiersToSourcesBuilder.put(module, module.getSource()); } namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); nameToModules = ImmutableSetMultimap.copyOf(nameMap); identifiersToSources = identifiersToSourcesBuilder.build(); }
From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext.java
public EffectiveSchemaContext(final Set<Module> modules) { /*//from ww w . j a va 2s.c o m * Instead of doing this on each invocation of getModules(), pre-compute * it once and keep it around -- better than the set we got in. */ this.modules = ImmutableSet.copyOf(ModuleDependencySort.sort(modules.toArray(new Module[modules.size()]))); /* * The most common lookup is from Namespace->Module. * * RESTCONF performs lookups based on module name only, where it wants * to receive the latest revision * * Invest some quality time in building up lookup tables for both. */ final SetMultimap<URI, Module> nsMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); final SetMultimap<String, Module> nameMap = Multimaps.newSetMultimap(new TreeMap<>(), MODULE_SET_SUPPLIER); Set<ModuleIdentifier> modIdBuilder = new HashSet<>(); for (Module m : modules) { nameMap.put(m.getName(), m); nsMap.put(m.getNamespace(), m); modIdBuilder.add(ModuleIdentifierImpl.create(m.getName(), Optional.of(m.getNamespace()), Optional.of(m.getRevision()))); resolveSubmoduleIdentifiers(m.getSubmodules(), modIdBuilder); } namespaceToModules = ImmutableSetMultimap.copyOf(nsMap); nameToModules = ImmutableSetMultimap.copyOf(nameMap); moduleIdentifiers = ImmutableSet.copyOf(modIdBuilder); rootDeclaredStatements = ImmutableList.of(); rootEffectiveStatements = ImmutableList.of(); }
From source file:com.opengamma.strata.pricer.curve.ImmutableRatesProviderGenerator.java
/** * Creates an instance./* ww w .j ava 2 s .c o m*/ * * @param knownProvider the underlying known provider * @param curveDefinitions the curve definitions * @param curveMetadata the curve metadata * @param discountCurveNames the map of discount curves * @param forwardCurveNames the map of index forward curves */ private ImmutableRatesProviderGenerator(ImmutableRatesProvider knownProvider, List<NodalCurveDefinition> curveDefinitions, List<CurveMetadata> curveMetadata, SetMultimap<CurveName, Currency> discountCurveNames, SetMultimap<CurveName, Index> forwardCurveNames) { this.knownProvider = ArgChecker.notNull(knownProvider, "knownProvider"); this.curveDefinitions = ImmutableList.copyOf(ArgChecker.notNull(curveDefinitions, "curveDefinitions")); this.curveMetadata = ImmutableList.copyOf(ArgChecker.notNull(curveMetadata, "curveMetadata")); this.discountCurveNames = ImmutableSetMultimap .copyOf(ArgChecker.notNull(discountCurveNames, "discountCurveNames")); this.forwardCurveNames = ImmutableSetMultimap .copyOf(ArgChecker.notNull(forwardCurveNames, "forwardCurveNames")); }
From source file:org.lightjason.agentspeak.language.CLiteral.java
/** * ctor// w ww .j a va2 s .c o m * * @param p_at @ prefix is set * @param p_negated negated flag * @param p_functor functor of the literal * @param p_values initial list of values * @param p_annotations initial set of annotations */ public CLiteral(final boolean p_at, final boolean p_negated, final IPath p_functor, final Collection<ITerm> p_values, final Collection<ILiteral> p_annotations) { m_at = p_at; m_negated = p_negated; // create a full copy of the functor, because concurrency modification m_functor = new CPath(p_functor); // create immutable structures final Multimap<IPath, ILiteral> l_annotations = HashMultimap.create(); p_annotations.forEach(i -> l_annotations.put(i.fqnfunctor(), i)); m_annotations = ImmutableSetMultimap.copyOf(l_annotations); final Multimap<IPath, ITerm> l_values = LinkedListMultimap.create(); p_values.forEach(i -> l_values.put(i.fqnfunctor(), i)); m_values = ImmutableListMultimap.copyOf(l_values); m_orderedvalues = Collections.unmodifiableList(new LinkedList<>(p_values)); // calculates hash value m_hash = m_functor.hashCode() ^ IntStream.range(0, m_orderedvalues.size()).boxed() .mapToInt(i -> (i + 1) * m_orderedvalues.get(i).hashCode()).sum() ^ m_annotations.values().stream().mapToInt(Object::hashCode).sum() ^ (m_negated ? 0 : 55529) ^ (m_at ? 0 : 8081); // calculates the structure hash value (Murmur3) of the value and annotation definition // functor will be added iif no literal data exists ( hasher must be existing twice ) final String l_functor = p_functor.getPath(); final Hasher l_valuehasher = CCommon.getTermHashing(); if (m_orderedvalues.stream().filter(i -> i instanceof ILiteral) .map(i -> l_valuehasher.putInt(((ILiteral) i).valuehash())).count() == 0) { l_valuehasher.putBoolean(m_negated); l_valuehasher.putString(l_functor, Charsets.UTF_8); } final Hasher l_annotationhasher = CCommon.getTermHashing(); if (m_annotations.values().stream().map(i -> l_annotationhasher.putInt(i.valuehash())).count() == 0) { l_annotationhasher.putBoolean(m_negated); l_annotationhasher.putString(l_functor, Charsets.UTF_8); } m_annotationhash = l_annotationhasher.hash().asInt(); m_valuehash = l_valuehasher.hash().asInt(); }
From source file:com.google.template.soy.jbcsrc.api.SoySauceImpl.java
private SoySauceImpl(CompiledTemplates templates, TemplateRegistry registry, SoyMsgBundle defaultMsgBundle, SetMultimap<String, String> templateToTransitiveUsedIjParams, GuiceSimpleScope apiCallScope, SoyValueHelper converter, Map<String, SoyJavaFunction> functions, Map<String, SoyJavaPrintDirective> printDirectives) { this.templates = checkNotNull(templates); this.defaultMsgBundle = replaceLocale(defaultMsgBundle); this.templateToTransitiveUsedIjParams = ImmutableSetMultimap.copyOf(templateToTransitiveUsedIjParams); this.apiCallScope = checkNotNull(apiCallScope); this.converter = checkNotNull(converter); this.functions = ImmutableMap.copyOf(functions); this.printDirectives = ImmutableMap.copyOf(printDirectives); this.factory = new DelTemplateSelectorImpl.Factory(registry, templates); }
From source file:dagger.internal.codegen.MapMultibindingValidator.java
private void checkForDuplicateMapKeys(dagger.model.Binding multiboundMapBinding, ImmutableSet<ContributionBinding> contributions, DiagnosticReporter diagnosticReporter) { ImmutableSetMultimap<Object, ContributionBinding> contributionsByMapKey = ImmutableSetMultimap .copyOf(Multimaps.index(contributions, ContributionBinding::mapKey)); for (Set<ContributionBinding> contributionsForOneMapKey : Multimaps.asMap(contributionsByMapKey).values()) { if (contributionsForOneMapKey.size() > 1) { diagnosticReporter.reportBinding(ERROR, multiboundMapBinding, duplicateMapKeyErrorMessage(contributionsForOneMapKey, multiboundMapBinding.key())); }// www . j a va 2s.c o m } }
From source file:dagger.internal.codegen.MapMultibindingValidator.java
private static ImmutableSetMultimap<Equivalence.Wrapper<DeclaredType>, ContributionBinding> indexByMapKeyAnnotationType( ImmutableSet<ContributionBinding> contributions) { return ImmutableSetMultimap.copyOf(Multimaps.index(contributions, mapBinding -> MoreTypes.equivalence() .wrap(mapBinding.mapKeyAnnotation().get().getAnnotationType()))); }