Skip to content

Commit 6d9e36e

Browse files
committed
Minor post-merge cleanup
1 parent 3e8d4ae commit 6d9e36e

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/SerializerCache.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.fasterxml.jackson.core.util.Snapshottable;
66
import com.fasterxml.jackson.databind.*;
77
import com.fasterxml.jackson.databind.ser.impl.ReadOnlyClassToSerializerMap;
8-
import com.fasterxml.jackson.databind.util.LookupCache;
98
import com.fasterxml.jackson.databind.util.SimpleLookupCache;
109
import com.fasterxml.jackson.databind.util.TypeKey;
1110

@@ -41,7 +40,7 @@ public final class SerializerCache
4140
* NOTE: keys are of various types (see below for key types), in addition to
4241
* basic {@link JavaType} used for "untyped" serializers.
4342
*/
44-
private final LookupCache<TypeKey, JsonSerializer<Object>> _sharedMap;
43+
private final SimpleLookupCache<TypeKey, JsonSerializer<Object>> _sharedMap;
4544

4645
/**
4746
* Most recent read-only instance, created from _sharedMap, if any.
@@ -61,7 +60,7 @@ public SerializerCache(int maxCached) {
6160
_readOnlyMap = new AtomicReference<ReadOnlyClassToSerializerMap>();
6261
}
6362

64-
protected SerializerCache(LookupCache<TypeKey, JsonSerializer<Object>> shared) {
63+
protected SerializerCache(SimpleLookupCache<TypeKey, JsonSerializer<Object>> shared) {
6564
_sharedMap = shared;
6665
_readOnlyMap = new AtomicReference<ReadOnlyClassToSerializerMap>();
6766
}

src/main/java/com/fasterxml/jackson/databind/ser/impl/ReadOnlyClassToSerializerMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.fasterxml.jackson.databind.JavaType;
44
import com.fasterxml.jackson.databind.JsonSerializer;
55
import com.fasterxml.jackson.databind.ser.SerializerCache;
6-
import com.fasterxml.jackson.databind.util.LookupCache;
6+
import com.fasterxml.jackson.databind.util.SimpleLookupCache;
77
import com.fasterxml.jackson.databind.util.TypeKey;
88

99
/**
@@ -27,7 +27,7 @@ public final class ReadOnlyClassToSerializerMap
2727
private final int _mask;
2828

2929
protected ReadOnlyClassToSerializerMap(SerializerCache shared,
30-
LookupCache<TypeKey, JsonSerializer<Object>> src)
30+
SimpleLookupCache<TypeKey, JsonSerializer<Object>> src)
3131
{
3232
_sharedCache = shared;
3333
_size = findSize(src.size());
@@ -55,7 +55,7 @@ private final static int findSize(int size)
5555
* Factory method for constructing an instance.
5656
*/
5757
public static ReadOnlyClassToSerializerMap from(SerializerCache shared,
58-
LookupCache<TypeKey, JsonSerializer<Object>> src) {
58+
SimpleLookupCache<TypeKey, JsonSerializer<Object>> src) {
5959
return new ReadOnlyClassToSerializerMap(shared, src);
6060
}
6161

src/main/java/com/fasterxml/jackson/databind/util/LookupCache.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,33 @@
22

33
import com.fasterxml.jackson.core.util.Snapshottable;
44

5-
import java.util.function.BiConsumer;
6-
75
/**
86
* An interface describing the required API for the Jackson-Databind Type cache.
7+
*<p>
8+
* Note that while interface itself does not specify synchronization requirements for
9+
* implementations, specific use cases do. Typically implementations are
10+
* expected to be thread-safe, that is, to handle synchronization.
911
*
1012
* @see com.fasterxml.jackson.databind.type.TypeFactory#withCache(LookupCache<java.lang.Object,com.fasterxml.jackson.databind.JavaType>)
1113
* @see SimpleLookupCache
1214
*/
1315
public interface LookupCache <K,V>
14-
extends Snapshottable<LookupCache<K,V>> {
15-
16-
void contents(BiConsumer<K,V> consumer);
16+
extends Snapshottable<LookupCache<K,V>>
17+
{
18+
// 17-Sep-2019, tatu: There is one usage, by `ReadOnlyClassToSerializerMap`, so
19+
// for now NOT exposed, but can reconsider if it proves generally useful
20+
21+
// void contents(BiConsumer<K,V> consumer);
1722

23+
/**
24+
* @return Number of entries currently in cache: may be approximate, only
25+
* to be used for diagnostics, metrics reporting
26+
*/
1827
int size();
1928

2029
/**
2130
* NOTE: key is of type Object only to retain binary backwards-compatibility
31+
*
2232
* @param key
2333
* @return value associated with key (can return null)
2434
*/
@@ -28,5 +38,8 @@ public interface LookupCache <K,V>
2838

2939
V putIfAbsent(K key, V value);
3040

41+
/**
42+
* Method for removing all contents this cache has.
43+
*/
3144
void clear();
3245
}

src/main/java/com/fasterxml/jackson/databind/util/SimpleLookupCache.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,16 @@ protected Object readResolve() {
5252
}
5353

5454
@Override
55-
public LookupCache<K, V> snapshot() {
55+
public SimpleLookupCache<K,V> snapshot() {
5656
return new SimpleLookupCache<K,V>(_initialEntries, _maxEntries);
5757
}
5858

59-
@Override
60-
public void contents(BiConsumer<K,V> consumer) {
61-
for (Map.Entry<K,V> entry : _map.entrySet()) {
62-
consumer.accept(entry.getKey(), entry.getValue());
63-
}
64-
}
65-
6659
/*
6760
/**********************************************************************
68-
/* Public API
61+
/* Public API, basic lookup/additions
6962
/**********************************************************************
7063
*/
64+
7165
@Override
7266
public V put(K key, V value) {
7367
if (_map.size() >= _maxEntries) {
@@ -103,4 +97,16 @@ public V putIfAbsent(K key, V value) {
10397

10498
@Override
10599
public int size() { return _map.size(); }
100+
101+
/*
102+
/**********************************************************************
103+
/* Extended API
104+
/**********************************************************************
105+
*/
106+
107+
public void contents(BiConsumer<K,V> consumer) {
108+
for (Map.Entry<K,V> entry : _map.entrySet()) {
109+
consumer.accept(entry.getKey(), entry.getValue());
110+
}
111+
}
106112
}

src/test/java/com/fasterxml/jackson/databind/util/UnlimitedLookupCache.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.fasterxml.jackson.databind.util;
22

3-
import java.util.Map;
43
import java.util.concurrent.ConcurrentHashMap;
5-
import java.util.function.BiConsumer;
64

75
/**
86
* A LookupCache implementation that has no synchronization (like SimpleLookupCache does)
@@ -26,12 +24,14 @@ public LookupCache<K, V> snapshot() {
2624
return new UnlimitedLookupCache<K,V>(_initialEntries, _maxEntries);
2725
}
2826

27+
/*
2928
@Override
3029
public void contents(BiConsumer<K, V> consumer) {
3130
for (Map.Entry<K,V> entry : _map.entrySet()) {
3231
consumer.accept(entry.getKey(), entry.getValue());
3332
}
3433
}
34+
*/
3535

3636
@Override
3737
public int size() {

src/test/java/com/fasterxml/jackson/databind/util/UnlimitedLookupCacheTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.JavaType;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
65
import com.fasterxml.jackson.databind.type.TypeFactory;
76
import org.junit.Test;
87

@@ -28,7 +27,8 @@ public void testCache() {
2827
public void testCompatibility() throws JsonProcessingException {
2928
UnlimitedLookupCache<Object, JavaType> cache = new UnlimitedLookupCache<>(4, 10);
3029
TypeFactory tf = TypeFactory.defaultInstance().withCache(cache);
31-
30+
assertNotNull(tf); // just to get rid of warning
31+
3232
//TODO find way to inject the `tf` instance into an ObjectMapper (via MapperBuilder?)
3333

3434
//ObjectMapper mapper = new ObjectMapper();

0 commit comments

Comments
 (0)