< prev index next >

src/java.base/share/classes/jdk/internal/util/concurrent/AbstractClassLoaderValue.java

Print this page

        

@@ -19,16 +19,17 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-package java.lang.reflect;
+package jdk.internal.util.concurrent;
 
 import jdk.internal.loader.BootLoader;
 import jdk.internal.misc.JavaLangAccess;
 import jdk.internal.misc.SharedSecrets;
 
+import java.lang.reflect.UndeclaredThrowableException;
 import java.util.Iterator;
 import java.util.Objects;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.BiFunction;
 import java.util.function.Supplier;

@@ -38,11 +39,11 @@
  * and {@link Sub sub}-ClassLoaderValue.
  *
  * @param <CLV> the type of concrete ClassLoaderValue (this type)
  * @param <V>   the type of values associated with ClassLoaderValue
  */
-abstract class AbstractClassLoaderValue<CLV extends AbstractClassLoaderValue<CLV, V>, V> {
+public abstract class AbstractClassLoaderValue<CLV extends AbstractClassLoaderValue<CLV, V>, V> {
 
     /**
      * Sole constructor.
      */
     AbstractClassLoaderValue() {}

@@ -149,10 +150,28 @@
     public boolean remove(ClassLoader cl, Object v) {
         return AbstractClassLoaderValue.<CLV>map(cl).remove(this, v);
     }
 
     /**
+     * Replaces the value associated with this ClassLoaderValue and given
+     * ClassLoader with {@code newV} if the associated value is equal to given
+     * value {@code oldV} and returns {@code true} or does nothing and returns
+     * {@code false} if there is no currently associated value or it is not equal
+     * to given value {@code oldV}.
+     *
+     * @param cl the ClassLoader for the associated value
+     * @param oldV  the value to compare with currently associated value
+     * @param newV  the value to associate if current value is equal to oldV
+     * @return {@code true} if the association was replaced or {@code false} if not
+     */
+    public boolean replace(ClassLoader cl, V oldV, V newV) {
+        @SuppressWarnings("unchecked")
+        CLV clv = (CLV) this;
+        return AbstractClassLoaderValue.<CLV>map(cl).replace(clv, oldV, newV);
+    }
+
+    /**
      * Returns the value associated with this ClassLoaderValue and given
      * ClassLoader if there is one or computes the value by invoking given
      * {@code mappingFunction}, associates it and returns it.
      * <p>
      * Computation and association of the computed value is performed atomically

@@ -375,11 +394,11 @@
      * sub-[sub-...]ClassLoaderValue instance in a type-safe way.
      *
      * @param <K> the type of {@link #key()} component contained in the
      *            sub-ClassLoaderValue.
      */
-    final class Sub<K> extends AbstractClassLoaderValue<Sub<K>, V> {
+    public final class Sub<K> extends AbstractClassLoaderValue<Sub<K>, V> {
 
         private final K key;
 
         Sub(K key) {
             this.key = key;
< prev index next >