List of usage examples for com.google.common.collect ImmutableMap.Builder put
public final V put(K k, V v)
From source file:com.opengamma.strata.loader.csv.FxRatesCsvLoader.java
private static void parseSingle(Predicate<LocalDate> datePredicate, CharSource resource, Map<LocalDate, ImmutableMap.Builder<FxRateId, FxRate>> mutableMap) { try {// w ww .ja v a2s.c om CsvFile csv = CsvFile.of(resource, true); for (CsvRow row : csv.rows()) { String dateText = row.getField(DATE_FIELD); LocalDate date = LocalDate.parse(dateText); if (datePredicate.test(date)) { String currencyPairStr = row.getField(CURRENCY_PAIR_FIELD); String valueStr = row.getField(VALUE_FIELD); CurrencyPair currencyPair = CurrencyPair.parse(currencyPairStr); double value = Double.valueOf(valueStr); ImmutableMap.Builder<FxRateId, FxRate> builderForDate = mutableMap.computeIfAbsent(date, k -> ImmutableMap.builder()); builderForDate.put(FxRateId.of(currencyPair), FxRate.of(currencyPair, value)); } } } catch (RuntimeException ex) { throw new IllegalArgumentException( Messages.format("Error processing resource as CSV file: {}", resource), ex); } }
From source file:org.lealone.cluster.net.MessageIn.java
public static MessageIn<?> read(DataInput in, int version, int id) throws IOException { InetAddress from = CompactEndpointSerializationHelper.deserialize(in); MessagingService.Verb verb = MessagingService.Verb.values()[in.readInt()]; int parameterCount = in.readInt(); Map<String, byte[]> parameters; if (parameterCount == 0) { parameters = Collections.emptyMap(); } else {//w w w. ja v a2 s . c om ImmutableMap.Builder<String, byte[]> builder = ImmutableMap.builder(); for (int i = 0; i < parameterCount; i++) { String key = in.readUTF(); byte[] value = new byte[in.readInt()]; in.readFully(value); builder.put(key, value); } parameters = builder.build(); } int payloadSize = in.readInt(); IVersionedSerializer<?> serializer = MessagingService.verbSerializers.get(verb); if (serializer instanceof MessagingService.CallbackDeterminedSerializer) { CallbackInfo callback = MessagingService.instance().getRegisteredCallback(id); if (callback == null) { // reply for expired callback. we'll have to skip it. FileUtils.skipBytesFully(in, payloadSize); return null; } serializer = callback.serializer; } if (payloadSize == 0 || serializer == null) return new MessageIn<>(from, null, parameters, verb, version); Object payload = serializer.deserialize(in, version); return new MessageIn<>(from, payload, parameters, verb, version); }
From source file:com.sun.tools.hat.internal.lang.jruby12.JRubyObject.java
private static void getPropertiesFromPackedTable(List<JavaObject> packedVTable, ImmutableMap.Builder<String, JavaThing> builder) { int midway = packedVTable.size() / 2; for (int i = 0; i < midway; ++i) { String name = Models.getStringValue(packedVTable.get(i)); if (name == null) { return; }// www . j ava2 s .c om builder.put(name, packedVTable.get(i + midway)); } }
From source file:org.voltcore.utils.CoreUtils.java
public static <K, V> ImmutableMap<K, ImmutableList<V>> unmodifiableMapCopy(Map<K, List<V>> m) { ImmutableMap.Builder<K, ImmutableList<V>> builder = ImmutableMap.builder(); for (Map.Entry<K, List<V>> e : m.entrySet()) { builder.put(e.getKey(), ImmutableList.<V>builder().addAll(e.getValue()).build()); }//from w ww .ja va2s . c om return builder.build(); }
From source file:com.spectralogic.ds3cli.util.FileUtils.java
/** * Perform platform-specific normalization of path names as strings * use by bulk put//from w w w. jav a2s .co m * @param pipedFiles * @return normalized pathname mapped to path */ public static ImmutableMap<String, String> normalizedObjectNames(final ImmutableList<String> pipedFiles) { final ImmutableMap.Builder<String, String> map = ImmutableMap.builder(); for (final String fileName : pipedFiles) { map.put(normalizeObjectName(fileName), fileName); } return map.build(); }
From source file:blusunrize.immersiveengineering.client.models.ModelData.java
public static ImmutableMap<String, String> asMap(JsonObject obj, boolean cleanStrings) { ImmutableMap.Builder<String, String> ret = new Builder<>(); for (Entry<String, JsonElement> entry : obj.entrySet()) if (cleanStrings && entry.getValue().isJsonPrimitive() && entry.getValue().getAsJsonPrimitive().isString()) ret.put(entry.getKey(), entry.getValue().getAsString()); else/*from w ww .j av a 2s. c o m*/ ret.put(entry.getKey(), entry.getValue().toString()); return ret.build(); }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.BaseTypeAdapter.java
private static TypeWidget registerYQL(YQLType type, ImmutableMap.Builder<YQLType, TypeWidget> t, TypeWidget main, TypeWidget optional) { t.put(type, main); t.put(YQLOptionalType.create(type), optional); return optional; }
From source file:com.yahoo.yqlplus.api.types.Annotations.java
private static ImmutableMap.Builder<String, Object> updateBuilder(ImmutableMap.Builder<String, Object> builder, Object[] kvPairs) {/*from www. jav a 2 s . com*/ for (int i = 0; i < kvPairs.length; i += 2) { String key = (String) kvPairs[i]; Object value = checkType(kvPairs[i + 1]); builder.put(key, value); } return builder; }
From source file:com.palantir.typescript.text.PresentationReconciler.java
private static ImmutableMap<TokenClass, TextAttribute> createClassificationTextAttributes() { ImmutableMap.Builder<TokenClass, TextAttribute> classAttributes = ImmutableMap.builder(); classAttributes.put(TokenClass.COMMENT, new TextAttribute(Colors.getColor(Colors.COMMENT))); classAttributes.put(TokenClass.IDENTIFIER, new TextAttribute(Colors.getColor(Colors.IDENTIFIER))); classAttributes.put(TokenClass.KEYWORD, new TextAttribute(Colors.getColor(Colors.KEYWORD), null, SWT.BOLD)); classAttributes.put(TokenClass.NUMBER_LITERAL, new TextAttribute(Colors.getColor(Colors.NUMBER_LITERAL))); classAttributes.put(TokenClass.OPERATOR, new TextAttribute(Colors.getColor(Colors.OPERATOR))); classAttributes.put(TokenClass.PUNCTUATION, new TextAttribute(Colors.getColor(Colors.PUNCTUATION))); classAttributes.put(TokenClass.REG_EXP_LITERAL, new TextAttribute(Colors.getColor(Colors.REG_EXP_LITERAL))); classAttributes.put(TokenClass.STRING_LITERAL, new TextAttribute(Colors.getColor(Colors.STRING_LITERAL))); classAttributes.put(TokenClass.WHITESPACE, new TextAttribute(Colors.getColor(Colors.WHITESPACE))); return classAttributes.build(); }
From source file:org.springframework.ide.eclipse.boot.templates.BootJavaContext.java
private static <T> Map<String, Predicate<T>> negate(ImmutableMap<String, Predicate<T>> base) { ImmutableMap.Builder<String, Predicate<T>> builder = ImmutableMap.builder(); builder.putAll(base);/* w w w. jav a 2 s . com*/ for (Entry<String, Predicate<T>> e : base.entrySet()) { String name = e.getKey(); if (!name.startsWith("!")) { builder.put("!" + name, e.getValue().negate()); } } return builder.build(); }