本文整理了Java中java.util.Map.replace()
方法的一些代码示例,展示了Map.replace()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Map.replace()
方法的具体详情如下:
包路径:java.util.Map
类名称: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();
}
}
内容来源于网络,如有侵权,请联系作者删除!