From 0385f387d9096de6a82c16f3eeb27731c1ab228d Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 16 Sep 2022 16:33:17 +0100 Subject: [PATCH] using value notion instead of key for the elements in the circular cache --- docs/unit_testing.md | 4 ++-- .../im/vector/app/features/notifications/CircularCache.kt | 6 +++--- .../vector/app/features/notifications/CircularCacheTest.kt | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/unit_testing.md b/docs/unit_testing.md index 5643e9709c..f786c9a160 100644 --- a/docs/unit_testing.md +++ b/docs/unit_testing.md @@ -259,8 +259,8 @@ private fun createIntCache(cacheSize: Int): Pair, Array return CircularCache(cacheSize, factory) to internalData!! } -private fun CircularCache.putInOrder(vararg keys: Int) { - keys.forEach { put(it) } +private fun CircularCache.putInOrder(vararg values: Int) { + values.forEach { put(it) } } ``` diff --git a/vector/src/main/java/im/vector/app/features/notifications/CircularCache.kt b/vector/src/main/java/im/vector/app/features/notifications/CircularCache.kt index 5c751e0d55..6c9b8b2e6c 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/CircularCache.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/CircularCache.kt @@ -29,13 +29,13 @@ class CircularCache(cacheSize: Int, factory: (Int) -> Array) { private val cache = factory(cacheSize) private var writeIndex = 0 - fun contains(key: T): Boolean = cache.contains(key) + fun contains(value: T): Boolean = cache.contains(value) - fun put(key: T) { + fun put(value: T) { if (writeIndex == cache.size) { writeIndex = 0 } - cache[writeIndex] = key + cache[writeIndex] = value writeIndex++ } } diff --git a/vector/src/test/java/im/vector/app/features/notifications/CircularCacheTest.kt b/vector/src/test/java/im/vector/app/features/notifications/CircularCacheTest.kt index 6428b1025b..509e2a8e29 100644 --- a/vector/src/test/java/im/vector/app/features/notifications/CircularCacheTest.kt +++ b/vector/src/test/java/im/vector/app/features/notifications/CircularCacheTest.kt @@ -66,7 +66,7 @@ class CircularCacheTest { return CircularCache(cacheSize, factory) to internalData!! } - private fun CircularCache.putInOrder(vararg keys: Int) { - keys.forEach { put(it) } + private fun CircularCache.putInOrder(vararg values: Int) { + values.forEach { put(it) } } }