Skip to content

Commit 2974f4d

Browse files
committed
Minor refactoring in encodeValue function
1 parent d4aa42f commit 2974f4d

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/io/writeJson.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ internal fun encodeRowWithMetadata(
166166
return JsonObject(values.toMap())
167167
}
168168

169-
internal fun encodeValue(col: AnyCol, index: Int, customEncoders: List<CustomEncoder> = emptyList()): JsonElement =
170-
when {
171-
customEncoders.any { it.canEncode(col[index]) } -> {
172-
customEncoders.first { it.canEncode(col[index]) }.encode(col[index])
173-
}
169+
internal fun encodeValue(col: AnyCol, index: Int, customEncoders: List<CustomEncoder> = emptyList()): JsonElement {
170+
val matchingEncoder = customEncoders.firstOrNull { it.canEncode(col[index]) }
171+
172+
return when {
173+
matchingEncoder != null -> matchingEncoder.encode(col[index])
174174

175175
col.isList() -> col[index]?.let { list ->
176176
val values = (list as List<*>).map { convert(it) }
@@ -181,6 +181,7 @@ internal fun encodeValue(col: AnyCol, index: Int, customEncoders: List<CustomEnc
181181

182182
else -> JsonPrimitive(col[index]?.toString())
183183
}
184+
}
184185

185186
internal class DataframeConvertableEncoder(
186187
private val encoders: List<CustomEncoder>,

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/io/writeJson.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ internal fun encodeRowWithMetadata(
166166
return JsonObject(values.toMap())
167167
}
168168

169-
internal fun encodeValue(col: AnyCol, index: Int, customEncoders: List<CustomEncoder> = emptyList()): JsonElement =
170-
when {
171-
customEncoders.any { it.canEncode(col[index]) } -> {
172-
customEncoders.first { it.canEncode(col[index]) }.encode(col[index])
173-
}
169+
internal fun encodeValue(col: AnyCol, index: Int, customEncoders: List<CustomEncoder> = emptyList()): JsonElement {
170+
val matchingEncoder = customEncoders.firstOrNull { it.canEncode(col[index]) }
171+
172+
return when {
173+
matchingEncoder != null -> matchingEncoder.encode(col[index])
174174

175175
col.isList() -> col[index]?.let { list ->
176176
val values = (list as List<*>).map { convert(it) }
@@ -181,6 +181,7 @@ internal fun encodeValue(col: AnyCol, index: Int, customEncoders: List<CustomEnc
181181

182182
else -> JsonPrimitive(col[index]?.toString())
183183
}
184+
}
184185

185186
internal class DataframeConvertableEncoder(
186187
private val encoders: List<CustomEncoder>,

docs/StardustDocs/snippets/manual/extensionPropertiesApi1.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@
327327
</style>
328328
</head>
329329
<body>
330-
<table class="dataframe" id="df_1291845901"></table>
330+
<table class="dataframe" id="df_-1627389683"></table>
331331

332-
<table class="dataframe" id="static_df_1291845902"><thead><tr><th class="bottomBorder" style="text-align:left">example</th></tr></thead><tbody><tr><td style="vertical-align:top">123</td></tr></tbody></table>
332+
<table class="dataframe" id="static_df_-1627389682"><thead><tr><th class="bottomBorder" style="text-align:left">example</th></tr></thead><tbody><tr><td style="vertical-align:top">123</td></tr></tbody></table>
333333
<p class="dataframe_description"></p>
334334
</body>
335335
<script>
@@ -609,11 +609,11 @@
609609

610610
/*<!--*/
611611
call_DataFrame(function() { DataFrame.addTable({ cols: [{ name: "<span title=\"example: Int\">example</span>", children: [], rightAlign: true, values: ["<span class=\"formatted\" title=\"\"><span class=\"numbers\">123</span></span>"] },
612-
], id: 1291845901, rootId: 1291845901, totalRows: 1 } ) });
612+
], id: -1627389683, rootId: -1627389683, totalRows: 1 } ) });
613613
/*-->*/
614614

615-
call_DataFrame(function() { DataFrame.renderTable(1291845901) });
615+
call_DataFrame(function() { DataFrame.renderTable(-1627389683) });
616616

617-
document.getElementById("static_df_1291845902").style.display = "none";
617+
document.getElementById("static_df_-1627389682").style.display = "none";
618618
</script>
619619
</html>

0 commit comments

Comments
 (0)