Class KeyHelper
-
- All Implemented Interfaces:
public final class KeyHelper<IMMUTABLE_KEY extends Object, MUTABLE_KEY extends Object>Utility class for a situation when we need to frequently use an immutable key (e.g. for checking shared ConcurrentHashMap content). We want to avoid creating new key objects all the time if a number of possible different key states is low and a number of threads which do the operation is also not big.
The general idea is to do the following:
Keep thread-local mutable key
Get a mutable key any time new immutable key is required
Modify mutable key within the current thread-local data
Keep a cache of mutable key -> immutable key
Query target immutable key by mutable key
Create new immutable key on the basis of the mutable key and store it if the cache doesn't have corresponding entry yet
-
-
Field Summary
Fields Modifier and Type Field Description private final MUTABLE_KEYmutableKey
-
Constructor Summary
Constructors Constructor Description KeyHelper(Function1<MUTABLE_KEY, IMMUTABLE_KEY> keyConverter, Function0<MUTABLE_KEY> mutableKeyCreator)
-
Method Summary
Modifier and Type Method Description final MUTABLE_KEYgetMutableKey()final IMMUTABLE_KEYgetImmutableKey(MUTABLE_KEY key)-
-
Constructor Detail
-
KeyHelper
KeyHelper(Function1<MUTABLE_KEY, IMMUTABLE_KEY> keyConverter, Function0<MUTABLE_KEY> mutableKeyCreator)
-
-
Method Detail
-
getMutableKey
final MUTABLE_KEY getMutableKey()
-
getImmutableKey
final IMMUTABLE_KEY getImmutableKey(MUTABLE_KEY key)
-
-
-
-