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:com.isotrol.impe3.pms.core.support.SatisfiabilitySupport.java

/**
 * Constructor./* ww  w  .  j  a v  a  2  s  .  c  om*/
 * @param dfns Connector definitions.
 */
public SatisfiabilitySupport(Iterable<ModuleDefinition<?>> modules) {
    final SatisfiabilityGraph graph = new SatisfiabilityGraph(modules);
    final ImmutableMultimap.Builder<ModuleDefinition<?>, String> builder = ImmutableMultimap.builder();
    for (DependencyNode dn : graph.getDependencies()) {
        if (!graph.isSatisfiable(dn)) {
            builder.put(dn.module.module, dn.name);
        }
    }
    unsatisfiable = builder.build();
}

From source file:org.jetbrains.android.inspections.XmlWrongFileTypeInspection.java

@NotNull
public static ImmutableCollection<ResourceFolderType> determineResourceFolderTypeByRootTag(
        @NotNull AndroidFacet facet, @NotNull String tagName) {
    if (ourResourceFolderTypeMap == null) {
        // First time calling the function, need to initialize the map first
        final ImmutableMultimap.Builder<String, ResourceFolderType> builder = ImmutableMultimap.builder();
        for (String tag : AndroidAnimationUtils.getPossibleRoots()) {
            builder.put(tag, ResourceFolderType.ANIM);
        }/*from   w w  w. j a v a  2s. c om*/
        for (String tag : AndroidAnimatorUtil.getPossibleRoots()) {
            builder.put(tag, ResourceFolderType.ANIMATOR);
        }
        for (String tag : AndroidXmlResourcesUtil.getPossibleRoots(facet)) {
            builder.put(tag, ResourceFolderType.XML);
        }
        for (String tag : AndroidDrawableDomUtil.getPossibleRoots(facet)) {
            builder.put(tag, ResourceFolderType.DRAWABLE);
        }
        for (String tag : TransitionDomUtil.getPossibleRoots()) {
            builder.put(tag, ResourceFolderType.TRANSITION);
        }
        ourResourceFolderTypeMap = builder.build();
    }
    return ourResourceFolderTypeMap.get(tagName);
}

From source file:google.registry.tools.EppToolCommand.java

/**
 * Helper function for grouping sets of domain names into respective TLDs. Useful for batched
 * EPP calls when invoking commands (i.e. domain check) with sets of domains across multiple TLDs.
 *//*from   w w w  .  j  a  va 2s.c  o  m*/
protected static Multimap<String, String> validateAndGroupDomainNamesByTld(List<String> names) {
    ImmutableMultimap.Builder<String, String> builder = new ImmutableMultimap.Builder<>();
    for (String name : names) {
        InternetDomainName tld = findTldForNameOrThrow(InternetDomainName.from(name));
        builder.put(tld.toString(), name);
    }
    return builder.build();
}

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

@SuppressWarnings("unchecked")
@Override//w  w w .j a v a  2 s .c  om
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof Map, "this binder is only valid for Map");
    Map<String, BlockDevice> blockDeviceMapping = (Map<String, BlockDevice>) input;
    Multimap<String, String> original = queryParser().apply(request.getPayload().getRawContent().toString());
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    builder.putAll("Action", "ModifyInstanceAttribute");
    int amazonOneBasedIndex = 1; // according to docs, counters must start with 1
    for (Entry<String, BlockDevice> ebsBlockDeviceName : blockDeviceMapping.entrySet()) {
        // not null by contract
        builder.put(format(deviceNamePattern, amazonOneBasedIndex), ebsBlockDeviceName.getKey());
        builder.put(format(deleteOnTerminationPattern, amazonOneBasedIndex),
                String.valueOf(ebsBlockDeviceName.getValue().isDeleteOnTermination()));
        builder.put(format(volumeIdPattern, amazonOneBasedIndex), ebsBlockDeviceName.getValue().getVolumeId());
        amazonOneBasedIndex++;
    }
    builder.putAll("InstanceId", original.get("InstanceId"));
    request.setPayload(newUrlEncodedFormPayload(builder.build()));
    return request;
}

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);// w w w .jav  a2 s . co 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.s3.binders.BindObjectMetadataToRequest.java

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

    ObjectMetadata md = ObjectMetadata.class.cast(input);
    checkArgument(md.getKey() != null, "objectMetadata.getKey() must be set!");

    request = metadataPrefixer.bindToRequest(request, md.getUserMetadata());

    Builder<String, String> headers = ImmutableMultimap.builder();
    if (md.getContentMetadata().getCacheControl() != null) {
        headers.put(HttpHeaders.CACHE_CONTROL, md.getContentMetadata().getCacheControl());
    }

    if (md.getContentMetadata().getContentDisposition() != null) {
        headers.put("Content-Disposition", md.getContentMetadata().getContentDisposition());
    }

    if (md.getContentMetadata().getContentEncoding() != null) {
        headers.put("Content-Encoding", md.getContentMetadata().getContentEncoding());
    }

    String contentLanguage = md.getContentMetadata().getContentLanguage();
    if (contentLanguage != null) {
        headers.put(HttpHeaders.CONTENT_LANGUAGE, contentLanguage);
    }

    if (md.getContentMetadata().getContentType() != null) {
        headers.put(HttpHeaders.CONTENT_TYPE, md.getContentMetadata().getContentType());
    } else {
        headers.put(HttpHeaders.CONTENT_TYPE, "binary/octet-stream");
    }

    if (md.getContentMetadata().getContentMD5() != null) {
        headers.put("Content-MD5", base64().encode(md.getContentMetadata().getContentMD5()));
    }

    return (R) request.toBuilder().replaceHeaders(headers.build()).build();
}

From source file:org.jclouds.aws.s3.binders.BindObjectMetadataToRequest.java

@SuppressWarnings("unchecked")
@Override//from www.  j  av a  2  s  .  c om
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof ObjectMetadata,
            "this binder is only valid for ObjectMetadata!");
    checkNotNull(request, "request");

    ObjectMetadata md = ObjectMetadata.class.cast(input);
    checkArgument(md.getKey() != null, "objectMetadata.getKey() must be set!");

    request = metadataPrefixer.bindToRequest(request, md.getUserMetadata());

    Builder<String, String> headers = ImmutableMultimap.builder();
    if (md.getCacheControl() != null) {
        headers.put(HttpHeaders.CACHE_CONTROL, md.getCacheControl());
    }

    if (md.getContentMetadata().getContentDisposition() != null) {
        headers.put("Content-Disposition", md.getContentMetadata().getContentDisposition());
    }

    if (md.getContentMetadata().getContentEncoding() != null) {
        headers.put("Content-Encoding", md.getContentMetadata().getContentEncoding());
    }
    if (md.getContentMetadata().getContentType() != null) {
        headers.put(HttpHeaders.CONTENT_TYPE, md.getContentMetadata().getContentType());
    } else {
        headers.put(HttpHeaders.CONTENT_TYPE, "binary/octet-stream");
    }

    if (md.getContentMetadata().getContentMD5() != null) {
        headers.put("Content-MD5", base64().encode(md.getContentMetadata().getContentMD5()));
    }

    return (R) request.toBuilder().replaceHeaders(headers.build()).build();
}

From source file:com.github.fge.jsonschema.keyword.validator.common.DependenciesValidator.java

public DependenciesValidator(final JsonNode digest) {
    super("dependencies");

    /*//from ww w  .j av  a2s .c  o m
     * Property dependencies
     */
    final ImmutableMultimap.Builder<String, String> mapBuilder = ImmutableMultimap.builder();
    final Map<String, JsonNode> map = JacksonUtils.asMap(digest.get("propertyDeps"));

    String key;
    for (final Map.Entry<String, JsonNode> entry : map.entrySet()) {
        key = entry.getKey();
        for (final JsonNode element : entry.getValue())
            mapBuilder.put(key, element.textValue());
    }

    propertyDeps = mapBuilder.build();

    /*
     * Schema dependencies
     */
    final ImmutableSet.Builder<String> setBuilder = ImmutableSet.builder();

    for (final JsonNode node : digest.get("schemaDeps"))
        setBuilder.add(node.textValue());

    schemaDeps = setBuilder.build();
}

From source file:co.cask.cdap.explore.jdbc.ExploreConnectionParams.java

/**
 * Parse Explore connection url string to retrieve the necessary parameters to connect to CDAP.
 *//*from w ww  . j a  v a2  s.  c o m*/
public static ExploreConnectionParams parseConnectionUrl(String url) {
    // URI does not accept two semicolons in a URL string, hence the substring
    URI jdbcURI = URI.create(url.substring(ExploreJDBCUtils.URI_JDBC_PREFIX.length()));
    String host = jdbcURI.getHost();
    int port = jdbcURI.getPort();
    ImmutableMultimap.Builder<ExploreConnectionParams.Info, String> builder = ImmutableMultimap.builder();

    // get the query params - javadoc for getQuery says that it decodes the query URL with UTF-8 charset.
    String query = jdbcURI.getQuery();
    if (query != null) {
        for (String entry : Splitter.on("&").split(query)) {
            // Need to do it twice because of error in guava libs Issue: 1577
            int idx = entry.indexOf('=');
            if (idx <= 0) {
                continue;
            }

            ExploreConnectionParams.Info info = ExploreConnectionParams.Info.fromStr(entry.substring(0, idx));
            if (info != null) {
                builder.putAll(info, Splitter.on(',').omitEmptyStrings().split(entry.substring(idx + 1)));
            }
        }
    }
    return new ExploreConnectionParams(host, port, builder.build());
}

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

/** For all the missing classes, represent the first chains that lead to the missing classes. */
public ImmutableMultimap<String, ClassInfo> getMissingClassesWithSubclasses() {
    ImmutableMultimap.Builder<String, ClassInfo> result = ImmutableMultimap.builder();
    getMissingClassesWithSubclasses(resolutionStartClass(), this.parentChains(), result);
    return result.build();
}