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:org.jclouds.net.domain.IpPermission.java

protected IpPermission(IpProtocol ipProtocol, int fromPort, int toPort,
        Multimap<String, String> tenantIdGroupNamePairs, Iterable<String> groupIds,
        Iterable<String> cidrBlocks) {
    this.fromPort = fromPort;
    this.toPort = toPort;
    this.tenantIdGroupNamePairs = ImmutableMultimap
            .copyOf(checkNotNull(tenantIdGroupNamePairs, "tenantIdGroupNamePairs"));
    this.ipProtocol = checkNotNull(ipProtocol, "ipProtocol");
    this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds"));
    this.cidrBlocks = ImmutableSet.copyOf(checkNotNull(cidrBlocks, "cidrBlocks"));
}

From source file:me.lucko.luckperms.api.context.ImmutableContextSet.java

ImmutableContextSet(Multimap<String, String> contexts) {
    this.map = ImmutableMultimap.copyOf(contexts);
}

From source file:com.qualys.feign.jaxrs.BeanParamTransformerFactory.java

protected BeanParamTransformer createTransformer(Type beanClass, int paramIndex) {
    try {//w  ww. java 2  s  .  c o m
        List<BeanParamPropertyMetadata> propertyMetas = new ArrayList<BeanParamPropertyMetadata>();

        // Find annotated write methods and their respective reads
        Map<String, PropertyDescriptor> descriptorsByName = new HashMap<String, PropertyDescriptor>();
        BeanInfo info = Introspector.getBeanInfo((Class<?>) beanClass);
        for (PropertyDescriptor prop : info.getPropertyDescriptors()) {
            if (prop.getReadMethod() != null && prop.getWriteMethod() != null) {
                Multimap<String, Annotation> names = getNames(prop.getWriteMethod().getAnnotations());
                if (!names.isEmpty()) {
                    propertyMetas.add(new BeanParamPropertyMetadata(names, null, prop.getReadMethod()));
                }
            }
            descriptorsByName.put(prop.getName(), prop);
        }

        // Find annotated fields, prefer getter access but use field in none is found
        for (Field field : ReflectionUtil.getAllDeclaredFields((Class<?>) beanClass, true)) {
            String fieldName = field.getName();
            if (descriptorsByName.containsKey(fieldName)) {
                PropertyDescriptor descriptor = descriptorsByName.get(fieldName);
                Multimap<String, Annotation> names = getNames(field.getAnnotations());
                if (descriptor.getReadMethod() != null && !names.isEmpty()) {
                    propertyMetas.add(new BeanParamPropertyMetadata(names, null, descriptor.getReadMethod()));
                    continue;
                }
            }

            Multimap<String, Annotation> names = getNames(field.getAnnotations());
            if (!names.isEmpty())
                propertyMetas.add(new BeanParamPropertyMetadata(names, field, null));
        }

        String[][] names = new String[propertyMetas.size()][];
        Method[] getters = new Method[propertyMetas.size()];
        Field[] fields = new Field[propertyMetas.size()];
        Multimap<Class<?>, String> params = ArrayListMultimap.create();
        for (int i = 0; i < propertyMetas.size(); i++) {
            BeanParamPropertyMetadata propertyMetadata = propertyMetas.get(i);
            fields[i] = propertyMetadata.property;
            getters[i] = propertyMetadata.getter;
            names[i] = propertyMetadata.names.keySet().toArray(new String[] {});
            invertFrom(transformValues(propertyMetadata.names, v -> (Class<?>) v.getClass().getInterfaces()[0]),
                    params);
        }
        return new BeanParamTransformer(names, ImmutableMultimap.copyOf(params), fields, getters, paramIndex);

    } catch (IntrospectionException e) {
        throw new RuntimeException(format("Unable to build bean info for %s", beanClass), e);
    }
}

From source file:com.hippo.leveldb.impl.VersionEdit.java

public Multimap<Integer, BucketMetaData> getDeletedBFiles() {
    return ImmutableMultimap.copyOf(deletedBFiles);
}

From source file:com.gradleware.tooling.toolingmodel.repository.internal.DefaultOmniBuildInvocationsContainerBuilder.java

private static ImmutableMultimap<Path, OmniProjectTask> buildProjectTasksRecursively(GradleProject project,
        Multimap<Path, OmniProjectTask> tasksPerProject, boolean enforceAllTasksPublic) {
    // add tasks of the current project
    for (GradleTask task : project.getTasks()) {
        tasksPerProject.put(Path.from(project.getPath()),
                DefaultOmniProjectTask.from(task, enforceAllTasksPublic));
    }/*from  w w w. jav a2s .c  o  m*/

    // recurse into child projects and add their tasks
    for (GradleProject childProject : project.getChildren()) {
        buildProjectTasksRecursively(childProject, tasksPerProject, enforceAllTasksPublic);
    }

    // return the tasks grouped by project path
    return ImmutableMultimap.copyOf(tasksPerProject);
}

From source file:org.jclouds.ovf.internal.BaseEnvelope.java

@SuppressWarnings("unchecked")
public BaseEnvelope(Iterable<? extends DiskSection> diskSections,
        Iterable<? extends NetworkSection> networkSections, Multimap<String, Section> additionalSections,
        V virtualSystem) {// ww  w  . j av a 2 s  .com
    this.diskSections = ImmutableSet.copyOf(checkNotNull(diskSections, "diskSections"));
    this.networkSections = ImmutableSet.copyOf(checkNotNull(networkSections, "networkSections"));
    this.additionalSections = ImmutableMultimap.copyOf(checkNotNull(additionalSections, "additionalSections"));
    this.virtualSystem = checkNotNull(virtualSystem, "virtualSystem");
}

From source file:org.eclipse.viatra.transformation.evm.api.RuleEngine.java

/**
 * /*from w w  w .  j a va  2  s.com*/
 * @return a copy of the multimap containing all activations
 */
public Multimap<ActivationState, Activation<?>> getActivations() {
    return ImmutableMultimap.copyOf(ruleBase.getAgenda().getActivations());
}

From source file:org.jclouds.http.HttpMessage.java

protected HttpMessage(Multimap<String, String> headers, @Nullable Payload payload) {
    super(payload);
    this.headers = ImmutableMultimap.copyOf(checkNotNull(headers, "headers"));
}

From source file:com.google.devtools.build.lib.packages.AspectDefinition.java

/**
 * Returns the attribute -&gt; set of labels that are provided by aspects of attribute.
 *///from w w w. j  a va2 s.  c om
public static ImmutableMultimap<Attribute, Label> visitAspectsIfRequired(Rule from, Attribute attribute,
        AdvertisedProviderSet advertisedProviders, DependencyFilter dependencyFilter) {
    SetMultimap<Attribute, Label> result = LinkedHashMultimap.create();
    for (Aspect candidateClass : attribute.getAspects(from)) {
        // Check if target satisfies condition for this aspect (has to provide all required
        // TransitiveInfoProviders)
        RequiredProviders requiredProviders = candidateClass.getDefinition().getRequiredProviders();
        if (requiredProviders.isSatisfiedBy(advertisedProviders)) {
            addAllAttributesOfAspect(from, result, candidateClass, dependencyFilter);
        }
    }
    return ImmutableMultimap.copyOf(result);
}

From source file:org.opendaylight.mdsal.dom.broker.DOMNotificationRouter.java

@Override
public synchronized <T extends DOMNotificationListener> ListenerRegistration<T> registerNotificationListener(
        final T listener, final Collection<SchemaPath> types) {
    final ListenerRegistration<T> reg = new AbstractListenerRegistration<T>(listener) {
        @Override/*w w  w.j  a  v  a  2s . com*/
        protected void removeRegistration() {
            final ListenerRegistration<T> me = this;

            synchronized (DOMNotificationRouter.this) {
                replaceListeners(ImmutableMultimap.copyOf(Multimaps.filterValues(listeners,
                        new Predicate<ListenerRegistration<? extends DOMNotificationListener>>() {
                            @Override
                            public boolean apply(
                                    final ListenerRegistration<? extends DOMNotificationListener> input) {
                                return input != me;
                            }
                        })));
            }
        }
    };

    if (!types.isEmpty()) {
        final Builder<SchemaPath, ListenerRegistration<? extends DOMNotificationListener>> b = ImmutableMultimap
                .builder();
        b.putAll(listeners);

        for (final SchemaPath t : types) {
            b.put(t, reg);
        }

        replaceListeners(b.build());
    }

    return reg;
}