/**
   * Returns a newly-created {@code ListMetricsOptions} based on the contents of the {@code
   * Builder}.
   */
  @Override
  public Multimap<String, String> buildFormParameters() {
    ImmutableMultimap.Builder<String, String> formParameters =
        ImmutableMultimap.<String, String>builder();
    int dimensionIndex = 1;

    // If namespace isn't specified, don't include it
    if (namespace != null) {
      formParameters.put("Namespace", namespace);
    }
    // If metricName isn't specified, don't include it
    if (metricName != null) {
      formParameters.put("MetricName", metricName);
    }

    // If dimensions isn't specified, don't include it
    if (dimensions != null) {
      for (Dimension dimension : dimensions) {
        formParameters.put("Dimensions.member." + dimensionIndex + ".Name", dimension.getName());
        formParameters.put("Dimensions.member." + dimensionIndex + ".Value", dimension.getValue());
        dimensionIndex++;
      }
    }

    // If nextToken isn't specified, don't include it
    if (nextToken != null) {
      formParameters.put("NextToken", nextToken.toString());
    }

    return formParameters.build();
  }
Beispiel #2
0
  /**
   * Constructs the feature configuration from a {@code CToolchain} protocol buffer.
   *
   * @param toolchain the toolchain configuration as specified by the user.
   * @throws InvalidConfigurationException if the configuration has logical errors.
   */
  CcToolchainFeatures(CToolchain toolchain) throws InvalidConfigurationException {
    // Build up the feature graph.
    // First, we build up the map of name -> features in one pass, so that earlier features can
    // reference later features in their configuration.
    ImmutableList.Builder<Feature> features = ImmutableList.builder();
    HashMap<String, Feature> featuresByName = new HashMap<>();
    for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
      Feature feature = new Feature(toolchainFeature);
      features.add(feature);
      if (featuresByName.put(feature.getName(), feature) != null) {
        throw new InvalidConfigurationException(
            "Invalid toolchain configuration: feature '"
                + feature.getName()
                + "' was specified multiple times.");
      }
    }
    this.features = features.build();
    this.featuresByName = ImmutableMap.copyOf(featuresByName);

    // Next, we build up all forward references for 'implies' and 'requires' edges.
    ImmutableMultimap.Builder<Feature, Feature> implies = ImmutableMultimap.builder();
    ImmutableMultimap.Builder<Feature, ImmutableSet<Feature>> requires =
        ImmutableMultimap.builder();
    // We also store the reverse 'implied by' and 'required by' edges during this pass.
    ImmutableMultimap.Builder<Feature, Feature> impliedBy = ImmutableMultimap.builder();
    ImmutableMultimap.Builder<Feature, Feature> requiredBy = ImmutableMultimap.builder();
    for (CToolchain.Feature toolchainFeature : toolchain.getFeatureList()) {
      String name = toolchainFeature.getName();
      Feature feature = featuresByName.get(name);
      for (CToolchain.FeatureSet requiredFeatures : toolchainFeature.getRequiresList()) {
        ImmutableSet.Builder<Feature> allOf = ImmutableSet.builder();
        for (String requiredName : requiredFeatures.getFeatureList()) {
          Feature required = getFeatureOrFail(requiredName, name);
          allOf.add(required);
          requiredBy.put(required, feature);
        }
        requires.put(feature, allOf.build());
      }
      for (String impliedName : toolchainFeature.getImpliesList()) {
        Feature implied = getFeatureOrFail(impliedName, name);
        impliedBy.put(implied, feature);
        implies.put(feature, implied);
      }
    }
    this.implies = implies.build();
    this.requires = requires.build();
    this.impliedBy = impliedBy.build();
    this.requiredBy = requiredBy.build();
  }
 @Value.Derived
 public ImmutableMultimap<Response, ResponseSet> responsesToContainingResponseSets() {
   final ImmutableMultimap.Builder<Response, ResponseSet> ret = ImmutableMultimap.builder();
   for (final ResponseSet responseSet : responseSets()) {
     for (final Response response : responseSet) {
       ret.put(response, responseSet);
     }
   }
   return ret.build();
 }
 /**
  * Registers one or more prototype method in a single namespace. The pass is agnostic with
  * regard to the class whose prototype is being augmented. The {@code base} parameter
  * specifies the qualified namespace where all the {@code methods} reside. Each method is
  * expected to have a sibling named with the {@code $install} suffix. The method calls
  * themselves are not rewritten, but whenever one is detected, its installer(s) will be added
  * to the top of the source file whenever the output version is less than {@code
  * nativeVersion}. For example, defining {@code addMethods(ES6, ES5, "$jscomp.string",
  * "startsWith", "endsWith")} will cause {@code $jscomp.string.startsWith$install();} to be
  * added to any source file that calls, e.g. {@code foo.startsWith}.
  *
  * <p>If {@code base} is blank, then no polyfills will be installed. This is useful for
  * documenting unimplemented polyfills.
  */
 Builder addMethods(
     FeatureSet nativeVersion, FeatureSet polyfillVersion, String base, String... methods) {
   if (!base.isEmpty()) {
     for (String method : methods) {
       methodsBuilder.put(
           method,
           new Polyfill(
               nativeVersion, polyfillVersion, "", base + "." + method + "$install();"));
     }
   }
   // TODO(sdh): If base.isEmpty() then it means no polyfill is implemented.  Is there
   // any way we can warn if the output language is too low?  It's not likely, since
   // there's no good way to determine if it's actually intended as an ES6 method or
   // else is defined elsewhere.
   return this;
 }
 /**
  * Parses a text file which is supposed to be in the following format: "file_path_without_spaces
  * file_hash ...." i.e. it parses the first two columns of each line and ignores the rest of it.
  *
  * @return A multi map from the file hash to its path, which equals the raw path resolved against
  *     {@code resolvePathAgainst}.
  */
 @VisibleForTesting
 static ImmutableMultimap<String, Path> parseExopackageInfoMetadata(
     Path metadataTxt, Path resolvePathAgainst, ProjectFilesystem filesystem) throws IOException {
   ImmutableMultimap.Builder<String, Path> builder = ImmutableMultimap.builder();
   for (String line : filesystem.readLines(metadataTxt)) {
     // ignore lines that start with '.'
     if (line.startsWith(".")) {
       continue;
     }
     List<String> parts = Splitter.on(' ').splitToList(line);
     if (parts.size() < 2) {
       throw new RuntimeException("Illegal line in metadata file: " + line);
     }
     builder.put(parts.get(1), resolvePathAgainst.resolve(parts.get(0)));
   }
   return builder.build();
 }