13
13
* This interface can be thought as a superset of {@link java.util.Map};
14
14
* less functionality is required here to achieve greater compatibility.
15
15
* <p>
16
- * There cannot be duplicate keys and null values are not necessarily supported .
16
+ * There cannot be duplicate keys, and null keys or values are not permitted .
17
17
* <p>
18
18
* Instances should be thread-safe, but no guarantee is made whether
19
19
* this is achieved through fine-grained locking or blunt synchronization.
@@ -30,10 +30,10 @@ public interface Cache<K, V> {
30
30
*
31
31
* @param key the key whose mapped value should be queried
32
32
* @return the value associated with the key in the cache, or null if no such mapping was found
33
- * @throws NullPointerException if the specified key is null and this implementation does not permit null keys
33
+ * @throws NullPointerException if the specified key is null
34
34
*/
35
35
@ Nullable
36
- V get (K key );
36
+ V get (@ NotNull K key );
37
37
38
38
/**
39
39
* Associates the specified key with the specified value,
@@ -42,20 +42,20 @@ public interface Cache<K, V> {
42
42
* @param key the key whose mapping should be created or updated
43
43
* @param value the value to be associated with the specified key
44
44
* @return the previous value associated with the key, or null if no prior mapping existed
45
- * @throws NullPointerException if the specified key or value is null and this cache does not permit null keys or values
45
+ * @throws NullPointerException if the specified key or value is null
46
46
*/
47
47
@ Nullable
48
- V put (K key , V value );
48
+ V put (@ NotNull K key , @ NotNull V value );
49
49
50
50
/**
51
51
* Deletes any mapping that may exist for the specified key.
52
52
*
53
53
* @param key the key whose mapping should be deleted
54
54
* @return the value in the removed mapping, or null if no mapping existed
55
- * @throws NullPointerException if the specified key is null and this cache does not permit null keys
55
+ * @throws NullPointerException if the specified key is null
56
56
*/
57
57
@ Nullable
58
- V remove (K key );
58
+ V remove (@ NotNull K key );
59
59
60
60
/**
61
61
* Removes all entries from the cache.
@@ -73,11 +73,11 @@ public interface Cache<K, V> {
73
73
* @param key the key with which the specified value is to be associated
74
74
* @param computeFunc the function to compute a value
75
75
* @return the new value associated with the specified key, or null if none
76
- * @throws NullPointerException if the specified key is null and this cache does not support null keys, or the compute function is null
76
+ * @throws NullPointerException if the specified key is null or the compute function is null
77
77
* @implNote atomicity is dependent on provider characteristics
78
78
*/
79
79
@ Nullable
80
- V compute (K key , @ NotNull BiFunction <? super K , ? super V , ? extends V > computeFunc );
80
+ V compute (@ NotNull K key , @ NotNull BiFunction <? super K , ? super V , ? extends V > computeFunc );
81
81
82
82
/**
83
83
* Obtains the value currently associated with the specified key,
@@ -86,9 +86,9 @@ public interface Cache<K, V> {
86
86
* @param key the key whose mapping should be created or returned
87
87
* @param computeFunc the value supplier for a given key, if no mapping already existed
88
88
* @return the current (existing or computed) value associated with the key
89
- * @throws NullPointerException if the specified key is null and this cache does not permit null keys, or the compute function is null
89
+ * @throws NullPointerException if the specified key is null or the compute function is null
90
90
*/
91
- V computeIfAbsent (K key , @ NotNull Function <K , V > computeFunc );
91
+ V computeIfAbsent (@ NotNull K key , @ NotNull Function <K , V > computeFunc );
92
92
93
93
/**
94
94
* Computes a new value for a specific key, if a mapping already existed.
@@ -98,10 +98,10 @@ public interface Cache<K, V> {
98
98
* @param key the key whose mapping should be updated
99
99
* @param computeFunc the function to compute the new value for an already existing mapping
100
100
* @return the new value associated with the key, or null if none
101
- * @throws NullPointerException if the specified key is null and this cache does not support null keys, or the compute function is null
101
+ * @throws NullPointerException if the specified key is null or the compute function is null
102
102
*/
103
103
@ Nullable
104
- V computeIfPresent (K key , @ NotNull BiFunction <? super K , ? super V , ? extends V > computeFunc );
104
+ V computeIfPresent (@ NotNull K key , @ NotNull BiFunction <? super K , ? super V , ? extends V > computeFunc );
105
105
106
106
/**
107
107
* Creates a mapping from the specified key to the specified value,
@@ -110,10 +110,10 @@ public interface Cache<K, V> {
110
110
* @param key the key whose mapping should be created or returned
111
111
* @param value the value that should be associated with the key if no prior mapping exists
112
112
* @return the previous value associated with the key, or null if no mapping already existed
113
- * @throws NullPointerException if the specified key or value is null and this cache does not permit null keys or values
113
+ * @throws NullPointerException if the specified key or value is null
114
114
*/
115
115
@ Nullable
116
- V putIfAbsent (K key , V value );
116
+ V putIfAbsent (@ NotNull K key , @ NotNull V value );
117
117
118
118
/**
119
119
* Associates the key with the specified value (or the result of the atomic merge function if a mapping already existed).
@@ -122,19 +122,19 @@ public interface Cache<K, V> {
122
122
* @param value the value to be associated with the key or merged with the existing mapped value
123
123
* @param mergeFunc the function that takes the existing value and the new value to compute a merged value
124
124
* @return the latest value associated with the specified key
125
- * @throws NullPointerException if the specified key is null and this cache does not support null keys or the value or mergeFunc is null
125
+ * @throws NullPointerException if the specified key or the value or mergeFunc is null
126
126
*/
127
- V merge (K key , V value , @ NotNull BiFunction <V , V , V > mergeFunc );
127
+ V merge (@ NotNull K key , @ NotNull V value , @ NotNull BiFunction <V , V , V > mergeFunc );
128
128
129
129
/**
130
130
* Replaces the entry for the specified key only if it is currently mapped to some value.
131
131
*
132
132
* @param key the key whose mapped value should be updated
133
133
* @param value the value to be associated with the specified key
134
134
* @return whether a replacement occurred (a prior mapping must have existed to return true)
135
- * @throws NullPointerException if the specified key or value is null, and this cache does not permit null keys or values
135
+ * @throws NullPointerException if the specified key or value is null
136
136
*/
137
- boolean replace (K key , V value );
137
+ boolean replace (@ NotNull K key , @ NotNull V value );
138
138
139
139
/**
140
140
* Replaces the value for the specified key only if it is currently mapped to the specified old value.
@@ -143,15 +143,15 @@ public interface Cache<K, V> {
143
143
* @param oldValue the value expected to be already associated with the specified key
144
144
* @param newValue the value to be newly associated with the specified key
145
145
* @return whether a replacement occurred
146
- * @throws NullPointerException if a specified key or newValue is null, and this cache does not permit null keys or values
146
+ * @throws NullPointerException if a specified key or newValue is null
147
147
*/
148
- boolean replace (K key , V oldValue , V newValue );
148
+ boolean replace (@ NotNull K key , @ NotNull V oldValue , @ NotNull V newValue );
149
149
150
150
/**
151
151
* Copies all of the mappings from the specified map to this cache.
152
152
*
153
153
* @param map the map whose entries should be added to this cache
154
- * @throws NullPointerException if the specified map is null, or if this cache does not permit null keys or values, and the specified map contains null keys or values
154
+ * @throws NullPointerException if the map is null, or the specified map contains null keys or values
155
155
* @implNote There is no behavior guarantee when there are concurrent updates to the map
156
156
*/
157
157
default void putAll (@ NotNull Map <? extends K , ? extends V > map ) {
0 commit comments