List of usage examples for com.google.common.collect ImmutableMap.Builder putAll
public final void putAll(Map<? extends K, ? extends V> map)
From source file:com.dopsun.msg4j.tools.model.yaml.YamlModelInfo.java
YamlModelInfo(Map<String, Object> input) { Objects.requireNonNull(input); ImmutableMap.Builder<String, String> optionsBuilder = ImmutableMap.builder(); ImmutableList.Builder<ConstInfo> constsBuilder = ImmutableList.builder(); ImmutableList.Builder<FieldInfo> fieldsBuilder = ImmutableList.builder(); ImmutableList.Builder<MessageInfo> messagesBuilder = ImmutableList.builder(); ImmutableList.Builder<MessageInfo> finalMessagesBuilder = ImmutableList.builder(); if (input.containsKey("options")) { @SuppressWarnings("unchecked") Map<String, String> inputOptions = (Map<String, String>) input.get("options"); optionsBuilder.putAll(inputOptions); }//from w ww.j a v a 2 s .c om if (input.containsKey("consts")) { @SuppressWarnings("unchecked") List<Map<String, String>> inputConsts = (List<Map<String, String>>) input.get("consts"); for (Map<String, String> inputConst : inputConsts) { YamlConstInfo yamlConstInfo = new YamlConstInfo(inputConst); constsBuilder.add(yamlConstInfo); } } if (input.containsKey("fields")) { @SuppressWarnings("unchecked") List<Map<String, String>> inputFields = (List<Map<String, String>>) input.get("fields"); for (Map<String, String> inputField : inputFields) { YamlFieldInfo yamlFieldInfo = new YamlFieldInfo(inputField); if (fieldByName.containsKey(yamlFieldInfo.getName())) { throw new RuntimeException("Duplciated field name detected: " + yamlFieldInfo.getName()); } fieldByName.put(yamlFieldInfo.getName(), yamlFieldInfo); fieldsBuilder.add(yamlFieldInfo); } } if (input.containsKey("messages")) { @SuppressWarnings("unchecked") List<Map<String, Object>> inputMessages = (List<Map<String, Object>>) input.get("messages"); for (Map<String, Object> inputMessage : inputMessages) { YamlMessageInfo yamlMessageInfo = new YamlMessageInfo(this, inputMessage); if (messageByName.containsKey(yamlMessageInfo.getName())) { throw new RuntimeException("Duplciated message name detected: " + yamlMessageInfo.getName()); } messageByName.put(yamlMessageInfo.getName(), yamlMessageInfo); messagesBuilder.add(yamlMessageInfo); if (!yamlMessageInfo.isAbstract()) { finalMessagesBuilder.add(yamlMessageInfo); } } } options = optionsBuilder.build(); consts = constsBuilder.build(); fields = fieldsBuilder.build(); messages = messagesBuilder.build(); finalMessages = finalMessagesBuilder.build(); String optMessageTypeFieldName = options.get("messageTypeField"); if (optMessageTypeFieldName == null) { optMessageTypeFieldName = "MessageType"; } if (!fieldByName.containsKey(optMessageTypeFieldName)) { throw new RuntimeException("Option 'messageTypeField' not found."); } this.messageTypeField = fieldByName.get(optMessageTypeFieldName); }
From source file:com.b2international.snowowl.snomed.datastore.id.cis.CisSnomedIdentifierService.java
@Override public Map<String, SctId> getSctIds(final Set<String> componentIds) { final Map<String, SctId> existingIdsMap = readSctIds(componentIds); if (existingIdsMap.size() == componentIds.size()) { return existingIdsMap; } else {/* w w w . ja v a 2s . c om*/ final Set<String> knownComponentIds = existingIdsMap.keySet(); final Set<String> difference = ImmutableSet.copyOf(Sets.difference(componentIds, knownComponentIds)); final ImmutableMap.Builder<String, SctId> resultBuilder = ImmutableMap.builder(); resultBuilder.putAll(existingIdsMap); for (final String componentId : difference) { resultBuilder.put(componentId, buildSctId(componentId, IdentifierStatus.AVAILABLE)); } return resultBuilder.build(); } }
From source file:co.cask.common.cli.CommandMatch.java
/** * Parse arguments from the input and command pattern. * * @param input the input/*from w w w . ja v a 2s .c om*/ * @param pattern the command pattern * @return parsed arguments */ private Arguments parseArguments(String input, String pattern) { ImmutableMap.Builder<String, String> args = ImmutableMap.builder(); List<String> splitInput = Parser.parseInput(input); List<String> splitPattern = Parser.parsePattern(pattern); while (!splitInput.isEmpty()) { if (splitPattern.isEmpty()) { throw new IllegalArgumentException("Expected format: " + command.getPattern()); } String patternPart = splitPattern.get(0); String inputPart = processInputArgument(splitInput.get(0)); if (patternPart.startsWith((Character.toString(OPTIONAL_PART_BEGINNING))) && patternPart.endsWith((Character.toString(OPTIONAL_PART_ENDING)))) { args.putAll(parseOptional(splitInput, getEntry(patternPart))); } else { if (patternPart.startsWith((Character.toString(MANDATORY_ARG_BEGINNING))) && patternPart.endsWith((Character.toString(MANDATORY_ARG_ENDING)))) { args.put(getEntry(patternPart), inputPart); } else if (!patternPart.equals(inputPart)) { throw new IllegalArgumentException("Expected format: " + command.getPattern()); } splitInput.remove(0); } splitPattern.remove(0); } return new Arguments(args.build(), input); }
From source file:io.soliton.shapeshifter.NamedSchema.java
/** * Returns a schema that will output an extra constant field in the JSON * serialization./*from w w w . j a v a 2 s . co m*/ * * @param key the key of the field to output * @param value the value of the field to output */ public NamedSchema addConstant(String key, String value) { Preconditions.checkNotNull(key); Preconditions.checkArgument(!has(key)); ImmutableMap.Builder<String, String> constantsCopy = ImmutableMap.builder(); constantsCopy.putAll(constants); constantsCopy.put(key, value); return new NamedSchema(descriptor, name, skippedFields, constantsCopy.build(), enumCaseFormat, substitutions, transforms, mappings, descriptions, subObjectSchemas, formats, treatLongsAsStrings); }
From source file:io.soliton.shapeshifter.NamedSchema.java
/** * Returns a new schema in which the given field with have a format * attribute./*from w w w . ja v a2s. c o m*/ * * @param fieldName the name of the field to specify a format for * @param format the format of the property */ public NamedSchema setFormat(String fieldName, String format) { Preconditions.checkNotNull(fieldName); Preconditions.checkNotNull(format); Preconditions.checkArgument(!format.isEmpty() && !CharMatcher.WHITESPACE.matchesAllOf(format)); Preconditions.checkState(has(fieldName)); ImmutableMap.Builder<String, String> formatsCopy = ImmutableMap.builder(); formatsCopy.putAll(formats); formatsCopy.put(fieldName, format); return new NamedSchema(descriptor, name, skippedFields, constants, enumCaseFormat, substitutions, transforms, mappings, descriptions, subObjectSchemas, formatsCopy.build(), treatLongsAsStrings); }
From source file:com.nesscomputing.cache.MemcacheProvider.java
@Override public Map<String, Boolean> add(final String namespace, final Collection<CacheStore<byte[]>> stores, @Nullable CacheStatistics cacheStatistics) { ImmutableMap.Builder<String, Boolean> builder = ImmutableMap.builder(); List<CacheStore<byte[]>> validStores = Lists.newArrayListWithExpectedSize(stores.size()); for (CacheStore<byte[]> store : stores) { if (validateWrite(store)) { validStores.add(store);/*ww w .ja va 2 s .co m*/ } else { builder.put(Maps.immutableEntry(store.getKey(), false)); } } if (cacheStatistics != null) { cacheStatistics.incrementOversizedStores(stores.size() - validStores.size()); } builder.putAll(processOps(namespace, true, validStores, ADD_CALLBACK)); return builder.build(); }
From source file:io.soliton.shapeshifter.NamedSchema.java
/** * Returns a new schema in which {@code fieldName} will be documented. * * @param fieldName the name of the field to document * @param description the documentation of the field *//*from w ww.j a v a2 s . c o m*/ public NamedSchema describe(String fieldName, String description) { Preconditions.checkNotNull(fieldName); Preconditions.checkNotNull(description); Preconditions.checkState(has(fieldName)); ImmutableMap.Builder<String, String> descriptionsCopy = ImmutableMap.builder(); descriptionsCopy.putAll(descriptions); descriptionsCopy.put(fieldName, description); return new NamedSchema(descriptor, name, skippedFields, constants, enumCaseFormat, substitutions, transforms, mappings, descriptionsCopy.build(), subObjectSchemas, formats, treatLongsAsStrings); }
From source file:io.soliton.shapeshifter.NamedSchema.java
/** * Returns a schema that will substitute a given field name in the * serialized JSON./*ww w .ja va 2 s . c o m*/ * <p/> * <p>The substituted name remains subject to the configured case formatting. * * @param fieldName the name of the field to substitute * @param substitution the string to use for the substitution */ public NamedSchema substitute(String fieldName, String substitution) { Preconditions.checkNotNull(fieldName); Preconditions.checkArgument(has(fieldName)); Preconditions.checkNotNull(substitution); ImmutableMap.Builder<String, String> substitutionsCopy = ImmutableMap.builder(); substitutionsCopy.putAll(substitutions); substitutionsCopy.put(fieldName, substitution); return new NamedSchema(descriptor, name, skippedFields, constants, enumCaseFormat, substitutionsCopy.build(), transforms, mappings, descriptions, subObjectSchemas, formats, treatLongsAsStrings); }
From source file:io.soliton.shapeshifter.NamedSchema.java
/** * Returns a new schema in which the given field will be delegated to the * specified schema./*w ww. java 2 s . co m*/ * <p/> * <p>The field must be a submessage and its type must match that of * {@code schema}. * * @param fieldName the name of the field, which must be of object type * @param schemaName the name of the schema to delegate this field to */ public NamedSchema useSchema(String fieldName, String schemaName) { Preconditions.checkNotNull(fieldName); Preconditions.checkNotNull(schemaName); Preconditions.checkState(has(fieldName)); FieldDescriptor field = fields.get(fieldName); Preconditions.checkArgument(Type.MESSAGE.equals(field.getType())); ImmutableMap.Builder<String, String> subObjectSchemasCopy = ImmutableMap.builder(); subObjectSchemasCopy.putAll(subObjectSchemas); subObjectSchemasCopy.put(fieldName, schemaName); return new NamedSchema(descriptor, name, skippedFields, constants, enumCaseFormat, substitutions, transforms, mappings, descriptions, subObjectSchemasCopy.build(), formats, treatLongsAsStrings); }
From source file:io.soliton.shapeshifter.NamedSchema.java
/** * Returns a schema that will transforms the given field's value, with an * added format specified in the resulting JSON Schema. * * @param fieldName the name of the field to transform * @param transformer the transformation to apply *//*ww w . j ava 2 s. c om*/ public NamedSchema transform(String fieldName, FormatTransformer transformer) { Preconditions.checkNotNull(fieldName); Preconditions.checkArgument(has(fieldName)); Preconditions.checkNotNull(transformer); ImmutableMap.Builder<String, FormatTransformer> transformsCopy = ImmutableMap.builder(); transformsCopy.putAll(transforms); transformsCopy.put(fieldName, transformer); return new NamedSchema(descriptor, name, skippedFields, constants, enumCaseFormat, substitutions, transformsCopy.build(), mappings, descriptions, subObjectSchemas, formats, treatLongsAsStrings); }