Skip to content

Commit

Permalink
Use Objects.requireNonNull()
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Dec 26, 2024
1 parent 8875dad commit d24d7a8
Showing 1 changed file with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1303,9 +1303,7 @@ private WriteThroughEntry(final K k, final V v) {
*/
@Override
public V setValue(final V value) {
if (value == null) {
throw new NullPointerException();
}
Objects.requireNonNull(value, "value");
final V v = super.setValue(value);
ConcurrentReferenceHashMap.this.put(getKey(), value);
return v;
Expand Down Expand Up @@ -1553,9 +1551,7 @@ public boolean containsKey(final Object key) {
*/
@Override
public boolean containsValue(final Object value) {
if (value == null) {
throw new NullPointerException();
}
Objects.requireNonNull(value, "value");
// See explanation of modCount use above
final Segment<K, V>[] segments = this.segments;
final int[] mc = new int[segments.length];
Expand Down Expand Up @@ -1715,9 +1711,8 @@ public void purgeStaleEntries() {
*/
@Override
public V put(final K key, final V value) {
if (key == null || value == null) {
throw new NullPointerException();
}
Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");
final int hash = hashOf(key);
return segmentFor(hash).put(key, hash, value, null, false);
}
Expand All @@ -1743,9 +1738,7 @@ public void putAll(final Map<? extends K, ? extends V> m) {
*/
@Override
public V putIfAbsent(final K key, final V value) {
if (value == null) {
throw new NullPointerException();
}
Objects.requireNonNull(value, "value");
final int hash = hashOf(key);
return segmentFor(hash).put(key, hash, value, null, true);
}
Expand Down Expand Up @@ -1785,9 +1778,7 @@ public boolean remove(final Object key, final Object value) {
*/
@Override
public V replace(final K key, final V value) {
if (value == null) {
throw new NullPointerException();
}
Objects.requireNonNull(value, "value");
final int hash = hashOf(key);
return segmentFor(hash).replace(key, hash, value);
}
Expand All @@ -1799,9 +1790,8 @@ public V replace(final K key, final V value) {
*/
@Override
public boolean replace(final K key, final V oldValue, final V newValue) {
if (oldValue == null || newValue == null) {
throw new NullPointerException();
}
Objects.requireNonNull(oldValue, "oldValue");
Objects.requireNonNull(newValue, "newValue");
final int hash = hashOf(key);
return segmentFor(hash).replace(key, hash, oldValue, newValue);
}
Expand Down

0 comments on commit d24d7a8

Please sign in to comment.