|
| 1 | +@file:Suppress("UNCHECKED_CAST", "DEPRECATION") |
| 2 | + |
| 3 | +package org.jetbrains.kotlinx.dataframe.api |
| 4 | + |
| 5 | +import org.jetbrains.kotlinx.dataframe.ColumnsScope |
| 6 | +import org.jetbrains.kotlinx.dataframe.DataColumn |
| 7 | +import org.jetbrains.kotlinx.dataframe.DataRow |
| 8 | +import org.jetbrains.kotlinx.dataframe.annotations.ColumnName |
| 9 | +import org.jetbrains.kotlinx.dataframe.annotations.DataSchema |
| 10 | +import org.jetbrains.kotlinx.dataframe.util.KEY_VALUE_PROPERTY |
| 11 | +import org.jetbrains.kotlinx.dataframe.util.KEY_VALUE_PROPERTY_KEY |
| 12 | + |
| 13 | +/** A [DataSchema] interface / class can implement this if it represents a map-like data schema (so name: value). */ |
| 14 | +@DataSchema |
| 15 | +public interface NameValueProperty<T> { |
| 16 | + // needs to be explicitly overridden in @DataSchema interface, otherwise extension functions won't generate (TODO) |
| 17 | + public val name: String |
| 18 | + |
| 19 | + // needs to be explicitly overridden in @DataSchema interface, otherwise type will be read as `T` and extensions won't generate (TODO) |
| 20 | + @ColumnName("value") |
| 21 | + public val `value`: T |
| 22 | +} |
| 23 | + |
| 24 | +// region Deprecated |
| 25 | + |
| 26 | +/** A [DataSchema] interface / class can implement this if it represents a map-like data schema (so key: value). */ |
| 27 | +@Deprecated(KEY_VALUE_PROPERTY, ReplaceWith("NameValueProperty<T>")) |
| 28 | +public interface KeyValueProperty<T> { |
| 29 | + // needs to be explicitly overridden in @DataSchema interface, otherwise extension functions won't generate (TODO) |
| 30 | + public val key: String |
| 31 | + |
| 32 | + // needs to be explicitly overridden in @DataSchema interface, otherwise type will be read as `T` and extensions won't generate (TODO) |
| 33 | + @ColumnName("value") |
| 34 | + public val `value`: T |
| 35 | +} |
| 36 | + |
| 37 | +@Deprecated(KEY_VALUE_PROPERTY_KEY, ReplaceWith("name")) |
| 38 | +public val ColumnsScope<KeyValueProperty<*>>.key: DataColumn<String> |
| 39 | + @JvmName("KeyValueProperty_key") |
| 40 | + get() = this["key"].cast() |
| 41 | + |
| 42 | +@Deprecated(KEY_VALUE_PROPERTY_KEY, ReplaceWith("name")) |
| 43 | +public val ColumnsScope<KeyValueProperty<*>?>.key: DataColumn<String?> |
| 44 | + @JvmName("NullableKeyValueProperty_key") |
| 45 | + get() = this["key"].cast() |
| 46 | + |
| 47 | +@Deprecated(KEY_VALUE_PROPERTY_KEY, ReplaceWith("name")) |
| 48 | +public val DataRow<KeyValueProperty<*>>.key: String |
| 49 | + @JvmName("KeyValueProperty_key") |
| 50 | + get() = this["key"] as String |
| 51 | + |
| 52 | +@Deprecated(KEY_VALUE_PROPERTY_KEY, ReplaceWith("name")) |
| 53 | +public val DataRow<KeyValueProperty<*>?>.key: String? |
| 54 | + @JvmName("NullableKeyValueProperty_key") |
| 55 | + get() = this["key"] as String? |
| 56 | + |
| 57 | +/** |
| 58 | + * Accesses the 'key' column of this [KeyValueProperty][KeyValueProperty] |
| 59 | + * [ColumnsContainer][org.jetbrains.kotlinx.dataframe.ColumnsContainer]. |
| 60 | + * |
| 61 | + * This is a temporary, future-proof, extension property in preparation of the migration from [KeyValueProperty] |
| 62 | + * to [NameValueProperty]. |
| 63 | + */ |
| 64 | +public val ColumnsScope<KeyValueProperty<*>>.name: DataColumn<String> |
| 65 | + @JvmName("KeyValueProperty_name") |
| 66 | + get() = key |
| 67 | + |
| 68 | +/** |
| 69 | + * Accesses the 'key' column of this [KeyValueProperty][KeyValueProperty] |
| 70 | + * [ColumnsContainer][org.jetbrains.kotlinx.dataframe.ColumnsContainer]. |
| 71 | + * |
| 72 | + * This is a temporary, future-proof, extension property in preparation of the migration from [KeyValueProperty] |
| 73 | + * to [NameValueProperty]. |
| 74 | + */ |
| 75 | +public val ColumnsScope<KeyValueProperty<*>?>.name: DataColumn<String?> |
| 76 | + @JvmName("NullableKeyValueProperty_name") |
| 77 | + get() = key |
| 78 | + |
| 79 | +/** |
| 80 | + * Accesses the 'key' value of this [KeyValueProperty][KeyValueProperty] |
| 81 | + * [DataRow][DataRow]. |
| 82 | + * |
| 83 | + * This is a temporary, future-proof, extension property in preparation of the migration from [KeyValueProperty] |
| 84 | + * to [NameValueProperty]. |
| 85 | + */ |
| 86 | +public val DataRow<KeyValueProperty<*>>.name: String |
| 87 | + @JvmName("KeyValueProperty_name") |
| 88 | + get() = key |
| 89 | + |
| 90 | +/** |
| 91 | + * Accesses the 'key' value of this [KeyValueProperty][KeyValueProperty] |
| 92 | + * [DataRow][DataRow]. |
| 93 | + * |
| 94 | + * This is a temporary, future-proof, extension property in preparation of the migration from [KeyValueProperty] |
| 95 | + * to [NameValueProperty]. |
| 96 | + */ |
| 97 | +public val DataRow<KeyValueProperty<*>?>.name: String? |
| 98 | + @JvmName("NullableKeyValueProperty_name") |
| 99 | + get() = key |
| 100 | + |
| 101 | +public val <T : Any?> ColumnsScope<KeyValueProperty<T>>.value: DataColumn<T> |
| 102 | + @JvmName("KeyValueProperty_value") |
| 103 | + get() = this["value"].cast() |
| 104 | + |
| 105 | +public val <T : Any?> ColumnsScope<KeyValueProperty<T>?>.value: DataColumn<T?> |
| 106 | + @JvmName("NullableKeyValueProperty_value") |
| 107 | + get() = this["value"].cast() |
| 108 | + |
| 109 | +public val <T : Any?> DataRow<KeyValueProperty<T>>.value: T |
| 110 | + @JvmName("KeyValueProperty_value") |
| 111 | + get() = this["value"] as T |
| 112 | + |
| 113 | +public val <T : Any?> DataRow<KeyValueProperty<T>?>.value: T? |
| 114 | + @JvmName("NullableKeyValueProperty_value") |
| 115 | + get() = this["value"] as T? |
| 116 | + |
| 117 | +// endregion |
0 commit comments