From 52330fa45dc820ec2da7796e2706d33cef449382 Mon Sep 17 00:00:00 2001 From: "Kim, Joo Hyuk" Date: Wed, 13 Sep 2023 01:54:39 +0900 Subject: [PATCH] Add LookUpCache.contents() (#4114) --- .../fasterxml/jackson/databind/util/LRUMap.java | 7 +------ .../jackson/databind/util/LookupCache.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/util/LRUMap.java b/src/main/java/com/fasterxml/jackson/databind/util/LRUMap.java index 2d67236b1e..b60c530939 100644 --- a/src/main/java/com/fasterxml/jackson/databind/util/LRUMap.java +++ b/src/main/java/com/fasterxml/jackson/databind/util/LRUMap.java @@ -74,12 +74,7 @@ public V putIfAbsent(K key, V value) { @Override public int size() { return _map.size(); } - /* - /********************************************************************** - /* Extended API (2.14) - /********************************************************************** - */ - + @Override public void contents(BiConsumer consumer) { for (Map.Entry entry : _map.entrySet()) { consumer.accept(entry.getKey(), entry.getValue()); diff --git a/src/main/java/com/fasterxml/jackson/databind/util/LookupCache.java b/src/main/java/com/fasterxml/jackson/databind/util/LookupCache.java index 777a97b82c..2d668f0611 100644 --- a/src/main/java/com/fasterxml/jackson/databind/util/LookupCache.java +++ b/src/main/java/com/fasterxml/jackson/databind/util/LookupCache.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.databind.util; +import java.util.function.BiConsumer; + /** * An interface describing the required API for the Jackson-databind Type cache. *

@@ -11,6 +13,20 @@ */ public interface LookupCache { + /** + * Method to apply operation on cache contents without exposing them. + *

+ * Default implementation throws {@link UnsupportedOperationException}. + * Implementations are required to override this method. + * + * @since 2.16 + * @throws UnsupportedOperationException if implementation does not override this method. + * @param consumer Operation to apply on cache contents. + */ + default void contents(BiConsumer consumer) { + throw new UnsupportedOperationException(); + } + /** * Method needed for creating clones but without contents. *