Example usage for com.google.common.collect ImmutableMultimap.Builder put

List of usage examples for com.google.common.collect ImmutableMultimap.Builder put

Introduction

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

Prototype

@Deprecated
@Override
public boolean put(K key, V value) 

Source Link

Document

Guaranteed to throw an exception and leave the multimap unmodified.

Usage

From source file:org.jetbrains.jet.lang.resolve.java.kotlinSignature.JavaToKotlinMethodMap.java

static void put(ImmutableMultimap.Builder<String, ClassData> builder, String javaFqName,
        String kotlinQualifiedName, Pair<String, String>... methods2Functions) {
    ImmutableMap<String, String> methods2FunctionsMap = pairs2Map(methods2Functions);

    ClassDescriptor kotlinClass;//from w w w.  j  a  v  a 2  s.  c  om
    if (kotlinQualifiedName.contains(".")) { // Map.Entry and MutableMap.MutableEntry
        String[] kotlinNames = kotlinQualifiedName.split("\\.");
        assert kotlinNames.length == 2 : "unexpected qualified name " + kotlinQualifiedName;

        ClassDescriptor outerClass = KotlinBuiltIns.getInstance()
                .getBuiltInClassByName(Name.identifier(kotlinNames[0]));
        kotlinClass = DescriptorUtils.getInnerClassByName(outerClass, kotlinNames[1]);
        assert kotlinClass != null : "Class not found: " + kotlinQualifiedName;
    } else {
        kotlinClass = KotlinBuiltIns.getInstance().getBuiltInClassByName(Name.identifier(kotlinQualifiedName));
    }

    builder.put(javaFqName, new ClassData(kotlinClass, methods2FunctionsMap));
}

From source file:com.github.flaxsearch.api.DocumentData.java

public DocumentData(Document document) {
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    for (IndexableField field : document) {
        builder.put(field.name(), field.stringValue());
    }/*  ww w .  jav  a 2  s.c o  m*/
    this.fields = builder.build();
}

From source file:org.jclouds.gogrid.binders.BindVirtualIpPortPairToQueryParams.java

@SuppressWarnings("unchecked")
@Override//from w  w w .j  a v a2  s .c o  m
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input is null") instanceof IpPortPair,
            "this binder is only valid for a IpPortPair argument");

    IpPortPair ipPortPair = (IpPortPair) input;

    checkNotNull(ipPortPair.getIp(), "There must be an IP address defined");
    checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object");
    checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");

    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.<String, String>builder();

    builder.put(VIRTUAL_IP_KEY + "ip", ipPortPair.getIp().getIp());
    builder.put(VIRTUAL_IP_KEY + "port", String.valueOf(ipPortPair.getPort()));

    return (R) request.toBuilder().replaceQueryParams(builder.build()).build();
}

From source file:com.twitter.aurora.scheduler.thrift.SchedulerThriftInterface.java

private static Multimap<String, IJobConfiguration> jobsByKey(JobStore jobStore, IJobKey jobKey) {
    ImmutableMultimap.Builder<String, IJobConfiguration> matches = ImmutableMultimap.builder();
    for (String managerId : jobStore.fetchManagerIds()) {
        for (IJobConfiguration job : jobStore.fetchJobs(managerId)) {
            if (job.getKey().equals(jobKey)) {
                matches.put(managerId, job);
            }/*from  ww w.  j av a2 s .  c  o  m*/
        }
    }
    return matches.build();
}

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

/**
 * Group the classes in the input jars into a multimap based on the APKModule they belong to
 *
 * @param apkModuleToJarPathMap the mapping of APKModules to the path for the jar files
 * @param translatorFunction function used to translate obfuscated names
 * @param filesystem filesystem representation for resolving paths
 * @return The mapping of APKModules to the class names they contain
 * @throws IOException/*www .ja v  a  2s  .co m*/
 */
public static ImmutableMultimap<APKModule, String> getAPKModuleToClassesMap(
        final ImmutableMultimap<APKModule, Path> apkModuleToJarPathMap,
        final Function<String, String> translatorFunction, final ProjectFilesystem filesystem)
        throws IOException {
    final ImmutableMultimap.Builder<APKModule, String> builder = ImmutableMultimap.builder();
    if (!apkModuleToJarPathMap.isEmpty()) {
        for (final APKModule dexStore : apkModuleToJarPathMap.keySet()) {
            for (Path jarFilePath : apkModuleToJarPathMap.get(dexStore)) {
                ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();
                classpathTraverser.traverse(new ClasspathTraversal(ImmutableSet.of(jarFilePath), filesystem) {
                    @Override
                    public void visit(FileLike entry) {
                        if (!entry.getRelativePath().endsWith(".class")) {
                            // ignore everything but class files in the jar.
                            return;
                        }

                        builder.put(dexStore, translatorFunction.apply(entry.getRelativePath()));
                    }
                });
            }
        }
    }
    return builder.build();
}

From source file:org.jclouds.rds.binders.BindInstanceRequestToFormParams.java

/**
 * {@inheritDoc}/*from   w ww.  j av a2 s.c  o m*/
 */
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    InstanceRequest instanceRequest = InstanceRequest.class
            .cast(checkNotNull(input, "instanceRequest must be set!"));

    ImmutableMultimap.Builder<String, String> formParameters = ImmutableMultimap.builder();

    formParameters.put("AllocatedStorage", instanceRequest.getAllocatedStorageGB() + "");
    formParameters.put("AutoMinorVersionUpgrade", instanceRequest.isAutoMinorVersionUpgrade() + "");
    formParameters.put("BackupRetentionPeriod", instanceRequest.getBackupRetentionPeriod() + "");
    if (instanceRequest.getCharacterSet().isPresent())
        formParameters.put("CharacterSetName", instanceRequest.getCharacterSet().get());
    formParameters.put("DBInstanceClass", instanceRequest.getInstanceClass());
    if (instanceRequest.getName().isPresent())
        formParameters.put("DBName", instanceRequest.getName().get());
    if (instanceRequest.getParameterGroup().isPresent())
        formParameters.put("DBParameterGroupName", instanceRequest.getParameterGroup().get());
    int groupIndex = 1;
    for (String securityGroup : instanceRequest.getSecurityGroups())
        formParameters.put("DBSecurityGroups.member." + groupIndex++, securityGroup);
    if (instanceRequest.getSubnetGroup().isPresent())
        formParameters.put("DBSubnetGroupName", instanceRequest.getSubnetGroup().get());
    formParameters.put("Engine", instanceRequest.getEngine());
    if (instanceRequest.getEngineVersion().isPresent())
        formParameters.put("EngineVersion", instanceRequest.getEngineVersion().get());
    if (instanceRequest.getLicenseModel().isPresent())
        formParameters.put("LicenseModel", instanceRequest.getLicenseModel().get());
    formParameters.put("MasterUserPassword", instanceRequest.getMasterPassword());
    formParameters.put("MasterUsername", instanceRequest.getMasterUsername());
    if (instanceRequest.getOptionGroup().isPresent())
        formParameters.put("OptionGroupName", instanceRequest.getOptionGroup().get());
    if (instanceRequest.getPort().isPresent())
        formParameters.put("Port", instanceRequest.getPort().get().toString());

    return (R) request.toBuilder().replaceFormParams(formParameters.build()).build();

}

From source file:co.freeside.betamax.message.httpclient.HttpMessageAdapter.java

@Override
public final Map<String, String> getHeaders() {
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    for (Header header : getDelegate().getAllHeaders()) {
        builder.put(header.getName(), header.getValue());
    }/* ww w. ja  v  a 2s . c o m*/
    return MultimapUtils.flatten(builder.build(), ", ");
}

From source file:org.apache.aurora.scheduler.async.preemptor.LiveClusterState.java

@Override
public Multimap<String, PreemptionVictim> getSlavesToActiveTasks() {
    // Only non-pending active tasks may be preempted.
    Iterable<IAssignedTask> activeTasks = Iterables.transform(Storage.Util.fetchTasks(storage, CANDIDATE_QUERY),
            SCHEDULED_TO_ASSIGNED);//from  w w w. ja  v a 2s  . c  o  m

    // Group the tasks by slave id so they can be paired with offers from the same slave.
    // Choosing to do this iteratively instead of using Multimaps.index/transform to avoid
    // generating a very large intermediate map.
    ImmutableMultimap.Builder<String, PreemptionVictim> tasksBySlave = ImmutableMultimap.builder();
    for (IAssignedTask task : activeTasks) {
        tasksBySlave.put(task.getSlaveId(), PreemptionVictim.fromTask(task));
    }
    return tasksBySlave.build();
}

From source file:org.jclouds.cloudwatch.binders.AlarmNamesBinder.java

@SuppressWarnings("unchecked")
@Override// ww w.  ja  v a 2 s. c  o m
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    Iterable<String> alarmNames = (Iterable<String>) checkNotNull(input, "alarm names must be set");
    ImmutableMultimap.Builder<String, String> formParameters = ImmutableMultimap.builder();
    int alarmNameIndex = 1;

    for (String alarmName : alarmNames) {
        formParameters.put("AlarmNames.member." + alarmNameIndex, alarmName);
        alarmNameIndex++;
    }

    return (R) request.toBuilder().replaceFormParams(formParameters.build()).build();
}

From source file:org.jclouds.elb.binders.BindListenersToFormParams.java

/**
 * {@inheritDoc}/*from w  w  w. ja va  2  s  .c  om*/
 */
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    Iterable<Listener> listeners = checkNotNull(input, "listeners must be set!") instanceof Listener
            ? ImmutableSet.of(Listener.class.cast(input))
            : (Iterable<Listener>) input;

    ImmutableMultimap.Builder<String, String> formParameters = ImmutableMultimap.builder();
    int listenerIndex = 1;

    for (Listener listener : listeners) {
        formParameters.put("Listeners.member." + listenerIndex + ".LoadBalancerPort", listener.getPort() + "");
        formParameters.put("Listeners.member." + listenerIndex + ".InstancePort",
                listener.getInstancePort() + "");
        formParameters.put("Listeners.member." + listenerIndex + ".Protocol", listener.getProtocol() + "");
        formParameters.put("Listeners.member." + listenerIndex + ".InstanceProtocol",
                listener.getInstanceProtocol() + "");
        if (listener.getSSLCertificateId().isPresent())
            formParameters.put("Listeners.member." + listenerIndex + ".SSLCertificateId",
                    listener.getSSLCertificateId().get() + "");
        listenerIndex++;
    }

    return (R) request.toBuilder().replaceFormParams(formParameters.build()).build();

}