Use assertions for conditions we never expect to hit

Signed-off-by: Graham <gpe@openrs2.dev>
Graham 4 years ago
parent 3a39639e3d
commit d5240e3e42
  1. 14
      cache/src/main/java/dev/openrs2/cache/NamedEntryCollection.kt

@ -74,7 +74,7 @@ public abstract class NamedEntryCollection<T : NamedEntry>(
} }
val entries = entries ?: return 0 val entries = entries ?: return 0
check(entries.isNotEmpty()) assert(entries.isNotEmpty())
return entries.lastIntKey() + 1 return entries.lastIntKey() + 1
} }
@ -128,7 +128,7 @@ public abstract class NamedEntryCollection<T : NamedEntry>(
val nameHashTable = nameHashTable ?: return null val nameHashTable = nameHashTable ?: return null
val ids = nameHashTable.getOrDefault(nameHash, IntSortedSets.EMPTY_SET) val ids = nameHashTable.getOrDefault(nameHash, IntSortedSets.EMPTY_SET)
return if (ids.isNotEmpty()) { return if (ids.isNotEmpty()) {
get(ids.firstInt()) ?: throw IllegalStateException() get(ids.firstInt()) ?: throw AssertionError()
} else { } else {
null null
} }
@ -210,20 +210,18 @@ public abstract class NamedEntryCollection<T : NamedEntry>(
val singleEntry = singleEntry val singleEntry = singleEntry
if (singleEntry != null) { if (singleEntry != null) {
check(singleEntry.id != 0) assert(singleEntry.id != 0)
return 0 return 0
} }
val entries = entries val entries = entries!!
check(entries != null)
for (id in 0 until capacity) { for (id in 0 until capacity) {
if (!entries.containsKey(id)) { if (!entries.containsKey(id)) {
return id return id
} }
} }
throw IllegalStateException() throw AssertionError()
} }
internal fun rename(id: Int, prevNameHash: Int, newNameHash: Int) { internal fun rename(id: Int, prevNameHash: Int, newNameHash: Int) {
@ -234,7 +232,7 @@ public abstract class NamedEntryCollection<T : NamedEntry>(
var nameHashTable = nameHashTable var nameHashTable = nameHashTable
if (nameHashTable != null && prevNameHash != -1) { if (nameHashTable != null && prevNameHash != -1) {
val set = nameHashTable.get(prevNameHash) val set = nameHashTable.get(prevNameHash)
check(set != null && set.contains(id)) assert(set != null && set.contains(id))
if (set.size > 1) { if (set.size > 1) {
set.remove(id) set.remove(id)

Loading…
Cancel
Save