java.util.Map.replace()方法的使用及代码示例

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

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

Map.replace介绍

暂无

代码示例

代码示例来源:origin: iluwatar/java-design-patterns

@Override
public boolean update(final Customer customer) {
 return idToCustomer.replace(customer.getId(), customer) != null;
}

代码示例来源:origin: google/guava

@Override
public V replace(K key, V value) {
 synchronized (mutex) {
  return delegate().replace(key, value);
 }
}

代码示例来源:origin: google/guava

@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
public void testReplace_absentNullValueUnsupported() {
 try {
  getMap().replace(k3(), null);
 } catch (NullPointerException tolerated) {
  // permitted not to throw because it would be a no-op
 }
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_KEY_QUERIES)
public void testReplace_absentNullKeyUnsupported() {
 try {
  getMap().replace(null, v3());
 } catch (NullPointerException tolerated) {
  // permitted not to throw because it would be a no-op
 }
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUE_QUERIES})
public void testReplaceEntry_nullDifferentFromAbsent() {
 assertFalse(getMap().replace(k3(), null, v3()));
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
public void testReplaceEntry_expectNullUnsupported() {
 try {
  assertFalse(getMap().replace(k3(), null, v3()));
 } catch (NullPointerException tolerated) {
  // the operation would be a no-op, so exceptions are allowed but not required
 }
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
public void testReplace_supportedAbsent() {
 assertNull(getMap().replace(k3(), v3()));
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testReplace_presentNullValueUnsupported() {
 try {
  getMap().replace(k0(), null);
  fail("Expected NullPointerException");
 } catch (NullPointerException expected) {
 }
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
public void testReplaceEntry_absentKeyNullValueUnsupported() {
 try {
  assertFalse(getMap().replace(k3(), v3(), null));
 } catch (NullPointerException tolerated) {
  // the operation would be a no-op, so exceptions are allowed but not required
 }
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(absent = SUPPORTS_PUT)
 public void testReplaceEntry_unsupportedAbsentKey() {
  try {
   getMap().replace(k3(), v3(), v4());
  } catch (UnsupportedOperationException tolerated) {
   // the operation would be a no-op, so exceptions are allowed but not required
  }
  expectUnchanged();
 }
}

代码示例来源:origin: google/guava

@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUE_QUERIES)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_wrongValueNullValueUnsupported() {
 try {
  assertFalse(getMap().replace(k0(), v3(), null));
 } catch (NullPointerException tolerated) {
  // the operation would be a no-op, so exceptions are allowed but not required
 }
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_unsupportedWrongValue() {
 try {
  getMap().replace(k0(), v3(), v4());
 } catch (UnsupportedOperationException tolerated) {
  // the operation would be a no-op, so exceptions are allowed but not required
 }
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
public void testReplaceEntry_supportedAbsentKey() {
 assertFalse(getMap().replace(k3(), v3(), v4()));
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_presentNullValueUnsupported() {
 try {
  getMap().replace(k0(), v0(), null);
  fail("Expected NullPointerException");
 } catch (NullPointerException expected) {
 }
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(absent = SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_unsupportedPresent() {
 try {
  getMap().replace(k0(), v0(), v3());
  fail("Expected UnsupportedOperationException");
 } catch (UnsupportedOperationException expected) {
 }
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_supportedPresentUnchanged() {
 assertTrue(getMap().replace(k0(), v0(), v0()));
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testReplace_supportedPresentNoChange() {
 assertEquals(v0(), getMap().replace(k0(), v0()));
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_supportedWrongValue() {
 assertFalse(getMap().replace(k0(), v3(), v4()));
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testReplace_supportedPresent() {
 try {
  assertEquals(v0(), getMap().replace(k0(), v3()));
  expectReplacement(entry(k0(), v3()));
 } catch (ClassCastException tolerated) { // for ClassToInstanceMap
  expectUnchanged();
 }
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
@CollectionSize.Require(absent = ZERO)
public void testReplaceEntry_supportedPresent() {
 try {
  assertTrue(getMap().replace(k0(), v0(), v3()));
  expectReplacement(entry(k0(), v3()));
 } catch (ClassCastException tolerated) { // for ClassToInstanceMap
  expectUnchanged();
 }
}

相关文章