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

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

Introduction

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

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Document

Returns a new builder.

Usage

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

/**
 * {@inheritDoc}/*from   ww w  . j ava  2  s.c  om*/
 */
@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:eu.eubrazilcc.lvl.core.entrez.GbFlatFileHelper.java

/**
 * Infers the possible countries of the species from which the DNA sequence was obtained and 
 * returns a map of Java {@link Locale} where the key of the map is the GenBank field that was
 * used to infer the country. The country is inferred from the annotations of the GenBank file 
 * format, using the fields in the following order:
 * <ol>/*from w ww . j av a  2 s.  c o  m*/
 * <li>If a /country entry exists in the FEATURES of the file, then this is returned to 
 * the caller and no other check is performed;</li>
 * <li>DEFINITION;</li>
 * <li>TITLE; or</li>
 * <li>Check PUBMED title and abstract fields.</li>
 * </ol>
 * Java {@link Locale} allows latter to export the country to several different formats, including a 
 * two-letter code compatible with ISO 3166-1 alpha-2 standard.
 * @param file - sequence file.
 * @return a Java {@link Locale} inferred from the sequence file.
 * @throws Exception if an error occurs.
 */
public static final ImmutableMultimap<GenBankField, Locale> inferCountry(final File file) throws Exception {
    checkArgument(file != null && file.canRead(), "Uninitialized or invalid file");
    final ImmutableMultimap.Builder<GenBankField, Locale> builder = new ImmutableMultimap.Builder<GenBankField, Locale>();
    // infer from features
    final Locale locale = getLocale(countryFeature(file));
    if (locale != null) {
        builder.put(GenBankField.COUNTRY_FEATURE, locale);
    } else {
        // infer from definition
        // TODO

        // infer from title
        // TODO

        // infer from PubMed title and abstract fields
        // TODO
    }
    return builder.build();
}

From source file:co.cask.cdap.internal.app.runtime.service.http.DefaultHttpServiceRequest.java

/**
 * Instantiates the class from a {@link HttpRequest}
 *
 * @param request the request which will be bound to.
 *///from   ww w .  j a  va2 s .c  o m
DefaultHttpServiceRequest(HttpRequest request) {
    this.request = request;
    this.content = request.getContent().toByteBuffer();

    final ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    for (Map.Entry<String, String> header : request.getHeaders()) {
        builder.put(header);
    }
    this.headers = builder.build();
}

From source file:org.jclouds.ec2.binders.BindUserIdGroupPairToSourceSecurityGroupFormParams.java

@SuppressWarnings("unchecked")
@Override/*from   w  w  w  . j  a  v  a2s.  c  om*/
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof UserIdGroupPair,
            "this binder is only valid for UserIdGroupPair!");
    UserIdGroupPair pair = (UserIdGroupPair) input;
    Builder<String, String> builder = ImmutableMultimap.builder();
    builder.put("SourceSecurityGroupOwnerId", pair.getUserId());
    builder.put("SourceSecurityGroupName", pair.getGroupName());
    return (R) request.toBuilder().replaceFormParams(builder.build()).build();
}

From source file:com.google.devtools.build.importdeps.ResolutionFailureChain.java

private static void getMissingClassesWithSubclasses(ClassInfo subclass,
        ImmutableList<ResolutionFailureChain> parentChains,
        ImmutableMultimap.Builder<String, ClassInfo> result) {
    for (ResolutionFailureChain parentChain : parentChains) {
        if (parentChain.resolutionStartClass() == null) {
            checkState(parentChain.parentChains().isEmpty() && parentChain.missingClasses().size() == 1);
            result.put(parentChain.missingClasses().get(0), subclass);
        } else {//from  w  ww  .j  av  a  2  s . co  m
            checkState(!parentChain.parentChains().isEmpty());
            getMissingClassesWithSubclasses(parentChain.resolutionStartClass(), parentChain.parentChains(),
                    result);
        }
    }
}

From source file:org.jclouds.ec2.binders.BindS3UploadPolicyAndSignature.java

@SuppressWarnings("unchecked")
@Override//from  w ww . jav a  2 s .c o m
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    String encodedJson = base64().encode(checkNotNull(input, "json").toString().getBytes(UTF_8));
    Builder<String, String> builder = ImmutableMultimap.builder();
    builder.put("Storage.S3.UploadPolicy", encodedJson);
    String signature = signer.sign(encodedJson);
    builder.put("Storage.S3.UploadPolicySignature", signature);
    return (R) request.toBuilder().replaceFormParams(builder.build()).build();
}

From source file:com.github.tomakehurst.wiremock.http.HttpHeaders.java

public HttpHeaders(Iterable<HttpHeader> headers) {
    ImmutableMultimap.Builder<CaseInsensitiveKey, String> builder = ImmutableMultimap.builder();
    for (HttpHeader header : headers) {
        builder.putAll(caseInsensitive(header.key()), header.values());
    }/*w  w w  .  j av a2s  .  com*/

    this.headers = builder.build();
}

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

/**
 * {@inheritDoc}/*  w ww .  j av  a  2  s. co  m*/
 */
@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();

}

From source file:com.isotrol.impe3.api.PageURI.java

public PageURI add(PageURI uri) {
    if (uri == null) {
        return this;
    }/*w  ww. j  a  v  a2 s. c om*/
    final PathSegments _path = path.add(uri.path);
    final ImmutableMultimap.Builder<String, String> b = ImmutableMultimap.builder();
    b.putAll(parameters).putAll(uri.parameters);
    return new PageURI(_path, b.build());
}

From source file:org.apache.aurora.common.args.parsers.MultimapParser.java

@SuppressWarnings("unchecked")
@Override/* w ww.ja v a 2 s.  co m*/
Multimap<?, ?> doParse(ParserOracle parserOracle, String raw, List<Type> typeParams) {
    Type keyType = typeParams.get(0);
    Parser<?> keyParser = parserOracle.get(TypeToken.of(keyType));

    Type valueType = typeParams.get(1);
    Parser<?> valueParser = parserOracle.get(TypeToken.of(valueType));

    ImmutableMultimap.Builder<Object, Object> multimapBuilder = ImmutableMultimap.builder();
    for (String keyAndValue : Parsers.MULTI_VALUE_SPLITTER.split(raw)) {
        List<String> fields = ImmutableList.copyOf(KEY_VALUE_SPLITTER.split(keyAndValue));
        checkArgument(fields.size() == 2, "Failed to parse key/value pair: " + keyAndValue);
        multimapBuilder.put(keyParser.parse(parserOracle, keyType, fields.get(0)),
                valueParser.parse(parserOracle, valueType, fields.get(1)));
    }

    return multimapBuilder.build();
}