From 11cf93fa55606bef982c4ca115744a72adb99a2d Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sun, 30 Apr 2023 21:49:05 +0200 Subject: [PATCH] Remove unused class PairedList (#3602) --- .../keylesspalace/tusky/util/PairedList.kt | 74 --------------- .../tusky/util/PairedListTest.kt | 91 ------------------- 2 files changed, 165 deletions(-) delete mode 100644 app/src/main/java/com/keylesspalace/tusky/util/PairedList.kt delete mode 100644 app/src/test/java/com/keylesspalace/tusky/util/PairedListTest.kt diff --git a/app/src/main/java/com/keylesspalace/tusky/util/PairedList.kt b/app/src/main/java/com/keylesspalace/tusky/util/PairedList.kt deleted file mode 100644 index 39a47cc7..00000000 --- a/app/src/main/java/com/keylesspalace/tusky/util/PairedList.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.keylesspalace.tusky.util - -import androidx.arch.core.util.Function - -/** - * This list implementation can help to keep two lists in sync - like real models and view models. - * - * Every operation on the main list triggers update of the supplementary list (but not vice versa). - * - * This makes sure that the main list is always the source of truth. - * - * Main list is projected to the supplementary list by the passed mapper function. - * - * Paired list is newer actually exposed and clients are provided with `getPairedCopy()`, - * `getPairedItem()` and `setPairedItem()`. This prevents modifications of the - * supplementary list size so lists are always have the same length. - * - * This implementation will not try to recover from exceptional cases so lists may be out of sync - * after the exception. - * - * It is most useful with immutable data because we cannot track changes inside stored objects. - * - * @param T type of elements in the main list - * @param V type of elements in supplementary list - * @param mapper Function, which will be used to translate items from the main list to the - * supplementary one. - * @constructor - */ -class PairedList (private val mapper: Function) : AbstractMutableList() { - private val main: MutableList = ArrayList() - private val synced: MutableList = ArrayList() - - val pairedCopy: List - get() = ArrayList(synced) - - fun getPairedItem(index: Int): V { - return synced[index] - } - - fun getPairedItemOrNull(index: Int): V? { - return synced.getOrNull(index) - } - - fun setPairedItem(index: Int, element: V) { - synced[index] = element - } - - override fun get(index: Int): T { - return main[index] - } - - override fun set(index: Int, element: T): T { - synced[index] = mapper.apply(element) - return main.set(index, element) - } - - override fun add(element: T): Boolean { - synced.add(mapper.apply(element)) - return main.add(element) - } - - override fun add(index: Int, element: T) { - synced.add(index, mapper.apply(element)) - main.add(index, element) - } - - override fun removeAt(index: Int): T { - synced.removeAt(index) - return main.removeAt(index) - } - - override val size: Int - get() = main.size -} diff --git a/app/src/test/java/com/keylesspalace/tusky/util/PairedListTest.kt b/app/src/test/java/com/keylesspalace/tusky/util/PairedListTest.kt deleted file mode 100644 index d5df1550..00000000 --- a/app/src/test/java/com/keylesspalace/tusky/util/PairedListTest.kt +++ /dev/null @@ -1,91 +0,0 @@ -package com.keylesspalace.tusky.util - -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNull -import org.junit.Before -import org.junit.Test - -/** - * Tests for PairedList, with a mapper that multiples everything by 2. - */ -class PairedListTest { - private lateinit var pairedList: PairedList - - @Before - fun beforeEachTest() { - pairedList = PairedList { it * 2 } - for (i in 0..10) { - pairedList.add(i) - } - } - - @Test - fun pairedCopy() { - val copy = pairedList.pairedCopy - for (i in 0..10) { - assertEquals(i * 2, copy[i]) - } - } - - @Test - fun getPairedItem() { - for (i in 0..10) { - assertEquals(i * 2, pairedList.getPairedItem(i)) - } - } - - @Test - fun getPairedItemOrNull() { - for (i in 0..10) { - assertEquals(i * 2, pairedList.getPairedItem(i)) - } - assertNull(pairedList.getPairedItemOrNull(11)) - } - - @Test - fun setPairedItem() { - pairedList.setPairedItem(2, 2) - assertEquals(2, pairedList.getPairedItem(2)) - } - - @Test - fun get() { - for (i in 0..10) { - assertEquals(i, pairedList[i]) - } - } - - @Test - fun set() { - assertEquals(0, pairedList[0]) - pairedList[0] = 10 - assertEquals(10, pairedList[0]) - assertEquals(20, pairedList.getPairedItem(0)) - } - - @Test - fun add() { - pairedList.add(11) - assertEquals(11, pairedList[11]) - assertEquals(22, pairedList.getPairedItem(11)) - } - - @Test - fun addAtIndex() { - pairedList.add(11, 11) - assertEquals(11, pairedList[11]) - assertEquals(22, pairedList.getPairedItem(11)) - } - - @Test - fun removeAt() { - pairedList.removeAt(5) - assertEquals(6, pairedList[5]) - assertEquals(12, pairedList.getPairedItem(5)) - } - - @Test - fun size() { - assertEquals(11, pairedList.size) - } -}