commonMain.jetbrains.datalore.plot.base.stat.MultiOrdering.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lets-plot-common Show documentation
Show all versions of lets-plot-common Show documentation
Lets-Plot JVM package without rendering part
/*
* Copyright (c) 2019. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.datalore.plot.base.stat
import jetbrains.datalore.base.gcommon.base.Preconditions.checkArgument
internal class MultiOrdering>(private val myKeys: List) {
private val myIndices: MutableList
init {
myIndices = ArrayList(myKeys.size)
for (i in myKeys.indices) {
myIndices.add(i)
}
myIndices.sortWith(Comparator { i: Int?, j: Int? ->
val keyI = myKeys[i!!]
val keyJ = myKeys[j!!]
when {
keyI === keyJ -> 0
keyI == null -> -1
keyJ == null -> 1
else -> keyI.compareTo(keyJ)
}
})
}
fun sortedCopy(l: List): List {
checkArgument(l.size == myIndices.size,
"Expected size " + myIndices.size + " but was size " + l.size)
val copy = ArrayList(myIndices.size)
for (oldIndex in myIndices) {
val v = l[oldIndex]
copy.add(v)
}
return copy
}
fun sortedCopyOfKeys(): List {
return sortedCopy(myKeys)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy