-
Notifications
You must be signed in to change notification settings - Fork 47
/
IdentityDiscreteMapperProvider.kt
30 lines (26 loc) · 1.12 KB
/
IdentityDiscreteMapperProvider.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* 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.builder.scale.provider
import jetbrains.datalore.plot.builder.scale.DiscreteOnlyMapperProvider
import jetbrains.datalore.plot.builder.scale.GuideMapper
import jetbrains.datalore.plot.builder.scale.mapper.GuideMappers
open class IdentityDiscreteMapperProvider<T>(
private val inputConverter: (Any?) -> T?,
naValue: T
) : DiscreteOnlyMapperProvider<T>(naValue) {
override fun createDiscreteMapper(domainValues: Collection<*>): GuideMapper<T> {
val outputValues = ArrayList<T>()
for (inputValue in domainValues) {
if (inputValue == null) {
outputValues.add(naValue)
} else {
val outputValue = inputConverter(inputValue)
?: throw IllegalStateException("Can't map input value $inputValue to output type")
outputValues.add(outputValue)
}
}
return GuideMappers.discreteToDiscrete(domainValues, outputValues, naValue)
}
}