@@ -40,6 +40,7 @@ import org.jetbrains.kotlinx.dataframe.impl.createStarProjectedType
40
40
import org.jetbrains.kotlinx.dataframe.path
41
41
import org.jetbrains.kotlinx.dataframe.type
42
42
import java.math.BigDecimal
43
+ import java.math.BigInteger
43
44
import java.net.URL
44
45
import java.util.Locale
45
46
import kotlin.math.roundToInt
@@ -272,6 +273,8 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
272
273
273
274
BigDecimal ::class -> convert<Boolean > { if (it) BigDecimal .ONE else BigDecimal .ZERO }
274
275
276
+ BigInteger ::class -> convert<Boolean > { if (it) BigInteger .ONE else BigInteger .ZERO }
277
+
275
278
else -> null
276
279
}
277
280
@@ -283,10 +286,19 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
283
286
Short ::class -> convert<Number > { it.toShort() }
284
287
Long ::class -> convert<Number > { it.toLong() }
285
288
Boolean ::class -> convert<Number > { it.toDouble() != 0.0 }
289
+ BigDecimal ::class -> convert<Number > { it.toBigDecimal() }
290
+ BigInteger ::class -> convert<Number > { it.toBigInteger() }
291
+ else -> null
292
+ }
293
+
294
+ Char ::class -> when (toClass) {
295
+ Int ::class -> convert<Char > { it.code }
286
296
else -> null
287
297
}
288
298
289
299
Int ::class -> when (toClass) {
300
+ Char ::class -> convert<Int > { it.toChar() }
301
+
290
302
Double ::class -> convert<Int > { it.toDouble() }
291
303
292
304
Float ::class -> convert<Int > { it.toFloat() }
@@ -299,6 +311,8 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
299
311
300
312
BigDecimal ::class -> convert<Int > { it.toBigDecimal() }
301
313
314
+ BigInteger ::class -> convert<Int > { it.toBigInteger() }
315
+
302
316
Boolean ::class -> convert<Int > { it != 0 }
303
317
304
318
LocalDateTime ::class -> convert<Int > { it.toLong().toLocalDateTime(defaultTimeZone) }
@@ -327,7 +341,9 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
327
341
Float ::class -> convert<Double > { it.toFloat() }
328
342
Long ::class -> convert<Double > { it.roundToLong() }
329
343
Short ::class -> convert<Double > { it.roundToInt().toShort() }
344
+ Byte ::class -> convert<Double > { it.roundToInt().toByte() }
330
345
BigDecimal ::class -> convert<Double > { it.toBigDecimal() }
346
+ BigInteger ::class -> convert<Double > { it.toBigInteger() }
331
347
Boolean ::class -> convert<Double > { it != 0.0 }
332
348
else -> null
333
349
}
@@ -345,6 +361,8 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
345
361
346
362
BigDecimal ::class -> convert<Long > { it.toBigDecimal() }
347
363
364
+ BigInteger ::class -> convert<Long > { it.toBigInteger() }
365
+
348
366
Boolean ::class -> convert<Long > { it != 0L }
349
367
350
368
LocalDateTime ::class -> convert<Long > { it.toLocalDateTime(defaultTimeZone) }
@@ -422,21 +440,38 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
422
440
Double ::class -> convert<Float > { it.toDouble() }
423
441
Long ::class -> convert<Float > { it.roundToLong() }
424
442
Int ::class -> convert<Float > { it.roundToInt() }
443
+ Byte ::class -> convert<Float > { it.roundToInt().toByte() }
425
444
Short ::class -> convert<Float > { it.roundToInt().toShort() }
426
445
BigDecimal ::class -> convert<Float > { it.toBigDecimal() }
446
+ BigInteger ::class -> convert<Float > { it.toBigInteger() }
427
447
Boolean ::class -> convert<Float > { it != 0.0F }
428
448
else -> null
429
449
}
430
450
431
451
BigDecimal ::class -> when (toClass) {
432
452
Double ::class -> convert<BigDecimal > { it.toDouble() }
433
453
Int ::class -> convert<BigDecimal > { it.toInt() }
454
+ Byte ::class -> convert<BigDecimal > { it.toByte() }
455
+ Short ::class -> convert<BigDecimal > { it.toShort() }
434
456
Float ::class -> convert<BigDecimal > { it.toFloat() }
435
457
Long ::class -> convert<BigDecimal > { it.toLong() }
458
+ BigInteger ::class -> convert<BigDecimal > { it.toBigInteger() }
436
459
Boolean ::class -> convert<BigDecimal > { it != BigDecimal .ZERO }
437
460
else -> null
438
461
}
439
462
463
+ BigInteger ::class -> when (toClass) {
464
+ Double ::class -> convert<BigInteger > { it.toDouble() }
465
+ Int ::class -> convert<BigInteger > { it.toInt() }
466
+ Byte ::class -> convert<BigInteger > { it.toByte() }
467
+ Short ::class -> convert<BigInteger > { it.toShort() }
468
+ Float ::class -> convert<BigInteger > { it.toFloat() }
469
+ Long ::class -> convert<BigInteger > { it.toLong() }
470
+ BigDecimal ::class -> convert<BigInteger > { it.toBigDecimal() }
471
+ Boolean ::class -> convert<BigInteger > { it != BigInteger .ZERO }
472
+ else -> null
473
+ }
474
+
440
475
LocalDateTime ::class -> when (toClass) {
441
476
LocalDate ::class -> convert<LocalDateTime > { it.date }
442
477
LocalTime ::class -> convert<LocalDateTime > { it.time }
@@ -540,3 +575,21 @@ internal fun Instant.toLocalDate(zone: TimeZone = defaultTimeZone) = toLocalDate
540
575
internal fun Instant.toLocalTime (zone : TimeZone = defaultTimeZone) = toLocalDateTime(zone).time
541
576
542
577
internal val defaultTimeZone = TimeZone .currentSystemDefault()
578
+
579
+ internal fun Number.toBigDecimal (): BigDecimal =
580
+ when (this ) {
581
+ is BigDecimal -> this
582
+ is BigInteger -> BigDecimal (this )
583
+ is Double -> BigDecimal .valueOf(this )
584
+ is Int -> BigDecimal (this )
585
+ is Long -> BigDecimal .valueOf(this )
586
+ else -> BigDecimal .valueOf(this .toDouble())
587
+ }
588
+
589
+ internal fun Number.toBigInteger (): BigInteger =
590
+ when (this ) {
591
+ is BigInteger -> this
592
+ is BigDecimal -> this .toBigInteger()
593
+ is Long -> BigInteger .valueOf(this )
594
+ else -> BigInteger .valueOf(this .toLong())
595
+ }
0 commit comments