Example usage for com.google.common.collect Multimaps newSetMultimap

List of usage examples for com.google.common.collect Multimaps newSetMultimap

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps newSetMultimap.

Prototype

public static <K, V> SetMultimap<K, V> newSetMultimap(Map<K, Collection<V>> map,
        final Supplier<? extends Set<V>> factory) 

Source Link

Document

Creates a new SetMultimap that uses the provided map and factory.

Usage

From source file:org.eclipse.viatra.query.runtime.internal.engine.ModelUpdateProvider.java

public ModelUpdateProvider(AdvancedViatraQueryEngine queryEngine, Logger logger) {
    super();/* ww  w. j  a  v  a  2 s  .co m*/
    this.queryEngine = queryEngine;
    this.logger = logger;
    Map<ChangeLevel, Collection<ViatraQueryModelUpdateListener>> map = new EnumMap<>(ChangeLevel.class);
    listenerMap = Multimaps.newSetMultimap(map, HashSet::new);
}

From source file:org.eclipse.incquery.runtime.internal.engine.ModelUpdateProvider.java

public ModelUpdateProvider(AdvancedIncQueryEngine incQueryEngine, Logger logger) {
    super();/*from  w  w  w  . ja va 2 s. c  om*/
    this.incQueryEngine = incQueryEngine;
    this.logger = logger;
    Map<ChangeLevel, Collection<IncQueryModelUpdateListener>> map = Maps.newEnumMap(ChangeLevel.class);
    listenerMap = Multimaps.newSetMultimap(map,
            new com.google.common.base.Supplier<Set<IncQueryModelUpdateListener>>() {
                @Override
                public Set<IncQueryModelUpdateListener> get() {
                    return Sets.newHashSet();
                }
            });
}

From source file:org.killbill.billing.lifecycle.DefaultLifecycle.java

private DefaultLifecycle() {
    this.handlersByLevel = Multimaps.newSetMultimap(
            new ConcurrentHashMap<LifecycleHandlerType.LifecycleLevel, Collection<LifecycleHandler<? extends KillbillService>>>(),

            new Supplier<Set<LifecycleHandler<? extends KillbillService>>>() {
                @Override//www  .j av  a2 s. c om
                public Set<LifecycleHandler<? extends KillbillService>> get() {
                    return new CopyOnWriteArraySet<LifecycleHandler<? extends KillbillService>>();
                }
            });
}

From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext.java

public EffectiveSchemaContext(final List<DeclaredStatement<?>> rootDeclaredStatements,
        final List<EffectiveStatement<?, ?>> rootEffectiveStatements) {
    this.rootDeclaredStatements = ImmutableList.copyOf(rootDeclaredStatements);
    this.rootEffectiveStatements = ImmutableList.copyOf(rootEffectiveStatements);

    Set<Module> modulesInit = new HashSet<>();
    for (EffectiveStatement<?, ?> rootEffectiveStatement : rootEffectiveStatements) {
        if (rootEffectiveStatement instanceof ModuleEffectiveStatementImpl) {
            Module module = (Module) rootEffectiveStatement;
            modulesInit.add(module);//  www  .  ja  v  a 2  s. c  om
        }
    }

    Module[] moduleArray = new Module[modulesInit.size()];
    List<Module> sortedModuleList = ModuleDependencySort.sort(modulesInit.toArray(moduleArray));
    this.modules = ImmutableSet.copyOf(sortedModuleList);

    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 : modulesInit) {
        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);
}

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 w  w 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<>(), 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.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
 *
 *//*  w w  w. j a  v a 2s.  co 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.eclipse.viatra.query.runtime.registry.view.AbstractRegistryView.java

/**
 * Creates a new view instance for the given registry. Note that views are created by the registry and the view
 * update mechanisms are also set up by the registry.
 * // w  ww.  j a va2  s .  co  m
 * @param registry
 */
public AbstractRegistryView(IQuerySpecificationRegistry registry, boolean allowDuplicateFQNs) {
    this.registry = registry;
    this.allowDuplicateFQNs = allowDuplicateFQNs;
    this.fqnToEntryMap = Multimaps.newSetMultimap(new TreeMap<>(), HashSet::new);
    this.listeners = new HashSet<>();
}

From source file:org.jetbrains.kotlin.grammar.ConfluenceHyperlinksGenerator.java

private static StringBuilder generate(List<Token> tokens) throws IOException {
    StringBuilder result = new StringBuilder("h1. Contents\n").append("{toc:style=disc|indent=20px}");

    Set<String> declaredSymbols = new HashSet<String>();
    Set<String> usedSymbols = new HashSet<String>();
    Multimap<String, String> usages = Multimaps.newSetMultimap(Maps.<String, Collection<String>>newHashMap(),
            new Supplier<Set<String>>() {
                @Override//from   www .ja  v a 2  s .com
                public Set<String> get() {
                    return Sets.newHashSet();
                }
            });

    Declaration lastDeclaration = null;
    for (Token advance : tokens) {
        if (advance instanceof Declaration) {
            Declaration declaration = (Declaration) advance;
            lastDeclaration = declaration;
            declaredSymbols.add(declaration.getName());
        } else if (advance instanceof Identifier) {
            Identifier identifier = (Identifier) advance;
            assert lastDeclaration != null;
            usages.put(identifier.getName(), lastDeclaration.getName());
            usedSymbols.add(identifier.getName());
        }
    }

    for (Token token : tokens) {
        if (token instanceof Declaration) {
            Declaration declaration = (Declaration) token;
            result.append("{anchor:").append(declaration.getName()).append("}");
            if (!usedSymbols.contains(declaration.getName())) {
                //                    result.append("(!) *Unused!* ");
                System.out.println("Unused: " + tokenWithPosition(token));
            }
            Collection<String> myUsages = usages.get(declaration.getName());
            if (!myUsages.isEmpty()) {
                result.append("\\[{color:grey}Used by ");
                for (Iterator<String> iterator = myUsages.iterator(); iterator.hasNext();) {
                    String usage = iterator.next();
                    result.append("[#").append(usage).append("]");
                    if (iterator.hasNext()) {
                        result.append(", ");
                    }
                }
                result.append("{color}\\]\n");
            }
            result.append(token);
            continue;
        } else if (token instanceof Identifier) {
            Identifier identifier = (Identifier) token;
            if (!declaredSymbols.contains(identifier.getName())) {
                result.append("(!) *Undeclared!* ");
                System.out.println("Undeclared: " + tokenWithPosition(token));
            }
        }
        result.append(token);
    }
    return result;
}

From source file:org.jboss.weld.annotated.enhanced.jlr.EnhancedAnnotationImpl.java

/**
 * Constructor//from   w w w . j  a  v  a 2  s  .c o  m
 * <p/>
 * Initializes the superclass with the built annotation map
 *
 * @param annotationType The annotation type
 */
protected EnhancedAnnotationImpl(SlimAnnotatedType<T> annotatedType,
        Map<Class<? extends Annotation>, Annotation> annotationMap,
        Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap, ClassTransformer classTransformer) {
    super(annotatedType, annotationMap, declaredAnnotationMap, classTransformer);
    this.clazz = annotatedType.getJavaClass();
    members = new HashSet<EnhancedAnnotatedMethod<?, ?>>();
    annotatedMembers = Multimaps.newSetMultimap(
            new HashMap<Class<? extends Annotation>, Collection<EnhancedAnnotatedMethod<?, ?>>>(),
            HashSetSupplier.<EnhancedAnnotatedMethod<?, ?>>instance());
    for (AnnotatedMethod<? super T> annotatedMethod : annotatedType.getMethods()) {
        EnhancedAnnotatedMethod<?, ? super T> enhancedAnnotatedMethod = EnhancedAnnotatedMethodImpl
                .of(annotatedMethod, this, classTransformer);
        members.add(enhancedAnnotatedMethod);
        for (Annotation annotation : enhancedAnnotatedMethod.getAnnotations()) {
            annotatedMembers.put(annotation.annotationType(), enhancedAnnotatedMethod);
        }
    }
}

From source file:org.jboss.weld.introspector.jlr.WeldAnnotationImpl.java

/**
 * Constructor/*w ww. j av  a2 s.c om*/
 * <p/>
 * Initializes the superclass with the built annotation map
 *
 * @param annotationType The annotation type
 */
protected WeldAnnotationImpl(Class<T> annotationType,
        Map<Class<? extends Annotation>, Annotation> annotationMap,
        Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap, ClassTransformer classTransformer) {
    super(annotationType, annotationType, null, new TypeClosureLazyValueHolder(annotationType), annotationMap,
            declaredAnnotationMap, classTransformer);
    this.clazz = annotationType;
    members = new HashSet<WeldMethod<?, ?>>();
    annotatedMembers = Multimaps.newSetMultimap(
            new HashMap<Class<? extends Annotation>, Collection<WeldMethod<?, ?>>>(),
            HashSetSupplier.<WeldMethod<?, ?>>instance());
    for (Method member : SecureReflections.getDeclaredMethods(clazz)) {
        WeldMethod<?, ?> annotatedMethod = WeldMethodImpl.of(member, this, classTransformer);
        members.add(annotatedMethod);
        for (Annotation annotation : annotatedMethod.getAnnotations()) {
            annotatedMembers.put(annotation.annotationType(), annotatedMethod);
        }
    }
}