Add in operator support to NamedEntryCollection

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 1f93b272cd
commit d78c382ea7
  1. 4
      cache/src/main/kotlin/org/openrs2/cache/NamedEntryCollection.kt
  2. 12
      cache/src/test/kotlin/org/openrs2/cache/Js5IndexTest.kt
  3. 58
      cache/src/test/kotlin/org/openrs2/cache/NamedEntryCollectionTest.kt

@ -78,7 +78,7 @@ public abstract class NamedEntryCollection<T : NamedEntry>(
return entries.lastIntKey() + 1 return entries.lastIntKey() + 1
} }
public fun contains(id: Int): Boolean { public operator fun contains(id: Int): Boolean {
require(id >= 0) require(id >= 0)
val entry = singleEntry val entry = singleEntry
@ -101,7 +101,7 @@ public abstract class NamedEntryCollection<T : NamedEntry>(
return nameHashTable?.containsKey(nameHash) ?: false return nameHashTable?.containsKey(nameHash) ?: false
} }
public fun contains(name: String): Boolean { public operator fun contains(name: String): Boolean {
return containsNamed(name.krHashCode()) return containsNamed(name.krHashCode())
} }

@ -367,19 +367,19 @@ object Js5IndexTest {
val group = index.createOrGet(0) val group = index.createOrGet(0)
assertEquals(1, index.size) assertEquals(1, index.size)
assertEquals(1, index.capacity) assertEquals(1, index.capacity)
assertTrue(index.contains(0)) assertTrue(0 in index)
assertEquals(group, index[0]) assertEquals(group, index[0])
group.remove() group.remove()
assertEquals(0, index.size) assertEquals(0, index.size)
assertEquals(0, index.capacity) assertEquals(0, index.capacity)
assertFalse(index.contains(0)) assertFalse(0 in index)
assertNull(index[0]) assertNull(index[0])
group.remove() group.remove()
assertEquals(0, index.size) assertEquals(0, index.size)
assertEquals(0, index.capacity) assertEquals(0, index.capacity)
assertFalse(index.contains(0)) assertFalse(0 in index)
assertNull(index[0]) assertNull(index[0])
} }
@ -391,19 +391,19 @@ object Js5IndexTest {
val file = group.createOrGet(0) val file = group.createOrGet(0)
assertEquals(1, group.size) assertEquals(1, group.size)
assertEquals(1, group.capacity) assertEquals(1, group.capacity)
assertTrue(group.contains(0)) assertTrue(0 in group)
assertEquals(file, group[0]) assertEquals(file, group[0])
file.remove() file.remove()
assertEquals(0, group.size) assertEquals(0, group.size)
assertEquals(0, group.capacity) assertEquals(0, group.capacity)
assertFalse(group.contains(0)) assertFalse(0 in group)
assertNull(group[0]) assertNull(group[0])
file.remove() file.remove()
assertEquals(0, group.size) assertEquals(0, group.size)
assertEquals(0, group.capacity) assertEquals(0, group.capacity)
assertFalse(group.contains(0)) assertFalse(0 in group)
assertNull(group[0]) assertNull(group[0])
} }

@ -34,7 +34,7 @@ object NamedEntryCollectionTest {
val collection = TestCollection() val collection = TestCollection()
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
collection.contains(-1) -1 in collection
} }
assertThrows<IllegalArgumentException> { assertThrows<IllegalArgumentException> {
@ -90,8 +90,8 @@ object NamedEntryCollectionTest {
assertEquals(1, collection.size) assertEquals(1, collection.size)
assertEquals(1, collection.capacity) assertEquals(1, collection.capacity)
assertTrue(collection.contains(0)) assertTrue(0 in collection)
assertFalse(collection.contains(1)) assertFalse(1 in collection)
assertEquals(entry, collection[0]) assertEquals(entry, collection[0])
assertNull(collection[1]) assertNull(collection[1])
@ -120,9 +120,9 @@ object NamedEntryCollectionTest {
assertEquals(2, collection.size) assertEquals(2, collection.size)
assertEquals(2, collection.capacity) assertEquals(2, collection.capacity)
assertTrue(collection.contains(0)) assertTrue(0 in collection)
assertTrue(collection.contains(1)) assertTrue(1 in collection)
assertFalse(collection.contains(2)) assertFalse(2 in collection)
assertEquals(entry0, collection[0]) assertEquals(entry0, collection[0])
assertEquals(entry1, collection[1]) assertEquals(entry1, collection[1])
@ -147,8 +147,8 @@ object NamedEntryCollectionTest {
assertEquals(1, collection.size) assertEquals(1, collection.size)
assertEquals(1, collection.capacity) assertEquals(1, collection.capacity)
assertTrue(collection.contains("hello")) assertTrue("hello" in collection)
assertFalse(collection.contains("world")) assertFalse("world" in collection)
assertEquals(entry, collection["hello"]) assertEquals(entry, collection["hello"])
assertNull(collection["world"]) assertNull(collection["world"])
@ -177,9 +177,9 @@ object NamedEntryCollectionTest {
assertEquals(2, collection.size) assertEquals(2, collection.size)
assertEquals(2, collection.capacity) assertEquals(2, collection.capacity)
assertTrue(collection.contains("hello")) assertTrue("hello" in collection)
assertTrue(collection.contains("world")) assertTrue("world" in collection)
assertFalse(collection.contains("!")) assertFalse("!" in collection)
assertEquals(entry0, collection["hello"]) assertEquals(entry0, collection["hello"])
assertEquals(entry1, collection["world"]) assertEquals(entry1, collection["world"])
@ -196,16 +196,16 @@ object NamedEntryCollectionTest {
assertEquals(0, entry.id) assertEquals(0, entry.id)
assertEquals("hello".krHashCode(), entry.nameHash) assertEquals("hello".krHashCode(), entry.nameHash)
assertTrue(collection.contains("hello")) assertTrue("hello" in collection)
assertFalse(collection.contains("world")) assertFalse("world" in collection)
assertEquals(entry, collection["hello"]) assertEquals(entry, collection["hello"])
assertNull(collection["world"]) assertNull(collection["world"])
entry.setName("world") entry.setName("world")
assertFalse(collection.contains("hello")) assertFalse("hello" in collection)
assertTrue(collection.contains("world")) assertTrue("world" in collection)
assertNull(collection["hello"]) assertNull(collection["hello"])
assertEquals(entry, collection["world"]) assertEquals(entry, collection["world"])
@ -219,13 +219,13 @@ object NamedEntryCollectionTest {
assertEquals(0, entry.id) assertEquals(0, entry.id)
assertEquals(-1, entry.nameHash) assertEquals(-1, entry.nameHash)
assertFalse(collection.contains("hello")) assertFalse("hello" in collection)
assertNull(collection["hello"]) assertNull(collection["hello"])
entry.setName("hello") entry.setName("hello")
assertEquals("hello".krHashCode(), entry.nameHash) assertEquals("hello".krHashCode(), entry.nameHash)
assertTrue(collection.contains("hello")) assertTrue("hello" in collection)
assertEquals(entry, collection["hello"]) assertEquals(entry, collection["hello"])
} }
@ -237,13 +237,13 @@ object NamedEntryCollectionTest {
assertEquals(0, entry.id) assertEquals(0, entry.id)
assertEquals("hello".krHashCode(), entry.nameHash) assertEquals("hello".krHashCode(), entry.nameHash)
assertTrue(collection.contains("hello")) assertTrue("hello" in collection)
assertEquals(entry, collection["hello"]) assertEquals(entry, collection["hello"])
entry.nameHash = -1 entry.nameHash = -1
assertEquals(-1, entry.nameHash) assertEquals(-1, entry.nameHash)
assertFalse(collection.contains("hello")) assertFalse("hello" in collection)
assertNull(collection["hello"]) assertNull(collection["hello"])
} }
@ -259,13 +259,13 @@ object NamedEntryCollectionTest {
assertEquals(1, entry1.id) assertEquals(1, entry1.id)
assertEquals(-1, entry1.nameHash) assertEquals(-1, entry1.nameHash)
assertFalse(collection.contains("hello")) assertFalse("hello" in collection)
assertNull(collection["hello"]) assertNull(collection["hello"])
entry0.setName("hello") entry0.setName("hello")
assertEquals("hello".krHashCode(), entry0.nameHash) assertEquals("hello".krHashCode(), entry0.nameHash)
assertTrue(collection.contains("hello")) assertTrue("hello" in collection)
assertEquals(entry0, collection["hello"]) assertEquals(entry0, collection["hello"])
} }
@ -281,13 +281,13 @@ object NamedEntryCollectionTest {
assertEquals(1, entry1.id) assertEquals(1, entry1.id)
assertEquals(-1, entry1.nameHash) assertEquals(-1, entry1.nameHash)
assertTrue(collection.contains("hello")) assertTrue("hello" in collection)
assertEquals(entry0, collection["hello"]) assertEquals(entry0, collection["hello"])
entry0.nameHash = -1 entry0.nameHash = -1
assertEquals(-1, entry0.nameHash) assertEquals(-1, entry0.nameHash)
assertFalse(collection.contains("hello")) assertFalse("hello" in collection)
assertNull(collection["hello"]) assertNull(collection["hello"])
} }
@ -314,7 +314,7 @@ object NamedEntryCollectionTest {
entry.setName("hello") entry.setName("hello")
assertEquals("hello".krHashCode(), entry.nameHash) assertEquals("hello".krHashCode(), entry.nameHash)
assertFalse(collection.contains("hello")) assertFalse("hello" in collection)
assertNull(collection["hello"]) assertNull(collection["hello"])
entry.remove() entry.remove()
@ -344,7 +344,7 @@ object NamedEntryCollectionTest {
entry.setName("hello") entry.setName("hello")
assertEquals("hello".krHashCode(), entry.nameHash) assertEquals("hello".krHashCode(), entry.nameHash)
assertFalse(collection.contains("hello")) assertFalse("hello" in collection)
assertNull(collection["hello"]) assertNull(collection["hello"])
collection.remove(0) collection.remove(0)
@ -374,7 +374,7 @@ object NamedEntryCollectionTest {
entry.setName("world") entry.setName("world")
assertEquals("world".krHashCode(), entry.nameHash) assertEquals("world".krHashCode(), entry.nameHash)
assertFalse(collection.contains("world")) assertFalse("world" in collection)
assertNull(collection["world"]) assertNull(collection["world"])
collection.remove("hello") collection.remove("hello")
@ -410,7 +410,7 @@ object NamedEntryCollectionTest {
entry0.setName("world") entry0.setName("world")
assertEquals("world".krHashCode(), entry0.nameHash) assertEquals("world".krHashCode(), entry0.nameHash)
assertFalse(collection.contains("world")) assertFalse("world" in collection)
assertNull(collection["world"]) assertNull(collection["world"])
entry0.remove() entry0.remove()
@ -446,7 +446,7 @@ object NamedEntryCollectionTest {
entry0.setName("world") entry0.setName("world")
assertEquals("world".krHashCode(), entry0.nameHash) assertEquals("world".krHashCode(), entry0.nameHash)
assertFalse(collection.contains("world")) assertFalse("world" in collection)
assertNull(collection["world"]) assertNull(collection["world"])
collection.remove(0) collection.remove(0)
@ -488,7 +488,7 @@ object NamedEntryCollectionTest {
entry0.setName("!") entry0.setName("!")
assertEquals("!".krHashCode(), entry0.nameHash) assertEquals("!".krHashCode(), entry0.nameHash)
assertFalse(collection.contains("!")) assertFalse("!" in collection)
assertNull(collection["!"]) assertNull(collection["!"])
collection.remove("hello") collection.remove("hello")

Loading…
Cancel
Save