Add capacity properties/methods to Archive and Cache

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 65194fae43
commit 95cb97bae8
  1. 16
      cache/src/main/kotlin/org/openrs2/cache/Archive.kt
  2. 19
      cache/src/main/kotlin/org/openrs2/cache/Cache.kt

@ -116,6 +116,22 @@ public abstract class Archive internal constructor(
// TODO(gpe): rename/move, reindex, rekey, method to go from name->id
public val capacity: Int = index.capacity
public fun capacity(group: Int): Int {
val entry = index[group] ?: throw FileNotFoundException()
return entry.capacity
}
public fun capacityNamed(groupNameHash: Int): Int {
val entry = index.getNamed(groupNameHash) ?: throw FileNotFoundException()
return entry.capacity
}
public fun capacity(group: String): Int {
return capacityNamed(group.krHashCode())
}
public fun exists(group: Int): Boolean {
require(group >= 0)
return index.contains(group)

@ -54,6 +54,25 @@ public class Cache private constructor(
createOrGetArchive(archive)
}
public fun capacity(archive: Int): Int {
checkArchive(archive)
return archives[archive]?.capacity ?: throw FileNotFoundException()
}
public fun capacity(archive: Int, group: Int): Int {
checkArchive(archive)
return archives[archive]?.capacity(group) ?: throw FileNotFoundException()
}
public fun capacityNamed(archive: Int, groupNameHash: Int): Int {
checkArchive(archive)
return archives[archive]?.capacityNamed(groupNameHash) ?: throw FileNotFoundException()
}
public fun capacity(archive: Int, group: String): Int {
return capacityNamed(archive, group.krHashCode())
}
public fun exists(archive: Int): Boolean {
checkArchive(archive)
return archives[archive] != null

Loading…
Cancel
Save