You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/05/16 11:56:15 UTC

[groovy] 02/02: Trivial refactoring: Explicit type can be replaced with <>

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 0d59634be1b62dbc50dbd6425101f19138e3c79e
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat May 16 19:55:17 2020 +0800

    Trivial refactoring: Explicit type can be replaced with <>
---
 .../ConcurrentLinkedHashMap.java                   | 50 +++++++++++-----------
 .../concurrentlinkedhashmap/Weighers.java          |  2 +-
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/main/java/org/apache/groovy/util/concurrent/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java b/src/main/java/org/apache/groovy/util/concurrent/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java
index ac61233..cac5cfe 100644
--- a/src/main/java/org/apache/groovy/util/concurrent/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java
+++ b/src/main/java/org/apache/groovy/util/concurrent/concurrentlinkedhashmap/ConcurrentLinkedHashMap.java
@@ -219,15 +219,15 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
     // The data store and its maximum capacity
     concurrencyLevel = builder.concurrencyLevel;
     capacity = new AtomicLong(Math.min(builder.capacity, MAXIMUM_CAPACITY));
-    data = new ConcurrentHashMap<K, Node<K, V>>(builder.initialCapacity, 0.75f, concurrencyLevel);
+    data = new ConcurrentHashMap<>(builder.initialCapacity, 0.75f, concurrencyLevel);
 
     // The eviction support
     weigher = builder.weigher;
     evictionLock = new ReentrantLock();
     weightedSize = new AtomicLong();
-    evictionDeque = new LinkedDeque<Node<K, V>>();
-    writeBuffer = new ConcurrentLinkedQueue<Runnable>();
-    drainStatus = new AtomicReference<DrainStatus>(IDLE);
+    evictionDeque = new LinkedDeque<>();
+    writeBuffer = new ConcurrentLinkedQueue<>();
+    drainStatus = new AtomicReference<>(IDLE);
 
     readBufferReadCount = new long[NUMBER_OF_READ_BUFFERS];
     readBufferWriteCount = new AtomicLong[NUMBER_OF_READ_BUFFERS];
@@ -238,7 +238,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
       readBufferDrainAtWriteCount[i] = new AtomicLong();
       readBuffers[i] = new AtomicReference[READ_BUFFER_SIZE];
       for (int j = 0; j < READ_BUFFER_SIZE; j++) {
-        readBuffers[i][j] = new AtomicReference<Node<K, V>>();
+        readBuffers[i][j] = new AtomicReference<>();
       }
     }
 
@@ -246,7 +246,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
     listener = builder.listener;
     pendingNotifications = (listener == DiscardingListener.INSTANCE)
         ? (Queue<Node<K, V>>) DISCARDING_QUEUE
-        : new ConcurrentLinkedQueue<Node<K, V>>();
+        : new ConcurrentLinkedQueue<>();
   }
 
   /** Ensures that the object is not null. */
@@ -492,7 +492,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
    */
   boolean tryToRetire(Node<K, V> node, WeightedValue<V> expect) {
     if (expect.isAlive()) {
-      final WeightedValue<V> retired = new WeightedValue<V>(expect.value, -expect.weight);
+      final WeightedValue<V> retired = new WeightedValue<>(expect.value, -expect.weight);
       return node.compareAndSet(expect, retired);
     }
     return false;
@@ -510,7 +510,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
       if (!current.isAlive()) {
         return;
       }
-      final WeightedValue<V> retired = new WeightedValue<V>(current.value, -current.weight);
+      final WeightedValue<V> retired = new WeightedValue<>(current.value, -current.weight);
       if (node.compareAndSet(current, retired)) {
         return;
       }
@@ -527,7 +527,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
   void makeDead(Node<K, V> node) {
     for (;;) {
       WeightedValue<V> current = node.get();
-      WeightedValue<V> dead = new WeightedValue<V>(current.value, 0);
+      WeightedValue<V> dead = new WeightedValue<>(current.value, 0);
       if (node.compareAndSet(current, dead)) {
         weightedSize.lazySet(weightedSize.get() - Math.abs(current.weight));
         return;
@@ -719,8 +719,8 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
     checkNotNull(value);
 
     final int weight = weigher.weightOf(key, value);
-    final WeightedValue<V> weightedValue = new WeightedValue<V>(value, weight);
-    final Node<K, V> node = new Node<K, V>(key, weightedValue);
+    final WeightedValue<V> weightedValue = new WeightedValue<>(value, weight);
+    final Node<K, V> node = new Node<>(key, weightedValue);
 
     for (;;) {
       final Node<K, V> prior = data.putIfAbsent(node.key, node);
@@ -781,7 +781,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
     checkNotNull(key);
     checkNotNull(mappingFunction);
 
-    final ObjectHolder<Node<K, V>> objectHolder = new ObjectHolder<Node<K, V>>();
+    final ObjectHolder<Node<K, V>> objectHolder = new ObjectHolder<>();
 
     for (;;) {
       Function<K, Node<K, V>> f = k -> {
@@ -790,8 +790,8 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
         checkNotNull(value);
 
         final int weight = weigher.weightOf(key, value);
-        final WeightedValue<V> weightedValue = new WeightedValue<V>(value, weight);
-        final Node<K, V> node = new Node<K, V>(key, weightedValue);
+        final WeightedValue<V> weightedValue = new WeightedValue<>(value, weight);
+        final Node<K, V> node = new Node<>(key, weightedValue);
 
         objectHolder.setObject(node);
 
@@ -803,8 +803,8 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
       if (null == node) { // the entry is present
         V value = prior.getValue();
         final int weight = weigher.weightOf(key, value);
-        final WeightedValue<V> weightedValue = new WeightedValue<V>(value, weight);
-        node = new Node<K, V>(key, weightedValue);
+        final WeightedValue<V> weightedValue = new WeightedValue<>(value, weight);
+        node = new Node<>(key, weightedValue);
       } else {
         // the return value of `computeIfAbsent` is different from the one of `putIfAbsent`.
         // if the key is absent in map, the return value of `computeIfAbsent` is the newly computed value, but `putIfAbsent` return null.
@@ -887,7 +887,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
     checkNotNull(value);
 
     final int weight = weigher.weightOf(key, value);
-    final WeightedValue<V> weightedValue = new WeightedValue<V>(value, weight);
+    final WeightedValue<V> weightedValue = new WeightedValue<>(value, weight);
 
     final Node<K, V> node = data.get(key);
     if (node == null) {
@@ -917,7 +917,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
     checkNotNull(newValue);
 
     final int weight = weigher.weightOf(key, newValue);
-    final WeightedValue<V> newWeightedValue = new WeightedValue<V>(newValue, weight);
+    final WeightedValue<V> newWeightedValue = new WeightedValue<>(newValue, weight);
 
     final Node<K, V> node = data.get(key);
     if (node == null) {
@@ -1027,7 +1027,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
       final int initialCapacity = (weigher == Weighers.entrySingleton())
           ? Math.min(limit, (int) weightedSize())
           : 16;
-      final Set<K> keys = new LinkedHashSet<K>(initialCapacity);
+      final Set<K> keys = new LinkedHashSet<>(initialCapacity);
       final Iterator<Node<K, V>> iterator = ascending
           ? evictionDeque.iterator()
           : evictionDeque.descendingIterator();
@@ -1137,7 +1137,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
       final int initialCapacity = (weigher == Weighers.entrySingleton())
           ? Math.min(limit, (int) weightedSize())
           : 16;
-      final Map<K, V> map = new LinkedHashMap<K, V>(initialCapacity);
+      final Map<K, V> map = new LinkedHashMap<>(initialCapacity);
       final Iterator<Node<K, V>> iterator = ascending
           ? evictionDeque.iterator()
           : evictionDeque.descendingIterator();
@@ -1473,7 +1473,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
     }
 
     Object writeReplace() {
-      return new SimpleEntry<K, V>(this);
+      return new SimpleEntry<>(this);
     }
   }
 
@@ -1521,7 +1521,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
   static final long serialVersionUID = 1;
 
   Object writeReplace() {
-    return new SerializationProxy<K, V>(this);
+    return new SerializationProxy<>(this);
   }
 
   private void readObject(ObjectInputStream stream) throws InvalidObjectException {
@@ -1544,7 +1544,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
 
     SerializationProxy(ConcurrentLinkedHashMap<K, V> map) {
       concurrencyLevel = map.concurrencyLevel;
-      data = new HashMap<K, V>(map);
+      data = new HashMap<>(map);
       capacity = map.capacity.get();
       listener = map.listener;
       weigher = map.weigher;
@@ -1666,7 +1666,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
     public Builder<K, V> weigher(Weigher<? super V> weigher) {
       this.weigher = (weigher == Weighers.singleton())
           ? Weighers.entrySingleton()
-          : new BoundedEntryWeigher<K, V>(Weighers.asEntryWeigher(weigher));
+          : new BoundedEntryWeigher<>(Weighers.asEntryWeigher(weigher));
       return this;
     }
 
@@ -1693,7 +1693,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
      */
     public ConcurrentLinkedHashMap<K, V> build() {
       checkState(capacity >= 0);
-      return new ConcurrentLinkedHashMap<K, V>(this);
+      return new ConcurrentLinkedHashMap<>(this);
     }
   }
 }
diff --git a/src/main/java/org/apache/groovy/util/concurrent/concurrentlinkedhashmap/Weighers.java b/src/main/java/org/apache/groovy/util/concurrent/concurrentlinkedhashmap/Weighers.java
index 7d31e9a..5b7f7a4 100644
--- a/src/main/java/org/apache/groovy/util/concurrent/concurrentlinkedhashmap/Weighers.java
+++ b/src/main/java/org/apache/groovy/util/concurrent/concurrentlinkedhashmap/Weighers.java
@@ -44,7 +44,7 @@ public final class Weighers {
       final Weigher<? super V> weigher) {
     return (weigher == singleton())
         ? Weighers.entrySingleton()
-        : new EntryWeigherView<K, V>(weigher);
+        : new EntryWeigherView<>(weigher);
   }
 
   /**