Skip to content

Commit

Permalink
Review issues: add KDocs, update .editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
obabichevjb committed Oct 2, 2024
1 parent c2704aa commit 0f12391
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ij_kotlin_spaces_around_logical_operators = true
ij_kotlin_spaces_around_equality_operators = true
ij_any_align_group_field_declarations = false
ij_java_align_group_field_declarations = false
ij_kotlin_line_break_after_multiline_when_entry = false

[{.github/**/*.yml, .idea/*.xml}]
indent_size = 2
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ open class ColumnWithTransform<Unwrapped, Wrapped>(
val transformer: ColumnTransformer<Unwrapped, Wrapped>
) : ColumnType<Wrapped & Any>() {

/**
* Recursively unwraps the given value by applying the delegate's transformation.
*
* This method will recursively call unwrap on the inner delegate if the delegate
* is also an instance of [ColumnWithTransform]. This is useful for handling nested
* transformations.
*
* @param value The value to unwrap. Could be null.
* @return The unwrapped value. Returns the value transformed by the transformer if it's not null.
*/
open fun unwrapRecursive(value: Wrapped?): Any? {
return if (delegate is ColumnWithTransform<*, *>) {
(delegate as ColumnWithTransform<Any, Unwrapped>).unwrapRecursive(transformer.unwrap(value as Wrapped))
Expand All @@ -324,6 +334,15 @@ open class ColumnWithTransform<Unwrapped, Wrapped>(
}
}

/**
* Gets the original column type that this column with transformation wraps around.
*
* This property will recursively unwrap the delegate column type if the delegate
* is also an instance of [ColumnWithTransform]. This ensures that you get the
* original column type, regardless of the number of nested transformations.
*
* @return The original column's [IColumnType].
*/
val originalColumnType: IColumnType<Any>
get() = when {
delegate is ColumnWithTransform<*, *> -> delegate.originalColumnType
Expand Down Expand Up @@ -371,6 +390,18 @@ open class NullableColumnWithTransform<Unwrapped, Wrapped>(
delegate: IColumnType<Unwrapped & Any>,
transformer: ColumnTransformer<Unwrapped, Wrapped>
) : ColumnWithTransform<Unwrapped, Wrapped>(delegate, transformer) {
/**
* Recursively unwraps the given value by applying the delegate's transformation.
*
* This method will recursively call unwrap on the inner delegate if the delegate
* is also an instance of [ColumnWithTransform]. This is useful for handling nested
* transformations. Unlike [ColumnWithTransform.unwrapRecursive], this method allows
* transformation involving `null` values.
*
* @param value The value to unwrap. Could be `null`.
* @return The unwrapped value. Returns the value transformed by the transformer, which
* could be `null` if the transformer design allows it.
*/
override fun unwrapRecursive(value: Wrapped?): Any? {
return if (delegate is ColumnWithTransform<*, *>) {
(delegate as ColumnWithTransform<Any, Unwrapped>).unwrapRecursive(transformer.unwrap(value as Wrapped))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,8 @@ class ResultRow(
columnType is ColumnWithTransform<*, *> -> {
(columnType as ColumnWithTransform<Any, Any>).unwrapRecursive(defaultValueFun!!())
}

else -> defaultValueFun!!()
}

columnType.nullable -> null
else -> NotInitializedValue
}
Expand Down

0 comments on commit 0f12391

Please sign in to comment.