Skip to content

Commit 6d2720c

Browse files
Make NativeMemoryMap KEY_TYPE and VALUE_TYPE extend Any to disallow nullable types.
1 parent a22210b commit 6d2720c

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

src/main/kotlin/com/target/nativememoryallocator/map/NativeMemoryMap.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ interface BaseNativeMemoryMap {
3232
* Keys are stored as normal on-heap objects in the map.
3333
* Each value is serialized using NativeMemoryMapSerializer and copied into a NativeMemoryBuffer.
3434
* NativeMemoryMap is safe for use by multiple concurrent threads.
35+
* [KEY_TYPE] and [VALUE_TYPE] extend [Any] to disallow nullable key and value types.
3536
*/
36-
interface NativeMemoryMap<KEY_TYPE, VALUE_TYPE> : BaseNativeMemoryMap {
37+
interface NativeMemoryMap<KEY_TYPE : Any, VALUE_TYPE : Any> : BaseNativeMemoryMap {
3738

3839
/**
3940
* The result of a put operation on the map.

src/main/kotlin/com/target/nativememoryallocator/map/NativeMemoryMapBuilder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ interface CaffeineConfigBuilder {
7171
* @property threadLocalOnHeapReadBufferInitialCapacityBytes initial capacity in bytes for [ThreadLocal] on-heap read buffers.
7272
* @property caffeineConfigFunction caffeine config function
7373
*/
74-
data class NativeMemoryMapBuilder<KEY_TYPE, VALUE_TYPE>(
74+
data class NativeMemoryMapBuilder<KEY_TYPE : Any, VALUE_TYPE : Any>(
7575
private val valueSerializer: NativeMemoryMapSerializer<VALUE_TYPE>,
7676
private val nativeMemoryAllocator: NativeMemoryAllocator,
7777
private val enableOperationCounters: Boolean = false,
@@ -89,7 +89,7 @@ data class NativeMemoryMapBuilder<KEY_TYPE, VALUE_TYPE>(
8989

9090
val nativeMemoryMap = when (backend) {
9191
NativeMemoryMapBackend.CONCURRENT_HASH_MAP -> {
92-
NativeMemoryMapImpl(
92+
NativeMemoryMapImpl<KEY_TYPE, VALUE_TYPE>(
9393
valueSerializer = valueSerializer,
9494
nativeMemoryAllocator = nativeMemoryAllocator,
9595
useThreadLocalOnHeapReadBuffer = useThreadLocalOnHeapReadBuffer,

src/main/kotlin/com/target/nativememoryallocator/map/impl/CaffeineNativeMemoryMapImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ internal fun <KEY_TYPE> buildCaffeineCache(
102102
* @param caffeineCache caffeine cache instance
103103
* @param nativeMemoryMap [NativeMemoryMap] instance for delegation
104104
*/
105-
internal class CaffeineNativeMemoryMapImpl<KEY_TYPE, VALUE_TYPE>(
105+
internal class CaffeineNativeMemoryMapImpl<KEY_TYPE : Any, VALUE_TYPE : Any>(
106106
private val caffeineCache: Cache<KEY_TYPE, NativeMemoryBuffer>,
107107
nativeMemoryMap: NativeMemoryMap<KEY_TYPE, VALUE_TYPE>,
108108
) : NativeMemoryMap<KEY_TYPE, VALUE_TYPE> by nativeMemoryMap {

src/main/kotlin/com/target/nativememoryallocator/map/impl/NativeMemoryMapImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentMap
2424
* @param threadLocalOnHeapReadBufferInitialCapacityBytes initial capacity in bytes for [ThreadLocal] on-heap read buffers.
2525
* @param cacheMap [ConcurrentMap] of keys to [NativeMemoryBuffer] backing this map instance.
2626
*/
27-
internal class NativeMemoryMapImpl<KEY_TYPE, VALUE_TYPE>(
27+
internal class NativeMemoryMapImpl<KEY_TYPE : Any, VALUE_TYPE : Any>(
2828
private val valueSerializer: NativeMemoryMapSerializer<VALUE_TYPE>,
2929
private val nativeMemoryAllocator: NativeMemoryAllocator,
3030
useThreadLocalOnHeapReadBuffer: Boolean,

src/main/kotlin/com/target/nativememoryallocator/map/impl/OperationCountedNativeMemoryMapImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal data class OperationCountersImpl(
5050
*
5151
* @param nativeMemoryMap [NativeMemoryMap] instance for delegation.
5252
*/
53-
internal class OperationCountedNativeMemoryMapImpl<KEY_TYPE, VALUE_TYPE>(
53+
internal class OperationCountedNativeMemoryMapImpl<KEY_TYPE : Any, VALUE_TYPE : Any>(
5454
private val nativeMemoryMap: NativeMemoryMap<KEY_TYPE, VALUE_TYPE>,
5555
) : NativeMemoryMap<KEY_TYPE, VALUE_TYPE> by nativeMemoryMap {
5656

0 commit comments

Comments
 (0)