本文整理了Java中java.util.Properties.putIfAbsent()
方法的一些代码示例,展示了Properties.putIfAbsent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Properties.putIfAbsent()
方法的具体详情如下:
包路径:java.util.Properties
类名称:Properties
方法名:putIfAbsent
暂无
代码示例来源:origin: apache/geode
public T withName(String name) {
// only if name is not defined yet
if (!properties.containsKey(NAME)) {
this.name = name;
properties.putIfAbsent(NAME, name);
}
return (T) this;
}
代码示例来源:origin: apache/geode
/**
* be able to start JMX manager and admin rest on default ports
*/
public T withJMXManager(boolean useProductDefaultPorts) {
if (!useProductDefaultPorts) {
// do no override these properties if already exists
properties.putIfAbsent(JMX_MANAGER_PORT,
portSupplier.getAvailablePort() + "");
this.jmxPort = Integer.parseInt(properties.getProperty(JMX_MANAGER_PORT));
} else {
// the real port numbers will be set after we started the server/locator.
this.jmxPort = 0;
}
properties.putIfAbsent(JMX_MANAGER, "true");
properties.putIfAbsent(JMX_MANAGER_START, "true");
return (T) this;
}
代码示例来源:origin: apache/hive
@Override
public synchronized Object putIfAbsent(Object key, Object value) {
if (interned != null) copyFromInternedToThis();
return super.putIfAbsent(key, value);
}
代码示例来源:origin: kiegroup/jbpm
private LdapContext buildLdapContext() throws NamingException {
config.putIfAbsent(Context.INITIAL_CONTEXT_FACTORY, DEFAULT_INITIAL_CONTEXT_FACTORY);
config.putIfAbsent(Context.SECURITY_AUTHENTICATION, DEFAULT_SECURITY_AUTHENTICATION);
String protocol = config.getProperty(Context.SECURITY_PROTOCOL);
config.putIfAbsent(Context.PROVIDER_URL, createDefaultProviderUrl(protocol));
if (log.isDebugEnabled()) {
log.debug("Using following InitialLdapContext properties:");
log.debug("Initial Context Factory: {}", config.getProperty(Context.INITIAL_CONTEXT_FACTORY));
log.debug("Authentication Type: {}", config.getProperty(Context.SECURITY_AUTHENTICATION));
log.debug("Protocol: {}", config.getProperty(Context.SECURITY_PROTOCOL));
log.debug("Provider URL: {}", config.getProperty(Context.PROVIDER_URL));
log.debug("User DN: {}", config.getProperty(Context.SECURITY_PRINCIPAL));
log.debug("Password: {}", config.getProperty(Context.SECURITY_CREDENTIALS));
}
return new InitialLdapContext(config, null);
}
代码示例来源:origin: apache/geode
@Override
public void before() {
normalizeProperties();
if (httpPort < 0) {
// at this point, httpPort is not being configured by api, we assume they do not
// want to start the http service.
// use putIfAbsent if it was configured using withProperty
properties.putIfAbsent(HTTP_SERVICE_PORT, "0");
}
firstLevelChildrenFile = Arrays.asList(getWorkingDir().listFiles());
}
代码示例来源:origin: apache/geode
protected void normalizeProperties() {
// if name is set via property, not with API
if (name == null) {
if (properties.containsKey(NAME)) {
name = properties.getProperty(NAME);
} else {
if (this instanceof ServerStarterRule) {
name = "server";
} else {
name = "locator";
}
}
withName(name);
}
// if jmxPort is set via property, not with API
if (jmxPort < 0 && properties.containsKey(JMX_MANAGER_PORT)) {
// this will make sure we have all the missing properties, but it won't override
// the existing properties
withJMXManager(false);
}
// if caller wants the logs being put into a file instead of in console output
// do it here since only here, we can guarantee the name is present
if (logFile) {
properties.putIfAbsent(LOG_FILE, new File(name + ".log").getAbsolutePath());
}
}
代码示例来源:origin: neo4j/neo4j
indexConfiguration.putIfAbsent( FulltextIndexSettings.INDEX_CONFIG_ANALYZER, defaultAnalyzerName );
indexConfiguration.putIfAbsent( FulltextIndexSettings.INDEX_CONFIG_EVENTUALLY_CONSISTENT, defaultEventuallyConsistentSetting );
return new FulltextSchemaDescriptor( schema, indexConfiguration );
代码示例来源:origin: schemaspy/schemaspy
private void processIncludes(Properties props, ResolutionInfo resolutionInfo) {
Map<String,String> includes = props.entrySet().stream()
.filter(isInclude)
.collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()));
includes.keySet().forEach(props::remove);
includes.values().stream()
.map( s -> s.split("::"))
.forEach( ref -> {
Properties refProps = resolve(ref[0], resolutionInfo);
props.putIfAbsent(ref[1], refProps.getProperty(ref[1]));
});
}
代码示例来源:origin: spring-projects/spring-kafka
Properties p = new Properties();
p.load(in);
p.forEach((key, value) -> properties.putIfAbsent(key, environment.resolvePlaceholders((String) value)));
代码示例来源:origin: com.sqlapp/sqlapp-core
@Override
public synchronized Object putIfAbsent(Object key, Object value) {
keys.remove(key);
return super.putIfAbsent(key, value);
}
代码示例来源:origin: org.infinispan/infinispan-embedded-query
/**
* Dynamic index uninverting is deprecated: using it will cause warnings to be logged,
* to encourage people to use the annotation org.hibernate.search.annotations.SortableField.
* The default in Hibernate Search is to throw an exception rather than logging a warning;
* we opt to be more lenient by default in the Infinispan use case, matching the behaviour
* of previous versions of Hibernate Search.
*
* @param indexingProperties
*/
private void allowDynamicSortingByDefault(Properties indexingProperties) {
indexingProperties.putIfAbsent(Environment.INDEX_UNINVERTING_ALLOWED, Boolean.TRUE.toString());
}
代码示例来源:origin: com.oracle.substratevm/svm
private void initializeLazyValue(String key) {
if (!fullyInitialized && lazyRuntimeValues.containsKey(key) && properties.get(key) == null) {
/*
* putIfAbsent has the correct synchronization to guard against concurrent manual
* updates of the same property key.
*/
properties.putIfAbsent(key, lazyRuntimeValues.get(key).get());
}
}
代码示例来源:origin: payara/Cloud-Connectors
public static Properties merge(Properties base, Properties addtional){
Properties properties = new Properties();
properties.putAll(base);
if(addtional != null){
for(String key : addtional.stringPropertyNames()){
properties.putIfAbsent(key, addtional.getProperty(key));
}
}
return properties;
}
代码示例来源:origin: asakusafw/asakusafw
static void configure() {
if (SimpleLoggerUtil.class.getClassLoader().getResource(NAME_RESOURCE_FILE) != null) {
return;
}
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Properties props = System.getProperties();
OPT_DEFAULTS.forEach((k, v) -> props.putIfAbsent(k, v));
System.setProperties(props);
return null;
});
}
}
代码示例来源:origin: asakusafw/asakusafw
static void configure() {
if (SimpleLoggerUtil.class.getClassLoader().getResource(NAME_RESOURCE_FILE) != null) {
return;
}
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Properties props = System.getProperties();
OPT_DEFAULTS.forEach((k, v) -> props.putIfAbsent(k, v));
System.setProperties(props);
return null;
});
}
}
代码示例来源:origin: com.buschmais.jqassistant.neo4jserver/neo4jv3
@Override
public Properties getProperties(EmbeddedNeo4jConfiguration embedded) {
Properties commonProperties = getCommonProperties();
commonProperties.putIfAbsent(PROPERTY_NEO4J_DBMS_CONNECTOR_BOLT_ENABLED, Boolean.toString(embedded.isConnectorEnabled()));
commonProperties.putIfAbsent(PROPERTY_NEO4J_DBMS_CONNECTOR_BOLT_LISTEN_ADDRESS, embedded.getListenAddress() + ":" + embedded.getBoltPort());
commonProperties.putIfAbsent(PROPERTY_NEO4J_DBMS_SECURITY_PROCEDURES_UNRESTRICTED, "apoc.*");
commonProperties.putIfAbsent(PROPERTY_NEO4J_DBMS_TX_LOG_ROTATION_SIZE, "50M");
commonProperties.putIfAbsent(PROPERTY_NEO4J_DBMS_TX_LOG_ROTATION_RETENTION_POLICY, Boolean.FALSE.toString());
return commonProperties;
}
}
代码示例来源:origin: org.apache.hive/hive-common
@Override
public synchronized Object putIfAbsent(Object key, Object value) {
if (interned != null) copyFromInternedToThis();
return super.putIfAbsent(key, value);
}
代码示例来源:origin: de.tudarmstadt.ukp.inception.rdf4j/rdf4j-lucene-spin
/**
* Add only absent parameters from argument.
*
* @see Properties#putIfAbsent(java.lang.Object, java.lang.Object)
* @param parameters
*/
public void addAbsentParameters(Properties parameters) {
parameters.forEach((Object k, Object v) -> {
LuceneSpinSail.this.parameters.putIfAbsent(k, v);
});
}
代码示例来源:origin: com.agapsys.libs/web-app-toolkit
/**
* Returns a new properties merging two instances
* @param properties main property instance
* @param defaults contains default properties to be merged if containing entries are not defined in main instance.
* @return merged instance.
*/
public static Properties mergeProperties(Properties properties, Properties defaults) {
Properties tmpProperties = new Properties();
for (Map.Entry mainEntry : properties.entrySet()) {
tmpProperties.put(mainEntry.getKey(), mainEntry.getValue());
}
for (Map.Entry defaultEntry : defaults.entrySet()) {
tmpProperties.putIfAbsent(defaultEntry.getKey(), defaultEntry.getValue());
}
return tmpProperties;
}
// =========================================================================
代码示例来源:origin: salesforce/Argus
/**
* Returns the list of configured properties and their values.
*
* @return The list of configured properties and their values.
*/
@Override
public synchronized String toString() {
Properties allProperties = new Properties();
allProperties.putAll(this);
for (Property property : Property.values()) {
allProperties.putIfAbsent(property.key(), property.defaultValue());
}
StringBuilder sb = new StringBuilder();
sb.append("Using the following configured values:\n");
Pattern pattern = Pattern.compile("pwd|secret|password|passwd|token");
Set<String> names = new TreeSet<>(allProperties.stringPropertyNames());
names.stream().forEach((name) -> {
String value = pattern.matcher(name).find() ? "********" : allProperties.get(name).toString();
sb.append("\t").append(name).append(" : ").append(value).append("\n");
});
return sb.toString();
}
内容来源于网络,如有侵权,请联系作者删除!