List of usage examples for java.util Map putIfAbsent
default V putIfAbsent(K key, V value)
From source file:com.yahoo.bullet.drpc.JoinBoltTest.java
public static final void enableMetadataInConfig(Map<String, Object> config, String metaConcept, String key) { List<Map<String, String>> metadataConfig = (List<Map<String, String>>) config .getOrDefault(BulletConfig.RESULT_METADATA_METRICS, new ArrayList<>()); Map<String, String> conceptConfig = new HashMap<>(); conceptConfig.put(BulletConfig.RESULT_METADATA_METRICS_CONCEPT_KEY, metaConcept); conceptConfig.put(BulletConfig.RESULT_METADATA_METRICS_NAME_KEY, key); metadataConfig.add(conceptConfig);//from www . j a v a 2 s . c o m config.put(BulletConfig.RESULT_METADATA_ENABLE, true); config.putIfAbsent(BulletConfig.RESULT_METADATA_METRICS, metadataConfig); }
From source file:de.micromata.genome.util.i18n.ChainedResourceBundleTranslationResolver.java
@Override public I18NTranslationProvider getTranslationFor(Locale locale) { Map<String, Object> entries = new HashMap<>(); for (String resId : resIds) { ResourceBundle resbundle = ResourceBundle.getBundle(resId, locale); for (String key : resbundle.keySet()) { entries.putIfAbsent(key, resbundle.getObject(key)); }/*w ww.j ava 2 s . c o m*/ } return new MapTranslationProvider(StringUtils.join(resIds, "_"), entries); }
From source file:com.quancheng.saluki.core.grpc.client.GrpcClientStrategy.java
private Map<String, Integer> cacheRetries(String[] methodNames, int reties) { Map<String, Integer> methodRetries = Maps.newConcurrentMap(); if (reties > 0) { if (methodNames != null && methodNames.length > 1) { for (String methodName : methodNames) { methodRetries.putIfAbsent(methodName, Integer.valueOf(reties)); }/* w w w .jav a2s .c o m*/ } else { methodRetries.putIfAbsent("*", Integer.valueOf(reties)); } } return methodRetries; }
From source file:org.codice.ddf.registry.schemabindings.helper.SlotTypeHelper.java
/** * This is a convenience method that will iterate through the List of SlotType1 provided and * return a mapping of SlotType1 name to a List of SlotType1s * If multiple slots share the same * name they will be added to the list/*ww w .j av a 2 s . co m*/ * * @param slots the list of SlotType1s to be mapped, null returns empty map * @return a mapping of SlotType1 name to List of SlotType1 */ public Map<String, List<SlotType1>> getNameSlotMapDuplicateSlotNamesAllowed(List<SlotType1> slots) { Map<String, List<SlotType1>> slotMap = new HashMap<>(); if (CollectionUtils.isNotEmpty(slots)) { for (SlotType1 slot : slots) { slotMap.putIfAbsent(slot.getName(), new ArrayList<>()); slotMap.get(slot.getName()).add(slot); } } return slotMap; }
From source file:org.codice.ddf.transformer.xml.streaming.lib.SaxEventHandlerUtils.java
/** * This method iterates through the attribute list provided and combines the values of common * attributes. The Attribute Descriptors are used to determine if the Attribute is permitted to * have multiple values.//from www . j a va2 s.c o m * * @param descriptors A set of attribute descriptors. Used to determine if the attribute can have * multiple values. If empty or null, a validation warning will be added to the attributes and * the attribute will default to not allow multiple values. * @param attributes The list of attributes to combine. * @return The list of attributes with multiple attribute values combined to a list on a single * attribute. Returns null or an empty list if the attribute list provided was null or empty. */ public List<Attribute> getCombinedMultiValuedAttributes(Set<AttributeDescriptor> descriptors, List<Attribute> attributes) { if (CollectionUtils.isEmpty(attributes)) { return attributes; } Map<String, Boolean> multiValuedMap = getMultiValuedNameMap(descriptors); List<String> validationWarnings = new ArrayList<>(); Map<String, Attribute> attributeMap = new HashMap<>(); for (Attribute attribute : attributes) { String attributeName = attribute.getName(); Attribute addedAttribute = attributeMap.putIfAbsent(attributeName, attribute); if (addedAttribute != null) { Boolean addValue = multiValuedMap.get(attributeName); if (addValue == null) { validationWarnings.add(String.format( "No attribute descriptor was found for attribute: '%s'. Handling the attribute as non-multi-valued.", attributeName)); addValue = false; } if (addValue) { attributeMap.get(attributeName).getValues().addAll(attribute.getValues()); } else { validationWarnings.add(String.format( "Multiple values found for a non-multi-valued attribute. Attribute: '%s', Existing value: '%s', New value: '%s'. Existing value will be kept, new value will be ignored.", attributeName, attributeMap.get(attributeName).getValue(), attribute.getValue())); } } } if (!validationWarnings.isEmpty()) { Attribute validationAttribute = attributeMap.get(ValidationAttributes.VALIDATION_WARNINGS); if (validationAttribute != null) { attributeMap.get(ValidationAttributes.VALIDATION_WARNINGS).getValues().addAll(validationWarnings); } else { attributeMap.put(ValidationAttributes.VALIDATION_WARNINGS, new AttributeImpl( ValidationAttributes.VALIDATION_WARNINGS, (Serializable) validationWarnings)); } } return attributeMap.values().stream().collect(Collectors.toList()); }
From source file:ru.histone.v2.BaseTest.java
protected Map<String, CompletableFuture<EvalNode>> convertContext(HistoneTestCase.Case testCase) { Map<String, CompletableFuture<EvalNode>> res = new HashMap<>(); for (Map.Entry<String, Object> entry : testCase.getContext().entrySet()) { if (entry.getValue() == null) { res.putIfAbsent(entry.getKey(), EvalUtils.getValue(ObjectUtils.NULL)); } else if (entry.getValue() instanceof List) { List list = (List) entry.getValue(); Map<String, Object> map = new LinkedHashMap<>(list.size()); for (int i = 0; i < list.size(); i++) { map.put(i + "", getObjectValue(list.get(i))); }/* ww w . j av a 2 s. c o m*/ res.putIfAbsent(entry.getKey(), EvalUtils.getValue(map)); } else if (entry.getValue() instanceof Map) { Map<String, Object> m = (Map<String, Object>) entry.getValue(); Map<String, Object> map = new LinkedHashMap<>(m.size()); for (Map.Entry<String, Object> e : m.entrySet()) { map.put(e.getKey(), getObjectValue(e.getValue())); } res.putIfAbsent(entry.getKey(), EvalUtils.getValue(map)); } else { res.putIfAbsent(entry.getKey(), EvalUtils.getValue(entry.getValue())); } } return res; }
From source file:org.shredzone.commons.view.manager.ViewManager.java
/** * Processes a {@link View}. A view name and view pattern is generated, and a * {@link ViewInvoker} is built.//from w w w . ja v a2 s .c o m * * @param bean * Spring bean to be used * @param method * View handler method to be invoked * @param anno * {@link View} annotation */ private void processView(Object bean, Method method, View anno) { String name = computeViewName(method, anno); Map<String, List<ViewPattern>> vpMap = patternMap.computeIfAbsent(name, it -> new HashMap<>()); ViewInvoker invoker = new ViewInvoker(bean, method, conversionService); ViewPattern vp = new ViewPattern(anno, invoker); List<ViewPattern> vpList = vpMap.computeIfAbsent(vp.getQualifier(), it -> new ArrayList<>()); vpList.add(vp); Signature sig = vp.getSignature(); if (sig != null) { Map<Signature, ViewPattern> sigMap = signatureMap.computeIfAbsent(vp.getQualifier(), it -> new HashMap<>()); if (sigMap.putIfAbsent(sig, vp) != null) { throw new IllegalStateException("Signature '" + sig + "' defined twice"); } } patternOrder.add(vp); log.info("Found view '{}' with pattern '{}'", name, anno.pattern()); }
From source file:tpt.dbweb.cat.io.TaggedTextXMLWriter.java
/** * Output a tagged text as an article/*ww w . j a v a 2s.c o m*/ * @param attributeMap * @param tt */ public void write(Map<String, String> attributeMap, TaggedText tt) { Map<String, String> tmpMap = new HashMap<>(); if (tt.info(false) != null) { tmpMap.putAll(tt.info(false)); } if (attributeMap != null) { tmpMap.putAll(attributeMap); } tmpMap.putIfAbsent("id", tt.id); writeString(tmpMap, toMarkedText(tt)); ps.flush(); }
From source file:org.apache.solr.cloud.TestAuthenticationFramework.java
private void createCollection(MiniSolrCloudCluster miniCluster, String collectionName, String asyncId) throws Exception { String configName = "solrCloudCollectionConfig"; miniCluster.uploadConfigSet(SolrTestCaseJ4.TEST_PATH().resolve("collection1/conf"), configName); final boolean persistIndex = random().nextBoolean(); Map<String, String> collectionProperties = new HashMap<>(); collectionProperties.putIfAbsent(CoreDescriptor.CORE_CONFIG, "solrconfig-tlog.xml"); collectionProperties.putIfAbsent("solr.tests.maxBufferedDocs", "100000"); collectionProperties.putIfAbsent("solr.tests.ramBufferSizeMB", "100"); // use non-test classes so RandomizedRunner isn't necessary if (random().nextBoolean()) { collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICY, TieredMergePolicy.class.getName()); collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICY, "true"); collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICYFACTORY, "false"); } else {//from w w w. j a va 2s . c o m collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_MERGEPOLICYFACTORY, TieredMergePolicyFactory.class.getName()); collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICYFACTORY, "true"); collectionProperties.putIfAbsent(SolrTestCaseJ4.SYSTEM_PROPERTY_SOLR_TESTS_USEMERGEPOLICY, "false"); } collectionProperties.putIfAbsent("solr.tests.mergeScheduler", "org.apache.lucene.index.ConcurrentMergeScheduler"); collectionProperties.putIfAbsent("solr.directoryFactory", (persistIndex ? "solr.StandardDirectoryFactory" : "solr.RAMDirectoryFactory")); if (asyncId == null) { CollectionAdminRequest.createCollection(collectionName, configName, NUM_SHARDS, REPLICATION_FACTOR) .setProperties(collectionProperties).process(miniCluster.getSolrClient()); } else { CollectionAdminRequest.createCollection(collectionName, configName, NUM_SHARDS, REPLICATION_FACTOR) .setProperties(collectionProperties).processAndWait(miniCluster.getSolrClient(), 30); } }
From source file:com.qwazr.server.configuration.ServerConfiguration.java
protected static Map<String, String> argsToMap(final String... args) throws IOException { final Map<String, String> props = argsToMapPrefix("--", args); // Load the QWAZR_PROPERTIES String propertyFile = props.get(QWAZR_PROPERTIES); if (propertyFile == null) propertyFile = System.getProperty(QWAZR_PROPERTIES, System.getenv(QWAZR_PROPERTIES)); if (propertyFile != null) { final Path propFile = Paths.get(propertyFile); LOGGER.info(() -> "Load QWAZR_PROPERTIES file: " + propFile.toAbsolutePath()); final Properties properties = new Properties(); try (final BufferedReader reader = Files.newBufferedReader(propFile, StandardCharsets.UTF_8)) { properties.load(reader);/*from w w w . j a va 2 s . c o m*/ } // Priority to program argument, we only put the value if the key is not present properties.forEach((key, value) -> props.putIfAbsent(key.toString(), value.toString())); } return props; }