@@ -43,6 +43,29 @@ public interface ConcurrentObjectDictionary<K, V> extends ObjectDictionary<K, V>
4343 return DictionaryFactory .newConcurrentStampedLockObjectDictionary ();
4444 }
4545
46+ /**
47+ * Execute a function for this dictionary under block {@link ConcurrentObjectDictionary#readLock()}.
48+ *
49+ * @param argument the argument.
50+ * @param consumer the function.
51+ * @param <A> the argument's type.
52+ * @return this dictionary.
53+ */
54+ default <A > @ NotNull ConcurrentObjectDictionary <K , V > runInReadLock (
55+ @ NotNull A argument ,
56+ @ NotNull NotNullBiConsumer <ConcurrentObjectDictionary <K , V >, A > consumer
57+ ) {
58+
59+ var stamp = readLock ();
60+ try {
61+ consumer .accept (this , argument );
62+ } finally {
63+ readUnlock (stamp );
64+ }
65+
66+ return this ;
67+ }
68+
4669 /**
4770 * Execute a function for this dictionary under block {@link ConcurrentObjectDictionary#writeLock()}.
4871 *
@@ -118,11 +141,12 @@ public interface ConcurrentObjectDictionary<K, V> extends ObjectDictionary<K, V>
118141 * @param argument the argument.
119142 * @param function the function.
120143 * @param <A> the argument's type.
144+ * @param <R> the result's type.
121145 * @return the result of the function.
122146 */
123- default <A > @ Nullable V getInReadLock (
147+ default <A , R > @ Nullable R getInReadLock (
124148 @ NotNull A argument ,
125- @ NotNull NotNullNullableBiFunction <ConcurrentObjectDictionary <K , V >, A , V > function
149+ @ NotNull NotNullNullableBiFunction <ConcurrentObjectDictionary <K , V >, A , R > function
126150 ) {
127151 var stamp = readLock ();
128152 try {
@@ -138,11 +162,12 @@ public interface ConcurrentObjectDictionary<K, V> extends ObjectDictionary<K, V>
138162 * @param argument the argument.
139163 * @param function the function.
140164 * @param <A> the argument's type.
165+ * @param <R> the result's type.
141166 * @return the result of the function.
142167 */
143- default <A > @ Nullable V getInWriteLock (
168+ default <A , R > @ Nullable R getInWriteLock (
144169 @ NotNull A argument ,
145- @ NotNull NotNullNullableBiFunction <ConcurrentObjectDictionary <K , V >, A , V > function
170+ @ NotNull NotNullNullableBiFunction <ConcurrentObjectDictionary <K , V >, A , R > function
146171 ) {
147172 var stamp = writeLock ();
148173 try {
0 commit comments