Fix extra list implementation for MultiSortedList
This commit is contained in:
parent
b25f91c3e3
commit
b5e431c7f6
@ -1,20 +1,36 @@
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.Comparator
|
import kotlin.Comparator
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class MultiSortedList<E> constructor(
|
class MultiSortedList<E> constructor(
|
||||||
underlying: MutableList<E>,
|
underlying: MutableList<E>,
|
||||||
|
generator: () -> MutableList<E>,
|
||||||
comparator: Comparator<in E>,
|
comparator: Comparator<in E>,
|
||||||
vararg extraComparators: Comparator<in E>
|
vararg extraComparators: Comparator<in E>
|
||||||
): SortedList<E>(underlying, comparator) {
|
): SortedList<E>(underlying, comparator) {
|
||||||
companion object {
|
companion object {
|
||||||
fun <T: Comparable<T>> ofComparable(
|
fun <T: Comparable<T>> ofComparable(
|
||||||
underlying: MutableList<T> = ArrayList(),
|
underlying: MutableList<T>,
|
||||||
|
generator: () -> MutableList<T> = ::ArrayList,
|
||||||
comparator: Comparator<in T> = Comparator { a, b -> a.compareTo(b) },
|
comparator: Comparator<in T> = Comparator { a, b -> a.compareTo(b) },
|
||||||
vararg extraComparators: Comparator<in T>
|
vararg extraComparators: Comparator<in T>
|
||||||
) = MultiSortedList(underlying, comparator, *extraComparators)
|
) = MultiSortedList(underlying, generator, comparator, *extraComparators)
|
||||||
|
|
||||||
|
fun <T: Comparable<T>> ofComparable(
|
||||||
|
generator: () -> MutableList<T> = ::ArrayList,
|
||||||
|
comparator: Comparator<in T> = Comparator { a, b -> a.compareTo(b) },
|
||||||
|
vararg extraComparators: Comparator<in T>
|
||||||
|
) = MultiSortedList(generator(), generator, comparator, *extraComparators)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var extraLists = extraComparators.associateWith { SortedList(underlying.subList(0, underlying.size), it) }
|
constructor(generator: () -> MutableList<E>, comparator: Comparator<in E>, vararg extraComparators: Comparator<in E>):
|
||||||
|
this(generator(), generator, comparator, *extraComparators)
|
||||||
|
|
||||||
|
private var extraLists = extraComparators.associateWith {
|
||||||
|
val list = generator()
|
||||||
|
Collections.copy(list, underlying)
|
||||||
|
SortedList(list, it)
|
||||||
|
}
|
||||||
|
|
||||||
override fun add(element: E): Boolean {
|
override fun add(element: E): Boolean {
|
||||||
extraLists.values.forEach {
|
extraLists.values.forEach {
|
||||||
|
@ -24,8 +24,8 @@ private const val DEFAULT_COOLDOWN_MIN = 5L
|
|||||||
class PortalManager(private val data: ConfigurationSection, private val config: () -> ConfigurationSection): Listener {
|
class PortalManager(private val data: ConfigurationSection, private val config: () -> ConfigurationSection): Listener {
|
||||||
private val players = PlayerMapper(data, PATH_DATA_PLAYERS)
|
private val players = PlayerMapper(data, PATH_DATA_PLAYERS)
|
||||||
private val worlds = WorldMapper(data, PATH_DATA_WORLDS)
|
private val worlds = WorldMapper(data, PATH_DATA_WORLDS)
|
||||||
private var portals = MultiSortedList(ArrayList(), COMPARATOR_PORTAL_LOCATION_OWNER, COMPARATOR_PORTAL_UID, COMPARATOR_PORTAL_OWNER_NAME, COMPARATOR_PORTAL_LINKS)
|
private var portals = MultiSortedList(::ArrayList, COMPARATOR_PORTAL_LOCATION_OWNER, COMPARATOR_PORTAL_UID, COMPARATOR_PORTAL_OWNER_NAME, COMPARATOR_PORTAL_LINKS)
|
||||||
private var invitations = MultiSortedList(ArrayList(), COMPARATOR_INVITE_RECIPIENT, COMPARATOR_INVITE_PORTAL)
|
private var invitations = MultiSortedList(::ArrayList, COMPARATOR_INVITE_RECIPIENT, COMPARATOR_INVITE_PORTAL)
|
||||||
|
|
||||||
private val cooldowns = LinkedList<Pair<OfflinePlayer, Long>>()
|
private val cooldowns = LinkedList<Pair<OfflinePlayer, Long>>()
|
||||||
private val cooldownsLookup = SortedList<OfflinePlayer>(ArrayList(), COMPARATOR_PLAYER)
|
private val cooldownsLookup = SortedList<OfflinePlayer>(ArrayList(), COMPARATOR_PLAYER)
|
||||||
@ -92,7 +92,7 @@ class PortalManager(private val data: ConfigurationSection, private val config:
|
|||||||
if (portal.id >= nextUUID)
|
if (portal.id >= nextUUID)
|
||||||
nextUUID = portal.id + 1UL
|
nextUUID = portal.id + 1UL
|
||||||
}
|
}
|
||||||
portals = MultiSortedList(portalList, COMPARATOR_PORTAL_LOCATION_OWNER, COMPARATOR_PORTAL_UID)
|
portals = MultiSortedList(portalList, ::ArrayList, COMPARATOR_PORTAL_LOCATION_OWNER, COMPARATOR_PORTAL_UID)
|
||||||
|
|
||||||
if(portals.isEmpty()) nextUUID = UUID(0, 0)
|
if(portals.isEmpty()) nextUUID = UUID(0, 0)
|
||||||
else {
|
else {
|
||||||
@ -105,6 +105,7 @@ class PortalManager(private val data: ConfigurationSection, private val config:
|
|||||||
|
|
||||||
invitations = MultiSortedList(
|
invitations = MultiSortedList(
|
||||||
data.getStringList(PATH_DATA_INVITES).mapTo(ArrayList(), ::Invite),
|
data.getStringList(PATH_DATA_INVITES).mapTo(ArrayList(), ::Invite),
|
||||||
|
::ArrayList,
|
||||||
COMPARATOR_INVITE_RECIPIENT,
|
COMPARATOR_INVITE_RECIPIENT,
|
||||||
COMPARATOR_INVITE_PORTAL
|
COMPARATOR_INVITE_PORTAL
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user