Class MapUtils

java.lang.Object
reactor.netty.internal.util.MapUtils

public final class MapUtils extends Object
This class contains temporary workarounds for Java 8 Map issues.

Note: This utility class is for internal use only. It can be removed at any time.

Since:
1.0.15
Author:
zimatars
  • Method Details

    • calculateInitialCapacity

      public static int calculateInitialCapacity(int expectedSize)
      This is a temporary workaround for Java 8 issue https://bugs.openjdk.org/browse/JDK-8186958. Fix is available in Java 19.

      Calculate the initial capacity for the Map from the expected size and the default load factor for the Map (0.75).

      Parameters:
      expectedSize - the expected size
      Returns:
      the initial capacity for the Map
      Since:
      1.0.31
    • computeIfAbsent

      public static <K, V> V computeIfAbsent(Map<K,V> map, K key, Function<K,V> mappingFunction)
      This is a temporary workaround for Java 8 specific performance issue https://bugs.openjdk.org/browse/JDK-8161372. Fix is available in Java 9.

      ConcurrentHashMap.computeIfAbsent(k,v) locks when k is present. Add pre-screen before locking inside computeIfAbsent.

      Note: This utility is not for a general purpose usage. Carefully consider the removal operations from the map. If you have many remove operations that are critical, do not use this pre-screening.

      Parameters:
      map - the ConcurrentHashMap instance
      key - key with which the specified value is to be associated
      mappingFunction - the function to compute a value
      Returns:
      the current (existing or computed) value associated with the specified key, or null if the computed value is null