Example usage for com.google.common.collect ImmutableMultimap copyOf

List of usage examples for com.google.common.collect ImmutableMultimap copyOf

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMultimap copyOf.

Prototype

@Beta
public static <K, V> ImmutableMultimap<K, V> copyOf(
        Iterable<? extends Entry<? extends K, ? extends V>> entries) 

Source Link

Document

Returns an immutable multimap containing the specified entries.

Usage

From source file:com.kolich.curacao.mappers.MapperTable.java

private final ImmutableMultimap<Class<?>, ControllerArgumentMapper<?>> buildArgumentMapperTable(
        final Set<Class<?>> mapperSet) {
    // Using a LinkedHashMultimap internally because insertion order is
    // very important in this case.
    final Multimap<Class<?>, ControllerArgumentMapper<?>> mappers = LinkedHashMultimap.create(); // Preserves order
    // Filter the incoming mapper set to only argument mappers.
    final Set<Class<?>> filtered = Sets.filter(mapperSet,
            Predicates.assignableFrom(ControllerArgumentMapper.class));
    logger__.debug("Found {} argument mappers annotated with @{}", filtered.size(), MAPPER_ANNOTATION_SN);
    // For each discovered mapper class...
    for (final Class<?> mapper : filtered) {
        logger__.debug("Found @{}: argument mapper {}", MAPPER_ANNOTATION_SN, mapper.getCanonicalName());
        try {//  ww w  .jav a 2s.c  o m
            // Locate a single constructor worthy of injecting with
            // components, if any.  May be null.
            final Constructor<?> ctor = getInjectableConstructor(mapper);
            ControllerArgumentMapper<?> instance = null;
            if (ctor == null) {
                // Class.newInstance() is evil, so we do the ~right~ thing
                // here to instantiate a new instance of the mapper using
                // the preferred getConstructor() idiom.
                instance = (ControllerArgumentMapper<?>) mapper.getConstructor().newInstance();
            } else {
                final Class<?>[] types = ctor.getParameterTypes();
                final Object[] params = new Object[types.length];
                for (int i = 0, l = types.length; i < l; i++) {
                    params[i] = componentTable_.getComponentForType(types[i]);
                }
                instance = (ControllerArgumentMapper<?>) ctor.newInstance(params);
            }
            // Note the key in the map is the parameterized generic type
            // hanging off the mapper.
            mappers.put(getGenericType(mapper), instance);
        } catch (Exception e) {
            logger__.error("Failed to instantiate mapper instance: {}", mapper.getCanonicalName(), e);
        }
    }
    // Add the "default" mappers to the ~end~ of the immutable hash multi map.
    // This essentially means that default argument mappers (the ones
    // provided by this library) are found & called after any user registered
    // mappers.
    mappers.putAll(defaultArgMappers__);
    return ImmutableMultimap.copyOf(mappers);
}

From source file:org.joda.beans.gen.ImmGuava.java

/**
 * Creates an instance./*  ww w  . j  ava  2  s  .  c o  m*/
 * @param collection  the value of the property, not null
 * @param list  the value of the property, not null
 * @param set  the value of the property, not null
 * @param sortedSet  the value of the property, not null
 * @param map  the value of the property, not null
 * @param sortedMap  the value of the property, not null
 * @param biMap  the value of the property, not null
 * @param multimap  the value of the property, not null
 * @param listMultimap  the value of the property, not null
 * @param setMultimap  the value of the property, not null
 * @param multiset  the value of the property, not null
 * @param sortedMultiset  the value of the property, not null
 * @param collectionInterface  the value of the property, not null
 * @param listInterface  the value of the property, not null
 * @param setInterface  the value of the property, not null
 * @param sortedSetInterface  the value of the property, not null
 * @param mapInterface  the value of the property, not null
 * @param sortedMapInterface  the value of the property, not null
 * @param biMapInterface  the value of the property, not null
 * @param multimapInterface  the value of the property, not null
 * @param listMultimapInterface  the value of the property, not null
 * @param setMultimapInterface  the value of the property, not null
 * @param multisetInterface  the value of the property, not null
 * @param sortedMultisetInterface  the value of the property, not null
 * @param listWildExtendsT  the value of the property, not null
 * @param listWildExtendsNumber  the value of the property, not null
 * @param listWildExtendsComparable  the value of the property, not null
 * @param setWildExtendsT  the value of the property, not null
 * @param setWildExtendsNumber  the value of the property, not null
 * @param setWildExtendsComparable  the value of the property, not null
 * @param listWildBuilder1  the value of the property, not null
 * @param listWildBuilder2  the value of the property, not null
 * @param mapWildBuilder1  the value of the property, not null
 */
public ImmGuava(Collection<T> collection, List<T> list, Set<T> set, SortedSet<T> sortedSet, Map<T, String> map,
        SortedMap<T, String> sortedMap, BiMap<T, String> biMap, Multimap<T, String> multimap,
        ListMultimap<T, String> listMultimap, SetMultimap<T, String> setMultimap, Multiset<T> multiset,
        SortedMultiset<T> sortedMultiset, Collection<T> collectionInterface, List<T> listInterface,
        Set<T> setInterface, SortedSet<T> sortedSetInterface, Map<T, String> mapInterface,
        SortedMap<T, String> sortedMapInterface, BiMap<T, String> biMapInterface,
        Multimap<T, String> multimapInterface, ListMultimap<T, String> listMultimapInterface,
        SetMultimap<T, String> setMultimapInterface, Multiset<T> multisetInterface,
        SortedMultiset<T> sortedMultisetInterface, List<? extends T> listWildExtendsT,
        List<? extends Number> listWildExtendsNumber, List<? extends Comparable<?>> listWildExtendsComparable,
        Set<? extends T> setWildExtendsT, Set<? extends Number> setWildExtendsNumber,
        Set<? extends Comparable<?>> setWildExtendsComparable, List<?> listWildBuilder1,
        List<? extends Address> listWildBuilder2, Map<String, ? extends Address> mapWildBuilder1) {
    JodaBeanUtils.notNull(collection, "collection");
    JodaBeanUtils.notNull(list, "list");
    JodaBeanUtils.notNull(set, "set");
    JodaBeanUtils.notNull(sortedSet, "sortedSet");
    JodaBeanUtils.notNull(map, "map");
    JodaBeanUtils.notNull(sortedMap, "sortedMap");
    JodaBeanUtils.notNull(biMap, "biMap");
    JodaBeanUtils.notNull(multimap, "multimap");
    JodaBeanUtils.notNull(listMultimap, "listMultimap");
    JodaBeanUtils.notNull(setMultimap, "setMultimap");
    JodaBeanUtils.notNull(multiset, "multiset");
    JodaBeanUtils.notNull(sortedMultiset, "sortedMultiset");
    JodaBeanUtils.notNull(collectionInterface, "collectionInterface");
    JodaBeanUtils.notNull(listInterface, "listInterface");
    JodaBeanUtils.notNull(setInterface, "setInterface");
    JodaBeanUtils.notNull(sortedSetInterface, "sortedSetInterface");
    JodaBeanUtils.notNull(mapInterface, "mapInterface");
    JodaBeanUtils.notNull(sortedMapInterface, "sortedMapInterface");
    JodaBeanUtils.notNull(biMapInterface, "biMapInterface");
    JodaBeanUtils.notNull(multimapInterface, "multimapInterface");
    JodaBeanUtils.notNull(listMultimapInterface, "listMultimapInterface");
    JodaBeanUtils.notNull(setMultimapInterface, "setMultimapInterface");
    JodaBeanUtils.notNull(multisetInterface, "multisetInterface");
    JodaBeanUtils.notNull(sortedMultisetInterface, "sortedMultisetInterface");
    JodaBeanUtils.notNull(listWildExtendsT, "listWildExtendsT");
    JodaBeanUtils.notNull(listWildExtendsNumber, "listWildExtendsNumber");
    JodaBeanUtils.notNull(listWildExtendsComparable, "listWildExtendsComparable");
    JodaBeanUtils.notNull(setWildExtendsT, "setWildExtendsT");
    JodaBeanUtils.notNull(setWildExtendsNumber, "setWildExtendsNumber");
    JodaBeanUtils.notNull(setWildExtendsComparable, "setWildExtendsComparable");
    JodaBeanUtils.notNull(listWildBuilder1, "listWildBuilder1");
    JodaBeanUtils.notNull(listWildBuilder2, "listWildBuilder2");
    JodaBeanUtils.notNull(mapWildBuilder1, "mapWildBuilder1");
    this.collection = ImmutableList.copyOf(collection);
    this.list = ImmutableList.copyOf(list);
    this.set = ImmutableSet.copyOf(set);
    this.sortedSet = ImmutableSortedSet.copyOfSorted(sortedSet);
    this.map = ImmutableMap.copyOf(map);
    this.sortedMap = ImmutableSortedMap.copyOfSorted(sortedMap);
    this.biMap = ImmutableBiMap.copyOf(biMap);
    this.multimap = ImmutableMultimap.copyOf(multimap);
    this.listMultimap = ImmutableListMultimap.copyOf(listMultimap);
    this.setMultimap = ImmutableSetMultimap.copyOf(setMultimap);
    this.multiset = ImmutableMultiset.copyOf(multiset);
    this.sortedMultiset = ImmutableSortedMultiset.copyOfSorted(sortedMultiset);
    this.collectionInterface = ImmutableList.copyOf(collectionInterface);
    this.listInterface = ImmutableList.copyOf(listInterface);
    this.setInterface = ImmutableSet.copyOf(setInterface);
    this.sortedSetInterface = ImmutableSortedSet.copyOfSorted(sortedSetInterface);
    this.mapInterface = ImmutableMap.copyOf(mapInterface);
    this.sortedMapInterface = ImmutableSortedMap.copyOfSorted(sortedMapInterface);
    this.biMapInterface = ImmutableBiMap.copyOf(biMapInterface);
    this.multimapInterface = ImmutableMultimap.copyOf(multimapInterface);
    this.listMultimapInterface = ImmutableListMultimap.copyOf(listMultimapInterface);
    this.setMultimapInterface = ImmutableSetMultimap.copyOf(setMultimapInterface);
    this.multisetInterface = ImmutableMultiset.copyOf(multisetInterface);
    this.sortedMultisetInterface = ImmutableSortedMultiset.copyOfSorted(sortedMultisetInterface);
    this.listWildExtendsT = ImmutableList.copyOf(listWildExtendsT);
    this.listWildExtendsNumber = ImmutableList.copyOf(listWildExtendsNumber);
    this.listWildExtendsComparable = ImmutableList.copyOf(listWildExtendsComparable);
    this.setWildExtendsT = ImmutableSet.copyOf(setWildExtendsT);
    this.setWildExtendsNumber = ImmutableSet.copyOf(setWildExtendsNumber);
    this.setWildExtendsComparable = ImmutableSet.copyOf(setWildExtendsComparable);
    this.listWildBuilder1 = ImmutableList.copyOf(listWildBuilder1);
    this.listWildBuilder2 = ImmutableList.copyOf(listWildBuilder2);
    this.mapWildBuilder1 = ImmutableMap.copyOf(mapWildBuilder1);
}

From source file:uk.jamierocks.zinc.ZincDispatcher.java

@Override
public Multimap<String, CommandMapping> getAll() {
    return ImmutableMultimap.copyOf(this.commands);
}

From source file:com.facebook.buck.apple.ProjectGenerator.java

/**
 * Sets combined test targets which should be generated in this project.
 *//*from ww w  .j  ava  2 s  .  c  om*/
public ProjectGenerator setAdditionalCombinedTestTargets(
        Multimap<AppleTestBundleParamsKey, TargetNode<AppleTestDescription.Arg>> targets) {
    Preconditions.checkState(!projectGenerated);
    this.additionalCombinedTestTargets = ImmutableMultimap.copyOf(targets);
    return this;
}

From source file:org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin.java

/**
 * Returns a new instance of EMF Compare adapter factory descriptor registry to which extension will be
 * registered. It filters available adapter factories using preferences.
 * /* www  .  ja va  2  s .  c  om*/
 * @return the the adapter factory descriptor registry to which extension will be registered
 * @since 2.3
 */
public RankedAdapterFactoryDescriptor.Registry createFilteredAdapterFactoryRegistry() {
    final List<String> disabledAdapterFactories = EMFComparePreferences
            .getDisabledAdapterFacotryDescriptorIds(getEMFComparePreferences());
    // Filters disabled adapter factories
    Multimap<Collection<?>, RankedAdapterFactoryDescriptor> filteredBackingMultimap = ImmutableMultimap
            .copyOf(Multimaps.filterValues(adapterFactoryRegistryBackingMultimap,
                    new Predicate<RankedAdapterFactoryDescriptor>() {

                        public boolean apply(RankedAdapterFactoryDescriptor input) {
                            return !disabledAdapterFactories.contains(input.getId());
                        }
                    }));
    return new RankedAdapterFactoryDescriptorRegistryImpl(ComposedAdapterFactory.Descriptor.Registry.INSTANCE,
            filteredBackingMultimap);
}

From source file:com.facebook.buck.android.apkmodule.APKModuleGraph.java

private ImmutableMultimap<BuildTarget, String> generateSharedSeeds() {
    Optional<Map<String, List<BuildTarget>>> seedConfigMap = configMapSupplier.get();
    HashMultimap<BuildTarget, String> sharedSeedMapBuilder = HashMultimap.create();
    if (!seedConfigMap.isPresent()) {
        return ImmutableMultimap.copyOf(sharedSeedMapBuilder);
    }//from   ww  w .j  a v a 2 s  .co  m
    // first: invert the seedConfigMap to get BuildTarget -> Seeds
    for (Map.Entry<String, List<BuildTarget>> entry : seedConfigMap.get().entrySet()) {
        for (BuildTarget buildTarget : entry.getValue()) {
            sharedSeedMapBuilder.put(buildTarget, entry.getKey());
        }
    }
    // second: remove keys that have only one value.
    Set<BuildTarget> nonSharedSeeds = new HashSet<>();
    for (BuildTarget buildTarget : sharedSeedMapBuilder.keySet()) {
        if (sharedSeedMapBuilder.get(buildTarget).size() <= 1) {
            nonSharedSeeds.add(buildTarget);
        }
    }
    for (BuildTarget targetToRemove : nonSharedSeeds) {
        sharedSeedMapBuilder.removeAll(targetToRemove);
    }
    return ImmutableMultimap.copyOf(sharedSeedMapBuilder);
}