Skip to content

Commit 27cc067

Browse files
committed
Refactor to remove 5 unnecessary "if" statements
1 parent fcd0ce4 commit 27cc067

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlTableExtensions.kt

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.sql.JDBCType
2222
import kotlin.reflect.KClass
2323

2424
/**
25-
* This function replaces the native functions in [@see SqlColumn} such as
25+
* This function replaces the native functions in [@see SqlColumn] such as
2626
* [@see SqlColumn#withTypeHandler], [@see SqlColumn#withRenderingStrategy], etc.
2727
* This function preserves the non-nullable column type which is lost with the Java
2828
* native versions.
@@ -34,28 +34,13 @@ fun <T : Any> SqlTable.column(
3434
renderingStrategy: RenderingStrategy? = null,
3535
parameterTypeConverter: ((T?) -> Any?)? = null,
3636
javaType: KClass<T>? = null
37-
): SqlColumn<T> {
38-
var column: SqlColumn<T> = if (jdbcType == null) {
39-
column(name)
40-
} else {
41-
column(name, jdbcType)
42-
}
43-
44-
if (typeHandler != null) {
45-
column = column.withTypeHandler(typeHandler)
46-
}
47-
48-
if (renderingStrategy != null) {
49-
column = column.withRenderingStrategy(renderingStrategy)
50-
}
51-
52-
if (parameterTypeConverter != null) {
53-
column = column.withParameterTypeConverter(parameterTypeConverter)
54-
}
55-
56-
if (javaType != null) {
57-
column = column.withJavaType(javaType.java)
58-
}
59-
60-
return column
37+
): SqlColumn<T> = SqlColumn.Builder<T>().run {
38+
withTable(this@column)
39+
withName(name)
40+
withJdbcType(jdbcType)
41+
withTypeHandler(typeHandler)
42+
withRenderingStrategy(renderingStrategy)
43+
withParameterTypeConverter(parameterTypeConverter)
44+
withJavaType(javaType?.java)
45+
build()
6146
}

0 commit comments

Comments
 (0)