1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -59,8 +59,8 @@ public CaffeineCache(String name, com.github.benmanes.caffeine.cache.Cache<Objec
59
59
* given internal {@link com.github.benmanes.caffeine.cache.Cache} to use.
60
60
* @param name the name of the cache
61
61
* @param cache the backing Caffeine Cache instance
62
- * @param allowNullValues whether to accept and convert {@code null}
63
- * values for this cache
62
+ * @param allowNullValues whether to accept and convert {@code null} values
63
+ * for this cache
64
64
*/
65
65
public CaffeineCache (String name , com .github .benmanes .caffeine .cache .Cache <Object , Object > cache ,
66
66
boolean allowNullValues ) {
@@ -86,7 +86,7 @@ public final com.github.benmanes.caffeine.cache.Cache<Object, Object> getNativeC
86
86
@ SuppressWarnings ("unchecked" )
87
87
@ Override
88
88
@ Nullable
89
- public <T > T get (Object key , final Callable <T > valueLoader ) {
89
+ public <T > T get (Object key , Callable <T > valueLoader ) {
90
90
return (T ) fromStoreValue (this .cache .get (key , new LoadFunction (valueLoader )));
91
91
}
92
92
@@ -106,7 +106,7 @@ public void put(Object key, @Nullable Object value) {
106
106
107
107
@ Override
108
108
@ Nullable
109
- public ValueWrapper putIfAbsent (Object key , @ Nullable final Object value ) {
109
+ public ValueWrapper putIfAbsent (Object key , @ Nullable Object value ) {
110
110
PutIfAbsentFunction callable = new PutIfAbsentFunction (value );
111
111
Object result = this .cache .get (key , callable );
112
112
return (callable .called ? null : toValueWrapper (result ));
@@ -140,7 +140,7 @@ private class PutIfAbsentFunction implements Function<Object, Object> {
140
140
@ Nullable
141
141
private final Object value ;
142
142
143
- private boolean called ;
143
+ boolean called ;
144
144
145
145
public PutIfAbsentFunction (@ Nullable Object value ) {
146
146
this .value = value ;
@@ -159,16 +159,17 @@ private class LoadFunction implements Function<Object, Object> {
159
159
private final Callable <?> valueLoader ;
160
160
161
161
public LoadFunction (Callable <?> valueLoader ) {
162
+ Assert .notNull (valueLoader , "Callable must not be null" );
162
163
this .valueLoader = valueLoader ;
163
164
}
164
165
165
166
@ Override
166
- public Object apply (Object o ) {
167
+ public Object apply (Object key ) {
167
168
try {
168
169
return toStoreValue (this .valueLoader .call ());
169
170
}
170
171
catch (Exception ex ) {
171
- throw new ValueRetrievalException (o , this .valueLoader , ex );
172
+ throw new ValueRetrievalException (key , this .valueLoader , ex );
172
173
}
173
174
}
174
175
}
0 commit comments