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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9d2890ff59 org.apache.juneau.common.reflect API improvements
9d2890ff59 is described below

commit 9d2890ff59776bbd6b79a54c9d0193b8bbe7eae7
Author: James Bognar <[email protected]>
AuthorDate: Thu Nov 20 12:18:27 2025 -0500

    org.apache.juneau.common.reflect API improvements
---
 .../apache/juneau/common/collections/Cache.java    | 112 ++++++++++++++++++++-
 .../org/apache/juneau/common/utils/ClassUtils.java |   2 +-
 2 files changed, 108 insertions(+), 6 deletions(-)

diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache.java
index e1655bd6fc..9fa526b204 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/collections/Cache.java
@@ -146,9 +146,9 @@ import java.util.function.*;
  * @param <K> The key type. Can be an array type for content-based key 
matching.
  * @param <V> The value type.
  */
-public class Cache<K,V> extends ConcurrentHashMap1Key<K,V> {
+public class Cache<K,V> implements java.util.Map<K,V> {
 
-       private static final long serialVersionUID = 1L;
+       private final ConcurrentHashMap1Key<K,V> map = new 
ConcurrentHashMap1Key<>();
 
        /**
         * Builder for creating configured {@link Cache} instances.
@@ -486,21 +486,42 @@ public class Cache<K,V> extends 
ConcurrentHashMap1Key<K,V> {
                assertArgNotNull("key", key);
                if (disableCaching)
                        return supplier.get();
-               V v = getKey(key);
+               V v = map.getKey(key);
                if (v == null) {
                        if (size() > maxSize)
                                clear();
                        v = supplier.get();
                        if (v == null)
-                               
super.remove(org.apache.juneau.common.function.Tuple1.of(key));
+                               remove(key);
                        else
-                               putKey(key, v);
+                               map.putKey(key, v);
                } else {
                        cacheHits.incrementAndGet();
                }
                return v;
        }
 
+       /**
+        * Associates the specified value with the specified key in this cache.
+        *
+        * <h5 class='section'>Example:</h5>
+        * <p class='bjava'>
+        *      Cache&lt;String,Pattern&gt; <jv>cache</jv> = 
Cache.<jsm>of</jsm>(String.<jk>class</jk>, Pattern.<jk>class</jk>).build();
+        *
+        *      Pattern <jv>pattern</jv> = Pattern.compile(<js>"[0-9]+"</js>);
+        *      <jv>cache</jv>.put(<js>"digits"</js>, <jv>pattern</jv>);
+        * </p>
+        *
+        * @param key The cache key. Must not be <jk>null</jk>.
+        * @param value The value to associate with the key.
+        * @return The previous value associated with the key, or <jk>null</jk> 
if there was no mapping for the key.
+        * @throws IllegalArgumentException if key is <jk>null</jk>.
+        */
+       public V put(K key, V value) {
+               assertArgNotNull("key", key);
+               return map.putKey(key, value);
+       }
+
 
        /**
         * Returns the total number of cache hits since this cache was created.
@@ -529,4 +550,85 @@ public class Cache<K,V> extends ConcurrentHashMap1Key<K,V> 
{
         * @return The total number of cache hits since creation.
         */
        public int getCacheHits() { return cacheHits.get(); }
+
+       /**
+        * Returns the number of entries currently in the cache.
+        *
+        * @return The number of cached entries.
+        */
+       @Override /* Map */
+       public int size() {
+               return map.size();
+       }
+
+       /**
+        * Returns a collection view of the values contained in this cache.
+        *
+        * @return A collection view of the values.
+        */
+       @Override /* Map */
+       public java.util.Collection<V> values() {
+               return map.values();
+       }
+
+       /**
+        * Returns <jk>true</jk> if this cache contains no entries.
+        *
+        * @return <jk>true</jk> if this cache contains no entries.
+        */
+       @Override /* Map */
+       public boolean isEmpty() {
+               return map.isEmpty();
+       }
+
+       /**
+        * Removes all entries from the cache.
+        *
+        * <p>
+        * Note: This does not reset the cache hit counter.
+        */
+       @Override /* Map */
+       public void clear() {
+               map.clear();
+       }
+
+       /**
+        * Removes the specified key from the cache.
+        *
+        * @param key The key to remove. Must not be <jk>null</jk>.
+        * @return The previous value associated with the key, or <jk>null</jk> 
if there was no mapping.
+        * @throws IllegalArgumentException if key is <jk>null</jk>.
+        */
+       @Override /* Map */
+       public V remove(Object key) {
+               assertArgNotNull("key", key);
+               return 
map.remove(org.apache.juneau.common.function.Tuple1.of(key));
+       }
+
+       @Override /* Map */
+       public boolean containsKey(Object key) {
+               return 
map.containsKey(org.apache.juneau.common.function.Tuple1.of(key));
+       }
+
+       @Override /* Map */
+       public boolean containsValue(Object value) {
+               return map.containsValue(value);
+       }
+
+       @Override /* Map */
+       public void putAll(java.util.Map<? extends K, ? extends V> m) {
+               m.forEach((k, v) -> put(k, v));
+       }
+
+       @Override /* Map */
+       public java.util.Set<K> keySet() {
+               return 
map.keySet().stream().map(org.apache.juneau.common.function.Tuple1::getA).collect(java.util.stream.Collectors.toSet());
+       }
+
+       @Override /* Map */
+       public java.util.Set<java.util.Map.Entry<K, V>> entrySet() {
+               return map.entrySet().stream()
+                       .map(e -> new 
java.util.AbstractMap.SimpleEntry<>(e.getKey().getA(), e.getValue()))
+                       .collect(java.util.stream.Collectors.toSet());
+       }
 }
diff --git 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
index e71f1b3fd2..be981c5418 100644
--- 
a/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
+++ 
b/juneau-core/juneau-common/src/main/java/org/apache/juneau/common/utils/ClassUtils.java
@@ -729,7 +729,7 @@ public class ClassUtils {
                if (b == null) {
                        var name = c.getName();
                        b = (! name.contains("Immutable") && ! 
name.contains("Unmodifiable") && ! name.contains("Arrays$ArrayList"));
-                       MODIFIABLE_COLLECTION_TYPES.putKey(c, b);
+                       MODIFIABLE_COLLECTION_TYPES.put(c, b);
                }
                return b;
        }

Reply via email to