From 2b9f423e9a7667506326eceda910df8c6676edf4 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 29 May 2021 12:49:22 +0100 Subject: [PATCH] Remove unused Iterable extensions Signed-off-by: Graham --- .../org/openrs2/util/collect/IterableUtils.kt | 29 ---------- .../openrs2/util/collect/IterableUtilsTest.kt | 55 ------------------- 2 files changed, 84 deletions(-) delete mode 100644 util/src/main/kotlin/org/openrs2/util/collect/IterableUtils.kt delete mode 100644 util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt diff --git a/util/src/main/kotlin/org/openrs2/util/collect/IterableUtils.kt b/util/src/main/kotlin/org/openrs2/util/collect/IterableUtils.kt deleted file mode 100644 index bc470c8b..00000000 --- a/util/src/main/kotlin/org/openrs2/util/collect/IterableUtils.kt +++ /dev/null @@ -1,29 +0,0 @@ -package org.openrs2.util.collect - -public fun MutableIterable.removeFirst(): T { - return removeFirstOrNull() ?: throw NoSuchElementException() -} - -public fun MutableIterable.removeFirstOrNull(): T? { - val iterator = iterator() - if (!iterator.hasNext()) { - return null - } - - val element = iterator.next() - iterator.remove() - - return element -} - -public inline fun MutableIterable.removeFirst(predicate: (T) -> Boolean): Boolean { - val iterator = iterator() - for (element in iterator) { - if (predicate(element)) { - iterator.remove() - return true - } - } - - return false -} diff --git a/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt b/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt deleted file mode 100644 index 187902d7..00000000 --- a/util/src/test/kotlin/org/openrs2/util/collect/IterableUtilsTest.kt +++ /dev/null @@ -1,55 +0,0 @@ -package org.openrs2.util.collect - -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith -import kotlin.test.assertFalse -import kotlin.test.assertNull -import kotlin.test.assertTrue - -class IterableUtilsTest { - @Test - fun testRemoveFirst() { - val list = mutableListOf(1, 2, 3) - assertEquals(1, list.removeFirst()) - assertEquals(listOf(2, 3), list) - - assertEquals(2, list.removeFirst()) - assertEquals(listOf(3), list) - - assertEquals(3, list.removeFirst()) - assertEquals(emptyList(), list) - - assertFailsWith { - list.removeFirst() - } - } - - @Test - fun testRemoveFirstOrNull() { - val list = mutableListOf(1, 2, 3) - assertEquals(1, list.removeFirstOrNull()) - assertEquals(listOf(2, 3), list) - - assertEquals(2, list.removeFirstOrNull()) - assertEquals(listOf(3), list) - - assertEquals(3, list.removeFirstOrNull()) - assertEquals(emptyList(), list) - - assertNull(list.removeFirstOrNull()) - } - - @Test - fun testRemoveFirstMatching() { - val list = mutableListOf(1, 2, 2, 3) - assertTrue(list.removeFirst { it == 2 }) - assertEquals(listOf(1, 2, 3), list) - - assertTrue(list.removeFirst { it == 2 }) - assertEquals(listOf(1, 3), list) - - assertFalse(list.removeFirst { it == 2 }) - assertEquals(listOf(1, 3), list) - } -}