Example usage for com.google.common.collect ImmutableMap.Builder putAll

List of usage examples for com.google.common.collect ImmutableMap.Builder putAll

Introduction

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

Prototype

public final void putAll(Map<? extends K, ? extends V> map) 

Source Link

Usage

From source file:no.ssb.vtl.script.expressions.FunctionExpression.java

@VisibleForTesting
static Map<String, VTLExpression> mergeArguments(VTLFunction.Signature signature, List<VTLExpression> arguments,
        Map<String, VTLExpression> namedArguments) {

    // Check unnamed arguments count.
    checkArgument(arguments.size() <= signature.size(), TOO_MANY_ARGUMENTS, signature.size(), arguments.size());

    ImmutableMap.Builder<String, VTLExpression> builder = ImmutableMap.builder();

    // Match the list with the signature names.
    Iterator<String> namesIterator = signature.keySet().iterator();
    for (VTLExpression argument : arguments) {
        builder.put(namesIterator.next(), argument);
    }//from   w w w .  j a v a2  s. c o m

    // Check for duplicates
    Set<String> duplicates = Sets.intersection(namedArguments.keySet(), builder.build().keySet());
    checkArgument(duplicates.isEmpty(), DUPLICATE_ARGUMENTS, String.join(", ", duplicates));

    ImmutableMap<String, VTLExpression> computedArguments = builder.putAll(namedArguments).build();

    // Check for unknown arguments.
    Set<String> unknown = Sets.difference(computedArguments.keySet(), signature.keySet());
    checkArgument(unknown.isEmpty(), UNKNOWN_ARGUMENTS, String.join(", ", unknown));

    // Check for missing arguments
    Set<String> required = Maps.filterValues(signature, VTLFunction.Argument::isRequired).keySet();
    Set<String> missing = Sets.difference(required, computedArguments.keySet());
    checkArgument(missing.isEmpty(), MISSING_ARGUMENTS, String.join(", ", missing));

    return computedArguments;
}

From source file:org.apache.beam.runners.fnexecution.control.ProcessBundleDescriptors.java

private static ExecutableProcessBundleDescriptor fromExecutableStageInternal(String id, ExecutableStage stage,
        ApiServiceDescriptor dataEndpoint, @Nullable ApiServiceDescriptor stateEndpoint) throws IOException {
    // Create with all of the processing transforms, and all of the components.
    // TODO: Remove the unreachable subcomponents if the size of the descriptor matters.
    Map<String, PTransform> stageTransforms = stage.getTransforms().stream()
            .collect(Collectors.toMap(PTransformNode::getId, PTransformNode::getTransform));

    Components.Builder components = stage.getComponents().toBuilder().clearTransforms()
            .putAllTransforms(stageTransforms);

    ImmutableMap.Builder<String, RemoteInputDestination<WindowedValue<?>>> inputDestinationsBuilder = ImmutableMap
            .builder();//from  w  w  w .  j  a  v  a2 s  . co m
    ImmutableMap.Builder<Target, Coder<WindowedValue<?>>> outputTargetCodersBuilder = ImmutableMap.builder();

    // The order of these does not matter.
    inputDestinationsBuilder.put(stage.getInputPCollection().getId(),
            addStageInput(dataEndpoint, stage.getInputPCollection(), components));

    outputTargetCodersBuilder.putAll(addStageOutputs(dataEndpoint, stage.getOutputPCollections(), components));

    Map<String, Map<String, SideInputSpec>> sideInputSpecs = addSideInputs(stage, components);

    Map<String, Map<String, BagUserStateSpec>> bagUserStateSpecs = forBagUserStates(stage, components.build());

    Map<String, Map<String, TimerSpec>> timerSpecs = forTimerSpecs(dataEndpoint, stage, components,
            inputDestinationsBuilder, outputTargetCodersBuilder);

    // Copy data from components to ProcessBundleDescriptor.
    ProcessBundleDescriptor.Builder bundleDescriptorBuilder = ProcessBundleDescriptor.newBuilder().setId(id);
    if (stateEndpoint != null) {
        bundleDescriptorBuilder.setStateApiServiceDescriptor(stateEndpoint);
    }

    bundleDescriptorBuilder.putAllCoders(components.getCodersMap())
            .putAllEnvironments(components.getEnvironmentsMap())
            .putAllPcollections(components.getPcollectionsMap())
            .putAllWindowingStrategies(components.getWindowingStrategiesMap())
            .putAllTransforms(components.getTransformsMap());

    return ExecutableProcessBundleDescriptor.of(bundleDescriptorBuilder.build(),
            inputDestinationsBuilder.build(), outputTargetCodersBuilder.build(), sideInputSpecs,
            bagUserStateSpecs, timerSpecs);
}

From source file:com.facebook.buck.features.go.CGoLibrary.java

private static HeaderSymlinkTree getHeaderSymlinkTree(BuildTarget buildTarget,
        ProjectFilesystem projectFilesystem, SourcePathRuleFinder ruleFinder, ActionGraphBuilder graphBuilder,
        CxxPlatform cxxPlatform, Iterable<BuildTarget> cxxDeps, ImmutableMap<Path, SourcePath> headers) {

    ImmutableList<BuildRule> cxxDepsRules = Streams.stream(cxxDeps).map(graphBuilder::requireRule)
            .collect(ImmutableList.toImmutableList());

    Collection<CxxPreprocessorInput> cxxPreprocessorInputs = CxxPreprocessables
            .getTransitiveCxxPreprocessorInput(cxxPlatform, graphBuilder, cxxDepsRules);

    ImmutableMap.Builder<Path, SourcePath> allHeaders = ImmutableMap.builder();

    // scan CxxDeps for headers and add them to allHeaders
    HashMap<Path, SourcePath> cxxDepsHeaders = new HashMap<Path, SourcePath>();
    cxxPreprocessorInputs.stream().flatMap(input -> input.getIncludes().stream())
            .filter(header -> header instanceof CxxSymlinkTreeHeaders)
            .flatMap(header -> ((CxxSymlinkTreeHeaders) header).getNameToPathMap().entrySet().stream())
            .forEach(entry -> cxxDepsHeaders.put(entry.getKey(), entry.getValue()));
    allHeaders.putAll(cxxDepsHeaders);

    // add headers defined within the cgo_library rule
    allHeaders.putAll(headers);/* ww w.j a  va  2  s  . co  m*/

    return CxxDescriptionEnhancer.createHeaderSymlinkTree(buildTarget, projectFilesystem, ruleFinder,
            graphBuilder, cxxPlatform, allHeaders.build(), HeaderVisibility.PUBLIC, true);
}

From source file:com.google.api.codegen.config.GapicProductConfig.java

private static ImmutableMap<String, FieldConfig> createResponseFieldConfigMap(
        ResourceNameMessageConfigs messageConfig,
        ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) {

    ImmutableMap.Builder<String, FieldConfig> builder = ImmutableMap.builder();
    if (messageConfig == null) {
        return builder.build();
    }/*from ww  w . ja  va 2 s  . co m*/
    Map<String, FieldConfig> map = new HashMap<>();
    for (FieldModel field : messageConfig.getFieldsWithResourceNamesByMessage().values()) {
        map.put(field.getFullName(), FieldConfig.createMessageFieldConfig(messageConfig, resourceNameConfigs,
                field, ResourceNameTreatment.STATIC_TYPES));
    }
    builder.putAll(map);
    return builder.build();
}

From source file:com.facebook.buck.cxx.CxxDescriptionEnhancer.java

private static void putAllSources(ImmutableSortedSet<SourceWithFlags> sourcesWithFlags,
        ImmutableMap.Builder<String, SourceWithFlags> sources, SourcePathResolver pathResolver,
        BuildTarget buildTarget) {/*from  ww  w  . j ava2  s. c  o m*/
    sources.putAll(pathResolver.getSourcePathNames(buildTarget, "srcs", sourcesWithFlags,
            SourceWithFlags::getSourcePath));
}

From source file:com.github.rinde.dynurg.Generator.java

static void writePropertiesFile(Scenario scen, StatisticalSummary urgency, double dynamism,
        String problemClassId, String instanceId, GeneratorSettings settings, String fileName) {
    final DateTimeFormatter formatter = ISODateTimeFormat.dateHourMinuteSecondMillis();

    final ImmutableMap.Builder<String, Object> properties = ImmutableMap.<String, Object>builder()
            .put("problem_class", problemClassId).put("id", instanceId).put("dynamism", dynamism)
            .put("urgency_mean", urgency.getMean()).put("urgency_sd", urgency.getStandardDeviation())
            .put("creation_date", formatter.print(System.currentTimeMillis()))
            .put("creator", System.getProperty("user.name")).put("day_length", settings.dayLength)
            .put("office_opening_hours", settings.officeHours);

    properties.putAll(settings.properties);

    final ImmutableMultiset<Enum<?>> eventTypes = Metrics.getEventTypeCounts(scen);
    for (final Multiset.Entry<Enum<?>> en : eventTypes.entrySet()) {
        properties.put(en.getElement().name(), en.getCount());
    }/*  w w  w . ja  va2 s.  c  om*/

    try {
        Files.write(Joiner.on("\n").withKeyValueSeparator(" = ").join(properties.build()),
                new File(fileName + ".properties"), Charsets.UTF_8);
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.facebook.buck.cxx.CxxDescriptionEnhancer.java

/**
 * Resolves the headers in `sourceList` and puts them into `sources` for the specificed
 * `buildTarget`.//from www  .  ja  va2  s.  co  m
 */
public static void putAllHeaders(SourceList sourceList, ImmutableMap.Builder<String, SourcePath> sources,
        SourcePathResolver sourcePathResolver, String parameterName, BuildTarget buildTarget) {
    switch (sourceList.getType()) {
    case NAMED:
        sources.putAll(sourceList.getNamedSources().get());
        break;
    case UNNAMED:
        sources.putAll(sourcePathResolver.getSourcePathNames(buildTarget, parameterName,
                sourceList.getUnnamedSources().get()));
        break;
    }
}

From source file:co.cask.cdap.cli.util.ArgumentParser.java

/**
 * Parses params from optional part./*  w  w  w .  j av  a  2 s  . c o  m*/
 *
 * @param splitInput optional part to be parsed
 * @param pattern pattern by which to parse
 * @return parsed params
 */
private static Map<String, String> parseOptional(List<String> splitInput, String pattern) {
    ImmutableMap.Builder<String, String> args = ImmutableMap.builder();

    List<String> copyInput = new ArrayList<>(splitInput);
    List<String> splitPattern = Parser.parsePattern(pattern);

    while (!splitPattern.isEmpty()) {
        if (copyInput.isEmpty()) {
            return Collections.emptyMap();
        }
        String patternPart = splitPattern.get(0);
        String inputPart = tryGetInputEntry(copyInput.get(0));
        if (patternPart.startsWith((Character.toString(MANDATORY_ARG_BEGINNING)))
                && patternPart.endsWith((Character.toString(MANDATORY_ARG_ENDING)))) {
            args.put(getEntry(patternPart), inputPart);
        } else if (patternPart.startsWith((Character.toString(OPTIONAL_PART_BEGINNING)))
                && patternPart.endsWith((Character.toString(OPTIONAL_PART_ENDING)))) {
            args.putAll(parseOptional(copyInput, getEntry(patternPart)));
        } else if (!patternPart.equals(inputPart)) {
            return Collections.emptyMap();
        }
        splitPattern.remove(0);
        copyInput.remove(0);
    }

    splitInput.clear();
    splitInput.addAll(copyInput);
    return args.build();
}

From source file:org.jclouds.elasticstack.functions.DriveDataToMap.java

@Override
public Map<String, String> apply(DriveData from) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    builder.putAll(baseDriveToMap.apply(from));
    return builder.build();
}

From source file:io.appium.java_client.imagecomparison.OccurrenceMatchingOptions.java

@Override
public Map<String, Object> build() {
    final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    builder.putAll(super.build());
    ofNullable(threshold).map(x -> builder.put("threshold", x));
    return builder.build();
}