mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 20:26:41 +01:00
Lint issues: remove unused methods, use indexing operator instead of .get()
This commit is contained in:
@@ -123,24 +123,12 @@ interface CacheOperations<K, V> {
|
|||||||
return runner.results
|
return runner.results
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T, U> associateNotNull(transform: (K, V) -> Pair<T, U>?): Map<T, U> {
|
|
||||||
val runner = CacheCollectors.BiAssociateNotNullCollector(size(), transform)
|
|
||||||
forEach(runner)
|
|
||||||
return runner.results
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <U> associateWith(transform: (K, V) -> U?): Map<K, U?> {
|
fun <U> associateWith(transform: (K, V) -> U?): Map<K, U?> {
|
||||||
val runner = CacheCollectors.BiAssociateWithCollector(size(), transform)
|
val runner = CacheCollectors.BiAssociateWithCollector(size(), transform)
|
||||||
forEach(runner)
|
forEach(runner)
|
||||||
return runner.results
|
return runner.results
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <U> associateNotNullWith(transform: (K, V) -> U): Map<K, U> {
|
|
||||||
val runner = CacheCollectors.BiAssociateNotNullWithCollector(size(), transform)
|
|
||||||
forEach(runner)
|
|
||||||
return runner.results
|
|
||||||
}
|
|
||||||
|
|
||||||
fun joinToString(
|
fun joinToString(
|
||||||
separator: CharSequence = ", ",
|
separator: CharSequence = ", ",
|
||||||
prefix: CharSequence = "",
|
prefix: CharSequence = "",
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class LargeCache<K, V> : CacheOperations<K, V> {
|
|||||||
key: K,
|
key: K,
|
||||||
builder: (key: K) -> V,
|
builder: (key: K) -> V,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val value = cache.get(key)
|
val value = cache[key]
|
||||||
return if (value != null) {
|
return if (value != null) {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class LargeSoftCache<K, V> : CacheOperations<K, V> {
|
|||||||
key: K,
|
key: K,
|
||||||
builder: (key: K) -> V,
|
builder: (key: K) -> V,
|
||||||
): V {
|
): V {
|
||||||
val softRef = cache.get(key)
|
val softRef = cache[key]
|
||||||
val value = softRef?.get()
|
val value = softRef?.get()
|
||||||
|
|
||||||
return if (value != null) {
|
return if (value != null) {
|
||||||
@@ -89,20 +89,6 @@ class LargeSoftCache<K, V> : CacheOperations<K, V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createIfAbsent(
|
|
||||||
key: K,
|
|
||||||
builder: (key: K) -> V,
|
|
||||||
): Boolean {
|
|
||||||
val softRef = cache.get(key)
|
|
||||||
val value = softRef?.get()
|
|
||||||
return if (value != null) {
|
|
||||||
false
|
|
||||||
} else {
|
|
||||||
val newObject = builder(key)
|
|
||||||
cache.putIfAbsent(key, WeakReference(newObject)) == null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proactively cleans up the cache by removing entries whose weakly referenced
|
* Proactively cleans up the cache by removing entries whose weakly referenced
|
||||||
* objects have been garbage collected. While `get` handles cleanup on access,
|
* objects have been garbage collected. While `get` handles cleanup on access,
|
||||||
|
|||||||
Reference in New Issue
Block a user