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

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

Introduction

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

Prototype

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

Source Link

Usage

From source file:com.opengamma.strata.basics.index.FloatingRateNameIniLookup.java

private static ImmutableMap<String, FloatingRateName> parseIndices(IniFile ini) {
    ImmutableMap.Builder<String, FloatingRateName> builder = ImmutableMap.builder();
    parseSection(ini.section("ibor"), "-", FloatingRateType.IBOR, builder);
    parseSection(ini.section("overnightCompounded"), "", FloatingRateType.OVERNIGHT_COMPOUNDED, builder);
    parseSection(ini.section("overnightAveraged"), "", FloatingRateType.OVERNIGHT_AVERAGED, builder);
    parseSection(ini.section("price"), "", FloatingRateType.PRICE, builder);
    return builder.build();
}

From source file:org.sonar.core.issue.workflow.StateMachine.java

private StateMachine(Builder builder) {
    this.keys = ImmutableList.copyOf(builder.states);
    ImmutableMap.Builder<String, State> mapBuilder = ImmutableMap.builder();
    for (String stateKey : builder.states) {
        List<Transition> outTransitions = builder.outTransitions.get(stateKey);
        State state = new State(stateKey, outTransitions.toArray(new Transition[outTransitions.size()]));
        mapBuilder.put(stateKey, state);
    }/*www .  j  av  a 2s. co m*/
    byKey = mapBuilder.build();
}

From source file:com.ibm.og.http.HttpRequest.java

private HttpRequest(final Builder builder) {
    this.method = checkNotNull(builder.method);
    this.uri = checkNotNull(builder.uri);
    // recursively immutable copy
    final ImmutableMap.Builder<String, List<String>> queryParametersBuilder = ImmutableMap.builder();
    for (final Map.Entry<String, List<String>> entry : builder.queryParameters.entrySet()) {
        queryParametersBuilder.put(entry.getKey(),
                // cannot use ImmutableList.copyOf because it rejects null values
                // must take null values to support query parameter keys without values
                Collections.unmodifiableList(Lists.newArrayList(entry.getValue())));
    }/*from   ww  w  .ja va 2  s . co m*/
    this.queryParameters = queryParametersBuilder.build();
    this.requestHeaders = ImmutableMap.copyOf(builder.requestHeaders);
    this.body = checkNotNull(builder.body);
    this.context = ImmutableMap.copyOf(builder.context);
    this.operation = checkNotNull(builder.operation);
}

From source file:com.nesscomputing.config.FixedConfigModule.java

public FixedConfigModule(Map<String, String> configOverrides) {
    final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    builder.putAll(configOverrides);/*  ww w  .  j  a v  a 2  s  . c o m*/
    this.config = Config.getFixedConfig(new SystemConfiguration(), new MapConfiguration(builder.build()));
}

From source file:com.google.template.soy.internal.proto.Field.java

/** Returns the set of fields indexed by soy accessor name for the given type. */
public static <T extends Field> ImmutableMap<String, T> getFieldsForType(Descriptor descriptor,
        Set<FieldDescriptor> extensions, Factory<T> factory) {
    ImmutableMap.Builder<String, T> fields = ImmutableMap.builder();
    for (FieldDescriptor fieldDescriptor : descriptor.getFields()) {
        if (ProtoUtils.shouldJsIgnoreField(fieldDescriptor)) {
            continue;
        }/*from  w w  w  .  ja v a  2s.  c  o  m*/
        T field = factory.create(fieldDescriptor);
        fields.put(field.getName(), field);
    }

    SetMultimap<String, T> extensionsBySoyName = MultimapBuilder.hashKeys().hashSetValues().build();
    for (FieldDescriptor extension : extensions) {
        T field = factory.create(extension);
        extensionsBySoyName.put(field.getName(), field);
    }

    for (Map.Entry<String, Set<T>> group : Multimaps.asMap(extensionsBySoyName).entrySet()) {
        Set<T> ambiguousFields = group.getValue();
        String fieldName = group.getKey();
        if (ambiguousFields.size() == 1) {
            fields.put(fieldName, Iterables.getOnlyElement(ambiguousFields));
        } else {
            T value = factory.createAmbiguousFieldSet(ambiguousFields);
            logger.severe("Proto " + descriptor.getFullName() + " has multiple extensions with the name \""
                    + fieldName + "\": " + fullFieldNames(ambiguousFields)
                    + "\nThis field will not be accessible from soy");
            fields.put(fieldName, value);
        }
    }

    return fields.build();
}

From source file:com.palantir.common.streams.MoreCollectors.java

public static <T, K, V> Collector<T, ?, Map<K, V>> toImmutableMap(Function<T, K> keyFunction,
        Function<T, V> valueFunction) {
    return Collector.of(ImmutableMap::<K, V>builder,
            (builder, value) -> builder.put(keyFunction.apply(value), valueFunction.apply(value)),
            (left, right) -> left.putAll(right.build()), ImmutableMap.Builder::build);
}

From source file:org.terasology.dynamicCities.parcels.DynParcelTypeHandler.java

@Override
public PersistedData serialize(DynParcel parcel, SerializationContext context) {
    Map<String, PersistedData> data = new ImmutableMap.Builder()
            .put("height", context.create(parcel.getHeight()))
            .put("posX", context.create(parcel.getShape().minX()))
            .put("posY", context.create(parcel.getShape().minY()))
            .put("sizeX", context.create(parcel.getShape().sizeX()))
            .put("sizeY", context.create(parcel.getShape().sizeY()))
            .put("zone", context.create(parcel.getZone()))
            .put("orientation", context.create(parcel.getOrientation().name())).build();
    return context.create(data);
}

From source file:org.sonar.server.computation.task.projectanalysis.qualitymodel.RatingSettings.java

private static Map<String, LanguageSpecificConfiguration> buildLanguageSpecificConfigurationByLanguageKey(
        Settings settings) {/*  w ww.ja  v a  2 s.c  o m*/
    ImmutableMap.Builder<String, LanguageSpecificConfiguration> builder = ImmutableMap.builder();
    String[] languageConfigIndexes = settings.getStringArray(LANGUAGE_SPECIFIC_PARAMETERS);
    for (String languageConfigIndex : languageConfigIndexes) {
        String languagePropertyKey = LANGUAGE_SPECIFIC_PARAMETERS + "." + languageConfigIndex + "."
                + LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY;
        String languageKey = settings.getString(languagePropertyKey);
        if (languageKey == null) {
            throw MessageException.of(
                    "Technical debt configuration is corrupted. At least one language specific parameter has no Language key. "
                            + "Contact your administrator to update this configuration in the global administration section of SonarQube.");
        }
        builder.put(languageKey, LanguageSpecificConfiguration.create(settings, languageConfigIndex));
    }
    return builder.build();
}

From source file:ch.piratenpartei.pivote.serialize.handlers.MapHandler.java

@Override
public Object read(DataInput input) throws IOException {
    ImmutableMap.Builder<Object, Object> builder = ImmutableMap.builder();
    int size = input.readInt32();
    for (int i = 0; i < size; i++) {
        builder.put(keyHandler.read(input), valueHandler.read(input));
    }//from   w  w w .ja v a 2  s  . c o m
    return builder.build();
}

From source file:edu.mit.streamjit.util.CollectionUtils.java

/**
 * Returns the union of the given maps with disjoint key sets.
 * @param <K> the key type of the returned map
 * @param <V> the value type of the returned map
 * @param first the first map/*from w w w  . j a v  a  2  s .c  om*/
 * @param more more maps
 * @return a map containing all the entries in the given maps
 */
@SafeVarargs
public static <K, V> ImmutableMap<K, V> union(Map<? extends K, ? extends V> first,
        Map<? extends K, ? extends V>... more) {
    ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
    builder.putAll(first);
    for (Map<? extends K, ? extends V> m : more)
        builder.putAll(m);
    return builder.build();
}