java.util.HashMap.putIfAbsent()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(166)

本文整理了Java中java.util.HashMap.putIfAbsent()方法的一些代码示例,展示了HashMap.putIfAbsent()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashMap.putIfAbsent()方法的具体详情如下:
包路径:java.util.HashMap
类名称:HashMap
方法名:putIfAbsent

HashMap.putIfAbsent介绍

暂无

代码示例

代码示例来源:origin: jfinal/jfinal

@Override
public V putIfAbsent(K key, V value) {
  synchronized (this) {
    return super.putIfAbsent(key, value);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public V putIfAbsent(String key, @Nullable V value) {
  String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key);
  if (oldKey != null) {
    return this.targetMap.get(oldKey);
  }
  return this.targetMap.putIfAbsent(key, value);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public V computeIfAbsent(String key, Function<? super String, ? extends V> mappingFunction) {
  String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key);
  if (oldKey != null) {
    return this.targetMap.get(oldKey);
  }
  return this.targetMap.computeIfAbsent(key, mappingFunction);
}

代码示例来源:origin: jfinal/jfinal

public static FieldGetter getFieldGetter(Object key, Class<?> targetClass, String fieldName) {
  FieldGetter fieldGetter = fieldGetterCache.get(key);
  if (fieldGetter == null) {
    fieldGetter = doGetFieldGetter(targetClass, fieldName);    // 已确保不会返回 null
    fieldGetterCache.putIfAbsent(key, fieldGetter);
  }
  return fieldGetter;
}

代码示例来源:origin: org.springframework/spring-core

@Override
@Nullable
public V computeIfAbsent(String key, Function<? super String, ? extends V> mappingFunction) {
  String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key);
  if (oldKey != null) {
    return this.targetMap.get(oldKey);
  }
  return this.targetMap.computeIfAbsent(key, mappingFunction);
}

代码示例来源:origin: org.springframework/spring-core

@Override
@Nullable
public V putIfAbsent(String key, @Nullable V value) {
  String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key);
  if (oldKey != null) {
    return this.targetMap.get(oldKey);
  }
  return this.targetMap.putIfAbsent(key, value);
}

代码示例来源:origin: stanfordnlp/CoreNLP

/**
 * Process multi-word prepositions.
 */
private static void processMultiwordPreps(SemanticGraph sg) {
 /* Semgrexes require a graph with a root. */
 if (sg.getRoots().isEmpty())
  return;
 HashMap<String, HashSet<Integer>> bigrams = new HashMap<>();
 HashMap<String, HashSet<Integer>> trigrams = new HashMap<>();
 List<IndexedWord> vertexList = sg.vertexListSorted();
 int numWords = vertexList.size();
 for (int i = 1; i < numWords; i++) {
  String bigram = vertexList.get(i-1).value().toLowerCase() + '_' + vertexList.get(i).value().toLowerCase();
  bigrams.putIfAbsent(bigram, new HashSet<>());
  bigrams.get(bigram).add(vertexList.get(i-1).index());
  if (i > 1) {
   String trigram = vertexList.get(i-2).value().toLowerCase() + '_' + bigram;
   trigrams.putIfAbsent(trigram, new HashSet<>());
   trigrams.get(trigram).add(vertexList.get(i-2).index());
  }
 }
 /* Simple two-word prepositions. */
 processSimple2WP(sg, bigrams);
 /* More complex two-word prepositions in which the first
  * preposition is the head of the prepositional phrase. */
 processComplex2WP(sg, bigrams);
 /* Process three-word prepositions. */
 process3WP(sg, trigrams);
}

代码示例来源:origin: jfinal/jfinal

public SharedMethodInfo getSharedMethodInfo(String methodName, Object[] argValues) {
  Class<?>[] argTypes = MethodKit.getArgTypes(argValues);
  Long key = getSharedMethodKey(methodName, argTypes);
  SharedMethodInfo method = methodCache.get(key);
  if (method == null) {
    method = doGetSharedMethodInfo(methodName, argTypes);
    if (method != null) {
      methodCache.putIfAbsent(key, method);
    }
    // shared method 不支持 null safe,不缓存: methodCache.putIfAbsent(key, Void.class)
  }
  return method;
}

代码示例来源:origin: apache/activemq

@Override
public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException {
  TopicMessageStore rc = (TopicMessageStore) storeCache.get(destination);
  if (rc == null) {
    TopicMessageStore store = transactionStore.proxy(new JDBCTopicMessageStore(this, getAdapter(), wireFormat, destination, audit));
    rc = (TopicMessageStore) storeCache.putIfAbsent(destination, store);
    if (rc == null) {
      rc = store;
    }
  }
  return rc;
}

代码示例来源:origin: apache/activemq

@Override
public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException {
  MessageStore rc = storeCache.get(destination);
  if (rc == null) {
    MessageStore store = transactionStore.proxy(new JDBCMessageStore(this, getAdapter(), wireFormat, destination, audit));
    rc = storeCache.putIfAbsent(destination, store);
    if (rc == null) {
      rc = store;
    }
  }
  return rc;
}

代码示例来源:origin: confluentinc/ksql

private KsqlRestConfig buildConfig() {
 final HashMap<String, Object> config = new HashMap<>(baseConfig);
 config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers.get());
 config.putIfAbsent(KsqlRestConfig.LISTENERS_CONFIG, "http://localhost:0,https://localhost:0");
 return new KsqlRestConfig(config);
}

代码示例来源:origin: cloudfoundry/uaa

private List<Map<String, String>> getScopes(ArrayList<String> scopes) {
  List<Map<String, String>> result = new ArrayList<Map<String, String>>();
  for (String scope : scopes) {
    HashMap<String, String> map = new HashMap<String, String>();
    String code = SCOPE_PREFIX + scope;
    map.put("code", code);
    Optional<ScimGroup> group = groupProvisioning.query(String.format("displayName eq \"%s\"", scope), IdentityZoneHolder.get().getId()).stream().findFirst();
    group.ifPresent(g -> {
      String description = g.getDescription();
      if (StringUtils.hasText(description)) {
        map.put("text", description);
      }
    });
    map.putIfAbsent("text", scope);
    result.add(map);
  }
  Collections.sort(result, (map1, map2) -> {
    String code1 = map1.get("code");
    String code2 = map2.get("code");
    int i;
    if (0 != (i = codeIsPasswordOrOpenId(code2) - codeIsPasswordOrOpenId(code1))) {
      return i;
    }
    return code1.compareTo(code2);
  });
  return result;
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public void collectGridNodeData(DiscoveryDataBag dataBag) {
  if (dataBag.isJoiningNodeClient() || dataBag.commonDataCollectedFor(ENCRYPTION_MGR.ordinal()))
    return;
  HashMap<Integer, byte[]> knownEncKeys = knownEncryptionKeys();
  HashMap<Integer, byte[]> newKeys =
    newEncryptionKeys(knownEncKeys == null ? Collections.EMPTY_SET : knownEncKeys.keySet());
  if (knownEncKeys == null)
    knownEncKeys = newKeys;
  else if (newKeys != null) {
    for (Map.Entry<Integer, byte[]> entry : newKeys.entrySet()) {
      byte[] old = knownEncKeys.putIfAbsent(entry.getKey(), entry.getValue());
      assert old == null;
    }
  }
  dataBag.addGridCommonData(ENCRYPTION_MGR.ordinal(), knownEncKeys);
}

代码示例来源:origin: kairosdb/kairosdb

mappedItem = m_hashMap.putIfAbsent(cacheData, li);

代码示例来源:origin: google/error-prone

.forEach(
  (k, v) -> {
   SeverityLevel existing = combinedSeverities.putIfAbsent(k, v);
   if (existing != null && !existing.equals(v)) {
    throw new IllegalArgumentException(

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String putIfAbsent(String key, String value) {
  return super.putIfAbsent(key, value);
}

代码示例来源:origin: com.typesafe.play/play

/**
 * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String putIfAbsent(String key, String value) {
  return super.putIfAbsent(key, value);
}

代码示例来源:origin: com.typesafe.play/play_2.11

/**
 * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String putIfAbsent(String key, String value) {
  return super.putIfAbsent(key, value);
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * @deprecated Deprecated as of 2.7.0. {@link Session} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String putIfAbsent(String key, String value) {
  return super.putIfAbsent(key, value);
}

代码示例来源:origin: com.typesafe.play/play_2.12

/**
 * @deprecated Deprecated as of 2.7.0. {@link Flash} will not be a subclass of {@link HashMap} in future Play releases.
 */
@Deprecated
@Override
public String putIfAbsent(String key, String value) {
  return super.putIfAbsent(key, value);
}

相关文章