Skip to content

Commit e7dc439

Browse files
stsypanovjhoeller
authored andcommitted
Simplify ConcurrentReferenceHashMap
1 parent d2bfca7 commit e7dc439

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java

+11-14
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ private V put(@Nullable final K key, @Nullable final V value, final boolean over
285285
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.RESIZE) {
286286
@Override
287287
@Nullable
288-
protected V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries entries) {
288+
protected V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries<V> entries) {
289289
if (entry != null) {
290290
V oldValue = entry.getValue();
291291
if (overwriteExisting) {
@@ -530,15 +530,12 @@ public <T> T doTask(final int hash, @Nullable final Object key, final Task<T> ta
530530
final Reference<K, V> head = this.references[index];
531531
Reference<K, V> ref = findInChain(head, key, hash);
532532
Entry<K, V> entry = (ref != null ? ref.get() : null);
533-
Entries entries = new Entries() {
534-
@Override
535-
public void add(@Nullable V value) {
536-
@SuppressWarnings("unchecked")
537-
Entry<K, V> newEntry = new Entry<>((K) key, value);
538-
Reference<K, V> newReference = Segment.this.referenceManager.createReference(newEntry, hash, head);
539-
Segment.this.references[index] = newReference;
540-
Segment.this.count.incrementAndGet();
541-
}
533+
Entries<V> entries = value -> {
534+
@SuppressWarnings("unchecked")
535+
Entry<K, V> newEntry = new Entry<>((K) key, value);
536+
Reference<K, V> newReference = Segment.this.referenceManager.createReference(newEntry, hash, head);
537+
Segment.this.references[index] = newReference;
538+
Segment.this.count.incrementAndGet();
542539
};
543540
return task.execute(ref, entry, entries);
544541
}
@@ -802,7 +799,7 @@ public boolean hasOption(TaskOption option) {
802799
* @see #execute(Reference, Entry)
803800
*/
804801
@Nullable
805-
protected T execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries entries) {
802+
protected T execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries<V> entries) {
806803
return execute(ref, entry);
807804
}
808805

@@ -830,15 +827,15 @@ private enum TaskOption {
830827

831828

832829
/**
833-
* Allows a task access to {@link Segment} entries.
830+
* Allows a task access to {@link ConcurrentReferenceHashMap.Segment} entries.
834831
*/
835-
private abstract class Entries {
832+
private interface Entries<V> {
836833

837834
/**
838835
* Add a new entry with the specified value.
839836
* @param value the value to add
840837
*/
841-
public abstract void add(@Nullable V value);
838+
void add(@Nullable V value);
842839
}
843840

844841

0 commit comments

Comments
 (0)