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:com.facebook.buck.rules.coercer.AbstractBuildConfigFields.java

/**
 * @return A new {@link BuildConfigFields} with all of the fields from this object, combined with
 *     all of the fields from the specified {@code fields}. If both objects have fields with the
 *     same name, the entry from the {@code fields} parameter wins.
 *///from www.j  av  a2  s . c om
public BuildConfigFields putAll(BuildConfigFields fields) {

    ImmutableMap.Builder<String, Field> nameToFieldBuilder = ImmutableMap.builder();
    nameToFieldBuilder.putAll(fields.getNameToField());
    for (Field field : this.getNameToField().values()) {
        if (!fields.getNameToField().containsKey(field.getName())) {
            nameToFieldBuilder.put(field.getName(), field);
        }
    }
    return BuildConfigFields.of(nameToFieldBuilder.build());
}

From source file:com.hortonworks.streamline.streams.runtime.storm.spout.AvroStreamsSnapshotDeserializer.java

protected Object doDeserialize(InputStream payloadInputStream, byte protocolId, SchemaMetadata schemaMetadata,
        Integer writerSchemaVersion, Integer readerSchemaVersion) throws SerDesException {
    Object deserializedObj = super.doDeserialize(payloadInputStream, protocolId, schemaMetadata,
            writerSchemaVersion, readerSchemaVersion);

    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    Object values = convertValue(deserializedObj);
    if (values instanceof Map) {
        builder.putAll((Map) values);
    } else {/* w w w  . j  a v  a2  s  . com*/
        builder.put(StreamlineEvent.PRIMITIVE_PAYLOAD_FIELD, values);
    }

    return builder.build();
}

From source file:org.onosproject.net.driver.DefaultDriver.java

@Override
public Driver merge(Driver other) {
    checkArgument(parent == null || Objects.equals(parent, other.parent()), "Parent drivers are not the same");

    // Merge the behaviours.
    Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = Maps.newHashMap();
    behaviours.putAll(this.behaviours);
    other.behaviours().forEach(b -> behaviours.put(b, other.implementation(b)));

    // Merge the properties.
    ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
    properties.putAll(this.properties).putAll(other.properties());

    return new DefaultDriver(name, other.parent(), manufacturer, hwVersion, swVersion,
            ImmutableMap.copyOf(behaviours), properties.build());
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.score.scorers.ParseAnswerScorer.java

@Override
public Map<String, Double> score(JCas jcas, Answer answer) {
    Set<CandidateAnswerOccurrence> caos = TypeUtil.getCandidateAnswerVariants(answer).stream()
            .map(TypeUtil::getCandidateAnswerOccurrences).flatMap(Collection::stream).collect(toSet());
    ImmutableMap.Builder<String, Double> builder = ImmutableMap.builder();
    double[] depths = caos.stream().map(TypeUtil::getHeadTokenOfAnnotation).mapToDouble(CavUtil::getDepth)
            .toArray();//  w w w.j  a  v  a 2s.com
    builder.putAll(Scorer.generateSummaryFeatures(depths, "depth", "avg", "max", "min"));
    double[] constituentForests = caos.stream().map(
            cao -> CavUtil.isConstituentForest(CavUtil.getJCas(cao), JCasUtil.selectCovered(Token.class, cao)))
            .mapToDouble(value -> value ? 1.0 : 0.0).toArray();
    builder.putAll(Scorer.generateSummaryFeatures(constituentForests, "constituent-forest", "avg", "max", "min",
            "one-ratio", "any-one"));
    double[] constituents = caos.stream()
            .map(cao -> CavUtil.isConstituent(CavUtil.getJCas(cao), JCasUtil.selectCovered(Token.class, cao)))
            .mapToDouble(value -> value ? 1.0 : 0.0).toArray();
    builder.putAll(Scorer.generateSummaryFeatures(constituents, "constituent", "avg", "max", "min", "one-ratio",
            "any-one"));
    return builder.build();
}

From source file:com.bendb.thrifty.schema.ServiceMethod.java

public ServiceMethod(FunctionElement element) {
    this.element = element;

    ImmutableList.Builder<Field> params = ImmutableList.builder();
    for (FieldElement field : element.params()) {
        params.add(new Field(field, FieldNamingPolicy.DEFAULT));
    }//www . j av  a 2  s.c  om
    this.paramTypes = params.build();

    ImmutableList.Builder<Field> exceptions = ImmutableList.builder();
    for (FieldElement field : element.exceptions()) {
        exceptions.add(new Field(field, FieldNamingPolicy.DEFAULT));
    }
    this.exceptionTypes = exceptions.build();

    ImmutableMap.Builder<String, String> annotationBuilder = ImmutableMap.builder();
    AnnotationElement anno = element.annotations();
    if (anno != null) {
        annotationBuilder.putAll(anno.values());
    }
    this.annotations = annotationBuilder.build();
}

From source file:com.bendb.thrifty.schema.Field.java

Field(FieldElement element, FieldNamingPolicy fieldNamingPolicy) {
    this.element = element;
    this.fieldNamingPolicy = fieldNamingPolicy;

    ImmutableMap.Builder<String, String> annotationBuilder = ImmutableMap.builder();
    AnnotationElement anno = element.annotations();
    if (anno != null) {
        annotationBuilder.putAll(anno.values());
    }// w  ww  .j  av a2 s .co  m
    this.annotations = annotationBuilder.build();
}

From source file:com.twitter.common.metrics.Metrics.java

@Override
public Map<String, Number> sample() {
    ImmutableMap.Builder<String, Number> samples = ImmutableMap.builder();
    samples.putAll(sampleGauges());
    samples.putAll(sampleCounters());/*  w  w w.j a v  a 2  s  . co  m*/
    for (Map.Entry<String, Snapshot> entry : sampleHistograms().entrySet()) {
        String name = entry.getKey();
        Snapshot snapshot = entry.getValue();
        samples.put(named(name, "count"), snapshot.count());
        samples.put(named(name, "sum"), snapshot.sum());
        samples.put(named(name, "avg"), snapshot.avg());
        samples.put(named(name, "min"), snapshot.min());
        samples.put(named(name, "max"), snapshot.max());
        samples.put(named(name, "stddev"), snapshot.stddev());
        for (Percentile p : snapshot.percentiles()) {
            String percentileName = named(name, gaugeName(p.getQuantile()));
            samples.put(percentileName, p.getValue());
        }
    }
    return samples.build();
}

From source file:com.facebook.buck.skylark.parser.AbstractBuckGlobals.java

/** Disable implicit native rules depending on configuration */
@Lazy//from w  ww. jav  a  2  s  . com
Environment.GlobalFrame getBuckBuildFileContextGlobals() {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    addBuckGlobals(builder);
    if (!getDisableImplicitNativeRules()) {
        builder.putAll(getBuckRuleFunctions());
    }
    Runtime.setupSkylarkLibrary(builder, SkylarkNativeModule.NATIVE_MODULE);
    addNativeModuleFunctions(builder);
    return GlobalFrame.createForBuiltins(builder.build());
}

From source file:com.bendb.thrifty.schema.StructType.java

StructType(StructElement element, ThriftType type, Map<NamespaceScope, String> namespaces,
        FieldNamingPolicy fieldNamingPolicy) {
    super(element.name(), namespaces);
    this.element = element;
    this.type = type;

    ImmutableList.Builder<Field> fieldsBuilder = ImmutableList.builder();
    for (FieldElement fieldElement : element.fields()) {
        fieldsBuilder.add(new Field(fieldElement, fieldNamingPolicy));
    }/* w w  w .j  av  a2  s.  c  o  m*/
    this.fields = fieldsBuilder.build();

    ImmutableMap.Builder<String, String> annotationBuilder = ImmutableMap.builder();
    AnnotationElement anno = element.annotations();
    if (anno != null) {
        annotationBuilder.putAll(anno.values());
    }
    this.annotations = annotationBuilder.build();
}

From source file:org.apache.gobblin.runtime.LimitingExtractorDecorator.java

/**
 * Compose meta data when limiter fails to acquire permit
 * The meta data key list is passed from source layer
 * A prefix matching is used because some work unit {@link org.apache.gobblin.source.workunit.MultiWorkUnit} have packing strategy, which
 * can append additional string after the key name
 *
 * @return String map representing all the meta data need to report. Return null if no meta data was found.
 *///from   w ww .  j  a v  a2  s.  co  m
private ImmutableMap<String, String> getLimiterStopMetadata() {
    WorkUnit workUnit = this.taskState.getWorkunit();
    Properties properties = workUnit.getProperties();

    String metadataKeyList = properties.getProperty(LimiterConfigurationKeys.LIMITER_REPORT_KEY_LIST,
            LimiterConfigurationKeys.DEFAULT_LIMITER_REPORT_KEY_LIST);
    List<String> keyList = Splitter.on(',').omitEmptyStrings().trimResults().splitToList(metadataKeyList);

    if (keyList.isEmpty())
        return ImmutableMap.of();

    Set<String> names = properties.stringPropertyNames();
    TreeMap<String, String> orderedProperties = new TreeMap<>();

    for (String name : names) {
        orderedProperties.put(name, properties.getProperty(name));
    }

    ImmutableMap.Builder builder = ImmutableMap.<String, String>builder();
    for (String oldKey : keyList) {
        builder.putAll(orderedProperties.subMap(oldKey, oldKey + Character.MAX_VALUE));
    }
    builder.put(LIMITER_STOP_CAUSE_KEY, LIMITER_STOP_CAUSE_VALUE);
    return builder.build();
}