Skip to content
Snippets Groups Projects
Commit 95806315 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Fix a missing method on Android 4.4

parent 24e1f8dd
Branches
Tags
No related merge requests found
......@@ -6,6 +6,7 @@ import de.kuschku.libquassel.protocol.Type
import de.kuschku.libquassel.protocol.message.SignalProxyMessage
import de.kuschku.libquassel.quassel.exceptions.ObjectNotFoundException
import de.kuschku.libquassel.quassel.syncables.interfaces.ISyncableObject
import de.kuschku.libquassel.util.helpers.removeIfEqual
class ObjectStorage(private val proxy: SignalProxy) {
private val objectTree: MutableMap<Pair<String, String>, ISyncableObject> = HashMap()
......@@ -35,7 +36,7 @@ class ObjectStorage(private val proxy: SignalProxy) {
fun rename(obj: ISyncableObject, new: String, old: String) {
objectTree[Pair(obj.className, new)] = obj
objectTree.remove(Pair(obj.className, old), obj)
objectTree.removeIfEqual(Pair(obj.className, old), obj)
if (get(obj.className, new) != obj) {
throw IllegalStateException("Object should be existing")
}
......
package de.kuschku.libquassel.util.helpers
fun <K, V> Map<K, V>.getOr(key: K, defValue: V) = this[key] ?: defValue
fun <K, V> MutableMap<K, V>.removeIfEqual(key: K, value: V): Boolean {
if (!this.containsKey(key))
return false
if (this[key] != value)
return false
this.remove(key)
return true
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment