11package com .ss .rlib .common .util .dictionary ;
22
3- import com .ss .rlib .common .function .TripleConsumer ;
3+ import com .ss .rlib .common .function .NotNullBiConsumer ;
4+ import com .ss .rlib .common .function .NotNullConsumer ;
5+ import com .ss .rlib .common .function .NotNullNullableBiFunction ;
6+ import com .ss .rlib .common .function .NotNullTripleConsumer ;
47import org .jetbrains .annotations .NotNull ;
58import org .jetbrains .annotations .Nullable ;
69
7- import java .util .function .BiConsumer ;
8- import java .util .function .BiFunction ;
9- import java .util .function .Consumer ;
10-
1110/**
1211 * The interface with methods for supporting thread-safe for the {@link ObjectDictionary}.
1312 *
@@ -25,7 +24,7 @@ public interface ConcurrentObjectDictionary<K, V> extends ObjectDictionary<K, V>
2524 * @return the new concurrent object dictionary.
2625 */
2726 static <T > @ NotNull ObjectDictionary <T , T > ofType (@ NotNull Class <? super T > keyValueType ) {
28- return DictionaryFactory .newConcurrentAtomicObjectDictionary ();
27+ return DictionaryFactory .newConcurrentStampedLockObjectDictionary ();
2928 }
3029
3130 /**
@@ -41,17 +40,17 @@ public interface ConcurrentObjectDictionary<K, V> extends ObjectDictionary<K, V>
4140 @ NotNull Class <? super K > keyType ,
4241 @ NotNull Class <? super V > valueType
4342 ) {
44- return DictionaryFactory .newConcurrentAtomicObjectDictionary ();
43+ return DictionaryFactory .newConcurrentStampedLockObjectDictionary ();
4544 }
4645
4746 /**
48- * Execute the function for this dictionary in the block {@link ConcurrentObjectDictionary#writeLock()}.
47+ * Execute a function for this dictionary under block {@link ConcurrentObjectDictionary#writeLock()}.
4948 *
5049 * @param consumer the function.
5150 * @return this dictionary.
5251 */
5352 default @ NotNull ConcurrentObjectDictionary <K , V > runInWriteLock (
54- @ NotNull Consumer < @ NotNull ConcurrentObjectDictionary <K , V >> consumer
53+ @ NotNull NotNullConsumer < ConcurrentObjectDictionary <K , V >> consumer
5554 ) {
5655
5756 var stamp = writeLock ();
@@ -65,20 +64,21 @@ public interface ConcurrentObjectDictionary<K, V> extends ObjectDictionary<K, V>
6564 }
6665
6766 /**
68- * Execute the function for this dictionary in the block {@link ConcurrentObjectDictionary#writeLock()}.
67+ * Execute a function for this dictionary under block {@link ConcurrentObjectDictionary#writeLock()}.
6968 *
70- * @param key the key value .
69+ * @param argument the argument .
7170 * @param consumer the function.
71+ * @param <A> the argument's type.
7272 * @return this dictionary.
7373 */
74- default @ NotNull ConcurrentObjectDictionary <K , V > runInWriteLock (
75- @ NotNull K key ,
76- @ NotNull BiConsumer < @ NotNull ConcurrentObjectDictionary <K , V >, @ NotNull K > consumer
74+ default < A > @ NotNull ConcurrentObjectDictionary <K , V > runInWriteLock (
75+ @ NotNull A argument ,
76+ @ NotNull NotNullBiConsumer < ConcurrentObjectDictionary <K , V >, A > consumer
7777 ) {
7878
7979 var stamp = writeLock ();
8080 try {
81- consumer .accept (this , key );
81+ consumer .accept (this , argument );
8282 } finally {
8383 writeUnlock (stamp );
8484 }
@@ -87,23 +87,24 @@ public interface ConcurrentObjectDictionary<K, V> extends ObjectDictionary<K, V>
8787 }
8888
8989 /**
90- * Execute the function for this dictionary in the block {@link ConcurrentObjectDictionary#writeLock()}.
90+ * Execute a function for this dictionary under block {@link ConcurrentObjectDictionary#writeLock()}.
9191 *
92- * @param key the key value .
93- * @param argument the additional argument,
92+ * @param first the first argument .
93+ * @param second the second argument.
9494 * @param consumer the function.
95- * @param <F> the argument's type.
95+ * @param <F> the first argument's type.
96+ * @param <S> the second argument's type.
9697 * @return this dictionary.
9798 */
98- default <F > @ NotNull ConcurrentObjectDictionary <K , V > runInWriteLock (
99- @ NotNull K key ,
100- @ NotNull F argument ,
101- @ NotNull TripleConsumer < @ NotNull ConcurrentObjectDictionary <K , V >, @ NotNull K , @ NotNull F > consumer
99+ default <F , S > @ NotNull ConcurrentObjectDictionary <K , V > runInWriteLock (
100+ @ NotNull F first ,
101+ @ NotNull S second ,
102+ @ NotNull NotNullTripleConsumer < ConcurrentObjectDictionary <K , V >, F , S > consumer
102103 ) {
103104
104105 var stamp = writeLock ();
105106 try {
106- consumer .accept (this , key , argument );
107+ consumer .accept (this , first , second );
107108 } finally {
108109 writeUnlock (stamp );
109110 }
@@ -112,40 +113,40 @@ public interface ConcurrentObjectDictionary<K, V> extends ObjectDictionary<K, V>
112113 }
113114
114115 /**
115- * Get the value using a function from a dictionary in the block {@link
116- * ConcurrentObjectDictionary#readLock()}.
116+ * Get the value from a function for this dictionary under block {@link ConcurrentObjectDictionary#readLock()}.
117117 *
118- * @param key the key value .
118+ * @param argument the argument .
119119 * @param function the function.
120+ * @param <A> the argument's type.
120121 * @return the result of the function.
121122 */
122- default @ Nullable V getInReadLock (
123- @ NotNull K key ,
124- @ NotNull BiFunction <ConcurrentObjectDictionary <K , V >, @ NotNull K , @ NotNull V > function
123+ default < A > @ Nullable V getInReadLock (
124+ @ NotNull A argument ,
125+ @ NotNull NotNullNullableBiFunction <ConcurrentObjectDictionary <K , V >, A , V > function
125126 ) {
126127 var stamp = readLock ();
127128 try {
128- return function .apply (this , key );
129+ return function .apply (this , argument );
129130 } finally {
130131 readUnlock (stamp );
131132 }
132133 }
133134
134135 /**
135- * Get the value using a function from a dictionary in the block {@link
136- * ConcurrentObjectDictionary#writeLock()}.
136+ * Get the value from a function for this dictionary under block {@link ConcurrentObjectDictionary#writeLock()}.
137137 *
138- * @param key the key value .
138+ * @param argument the argument .
139139 * @param function the function.
140+ * @param <A> the argument's type.
140141 * @return the result of the function.
141142 */
142- default @ Nullable V getInWriteLock (
143- @ NotNull K key ,
144- @ NotNull BiFunction <ConcurrentObjectDictionary <K , V >, @ NotNull K , @ NotNull V > function
143+ default < A > @ Nullable V getInWriteLock (
144+ @ NotNull A argument ,
145+ @ NotNull NotNullNullableBiFunction <ConcurrentObjectDictionary <K , V >, A , V > function
145146 ) {
146147 var stamp = writeLock ();
147148 try {
148- return function .apply (this , key );
149+ return function .apply (this , argument );
149150 } finally {
150151 writeUnlock (stamp );
151152 }
@@ -156,7 +157,7 @@ public interface ConcurrentObjectDictionary<K, V> extends ObjectDictionary<K, V>
156157 *
157158 * @param consumer the consumer.
158159 */
159- default void forEachInReadLock (@ NotNull BiConsumer < @ NotNull ? super K , @ NotNull ? super V > consumer ) {
160+ default void forEachInReadLock (@ NotNull NotNullBiConsumer < ? super K , ? super V > consumer ) {
160161 var stamp = readLock ();
161162 try {
162163 forEach (consumer );
0 commit comments