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.napile.compiler.util.CommonSuppliers.java

public static <K, V> SetMultimap<K, V> newLinkedHashSetHashSetMultimap() {
    return Multimaps.newSetMultimap(Maps.<K, Collection<V>>newHashMap(),
            CommonSuppliers.<V>getLinkedHashSetSupplier());
}

From source file:dupfitwo.Mmap.java

public Mmap() {
    backing = new TLongObjectHashMap<Collection<T>>(EXPECTED_KEYS);
    coll = Multimaps.newSetMultimap(TDecorators.wrap(backing), new Supplier<Set<T>>() {
        public Set<T> get() {
            return new LinkedHashSet<T>();
        }/*from   ww w . j  a  v  a2 s  .  co m*/
    });
}

From source file:org.jboss.weld.metadata.TypeStore.java

public TypeStore() {
    this.extraAnnotations = Multimaps.newSetMultimap(
            new ConcurrentHashMap<Class<? extends Annotation>, Collection<Annotation>>(),
            new Supplier<Set<Annotation>>() {

                public Set<Annotation> get() {
                    return new CopyOnWriteArraySet<Annotation>();
                }//  w ww .  ja  v  a2  s .  com

            });
    this.extraScopes = new CopyOnWriteArraySet<Class<? extends Annotation>>();
}

From source file:org.jboss.weld.ejb.EjbDescriptors.java

/**
 * Constructor//from  w  ww . j  a v a 2s .  co  m
 */
public EjbDescriptors() {
    this.ejbByName = new HashMap<String, InternalEjbDescriptor<?>>();
    this.ejbByClass = Multimaps.newSetMultimap(new HashMap<Class<?>, Collection<String>>(),
            new Supplier<Set<String>>() {

                public Set<String> get() {
                    return new HashSet<String>();
                }

            });
}

From source file:com.ning.billing.beatrix.lifecycle.Lifecycle.java

@Inject
public Lifecycle(Injector injector) {

    this.serviceFinder = new ServiceFinder(Lifecycle.class.getClassLoader());
    this.handlersByLevel = Multimaps.newSetMultimap(
            new ConcurrentHashMap<LifecycleLevel, Collection<LifecycleHandler<? extends KillbillService>>>(),

            new Supplier<Set<LifecycleHandler<? extends KillbillService>>>() {
                @Override/*  w ww. j a v a 2s .  com*/
                public Set<LifecycleHandler<? extends KillbillService>> get() {
                    return new CopyOnWriteArraySet<LifecycleHandler<? extends KillbillService>>();
                }
            });
    this.injector = injector;

    init();
}

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

@Inject
public DefaultLifecycle(final Injector injector) {

    this.serviceFinder = new ServiceFinder(DefaultLifecycle.class.getClassLoader());
    this.handlersByLevel = Multimaps.newSetMultimap(
            new ConcurrentHashMap<LifecycleLevel, Collection<LifecycleHandler<? extends KillbillService>>>(),

            new Supplier<Set<LifecycleHandler<? extends KillbillService>>>() {
                @Override/*from   ww  w .  ja  va 2s  . c o  m*/
                public Set<LifecycleHandler<? extends KillbillService>> get() {
                    return new CopyOnWriteArraySet<LifecycleHandler<? extends KillbillService>>();
                }
            });
    this.injector = injector;

    init();
}

From source file:org.opendaylight.yangtools.yang.parser.impl.SchemaContextImpl.java

SchemaContextImpl(final Set<Module> modules, final Map<ModuleIdentifier, String> identifiersToSources) {
    this.identifiersToSources = ImmutableMap.copyOf(identifiersToSources);

    /*/*from w w w  .  j a  v  a 2s .  com*/
    * 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<URI, Collection<Module>>(),
            MODULE_SET_SUPPLIER);
    final SetMultimap<String, Module> nameMap = Multimaps
            .newSetMultimap(new TreeMap<String, Collection<Module>>(), MODULE_SET_SUPPLIER);

    for (Module m : modules) {
        nameMap.put(m.getName(), m);
        nsMap.put(m.getNamespace(), m);
    }

    namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
    nameToModules = ImmutableSetMultimap.copyOf(nameMap);
}

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

public EffectiveSchemaContext(List<DeclaredStatement<?>> rootDeclaredStatements,
        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 Module) {
            Module module = (Module) rootEffectiveStatement;
            modulesInit.add(module);/*from   w w  w. j  a  va 2s .  c  o  m*/
        }
    }
    this.modules = ImmutableSet.copyOf(modulesInit);

    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);

    for (Module m : modulesInit) {
        nameMap.put(m.getName(), m);
        nsMap.put(m.getNamespace(), m);
    }

    namespaceToModules = ImmutableSetMultimap.copyOf(nsMap);
    nameToModules = ImmutableSetMultimap.copyOf(nameMap);

    // :TODO
    // this.identifiersToSources =
    // ImmutableMap.copyOf(identifiersToSources);
    this.identifiersToSources = null;

}

From source file:org.eclipse.incquery.runtime.evm.specific.resolver.FixedPriorityConflictSet.java

public FixedPriorityConflictSet(FixedPriorityConflictResolver resolver,
        Map<RuleSpecification<?>, Integer> priorities) {
    this.resolver = resolver;
    checkArgument(priorities != null, "Priority map cannot be null!");
    priorityMap = Maps.newHashMap(priorities);
    Map<Integer, Collection<Activation<?>>> treeMap = new TreeMap<Integer, Collection<Activation<?>>>();
    Multimap<Integer, Activation<?>> multimap = Multimaps.newSetMultimap(treeMap,
            new Supplier<Set<Activation<?>>>() {
                @Override// w w  w  .jav  a  2  s .co m
                public Set<Activation<?>> get() {
                    return new HashSet<Activation<?>>();
                }
            });
    this.priorityBuckets = multimap;
}

From source file:com.mycila.inject.jsr250.Jsr250Module.java

@Override
public void configure(Binder binder) {
    binder.bind(Jsr250Injector.class).to(Jsr250InjectorImpl.class).in(Singleton.class);
    binder.bind(Jsr250KeyProvider.class).in(Singleton.class);
    binder.bind(Jsr250PostConstructHandler.class).in(Singleton.class);
    in(binder).bindAnnotationInjector(Resource.class, Jsr250KeyProvider.class)
            .handleMethodAfterInjection(PostConstruct.class, Jsr250PostConstructHandler.class)
            .bind(Jsr250Destroyer.class, new Jsr250Destroyer() {
                @Inject/*from w w  w  .  j  av  a2  s.  co  m*/
                Injector injector;

                @Override
                public void preDestroy() {
                    Map<Key<?>, Binding<?>> bindings = injector.getAllBindings();
                    Multimap<Binding<?>, Binding<?>> dependants = Multimaps.newSetMultimap(
                            new IdentityHashMap<Binding<?>, Collection<Binding<?>>>(),
                            new Supplier<Set<Binding<?>>>() {
                                @Override
                                public Set<Binding<?>> get() {
                                    return new HashSet<Binding<?>>();
                                }
                            });
                    for (Binding<?> binding : bindings.values()) {
                        if (binding instanceof HasDependencies) {
                            for (Dependency<?> dependency : ((HasDependencies) binding).getDependencies()) {
                                if (bindings.containsKey(dependency.getKey())) {
                                    dependants.put(injector.getBinding(dependency.getKey()), binding);
                                }
                            }
                        }
                    }
                    Map<Object, Object> done = new IdentityHashMap<Object, Object>(bindings.size());
                    for (final Binding<?> binding : bindings.values())
                        if (new SingletonChecker(binding).isSingleton()) {
                            close(binding, done, dependants);
                        }
                    for (Scope scope : injector.getScopeBindings().values())
                        Jsr250.preDestroy(scope);
                }

                private void close(Binding<?> binding, Map<Object, Object> done,
                        Multimap<Binding<?>, Binding<?>> dependants) {
                    if (!done.containsKey(binding)) {
                        done.put(binding, Void.TYPE);
                        for (Binding<?> dependant : dependants.get(binding)) {
                            close(dependant, done, dependants);
                        }
                        try {
                            if (binding instanceof ProviderInstanceBinding<?>) {
                                Object o = ((ProviderInstanceBinding) binding).getProviderInstance();
                                if (!done.containsKey(o)) {
                                    Jsr250.preDestroy(o);
                                    done.put(o, Void.TYPE);
                                }
                            } else if (new SingletonChecker(binding).isSingleton()) {
                                Object o = binding.getProvider().get();
                                if (!done.containsKey(o)) {
                                    Jsr250.preDestroy(o);
                                    done.put(o, Void.TYPE);
                                }
                            }
                        } catch (Exception e) {
                            // just ignore close errors
                        }
                    }
                }
            });
}