Skip to content

Commit ba61247

Browse files
committed
Some CS fixes
1 parent 464d4f3 commit ba61247

File tree

6 files changed

+45
-53
lines changed

6 files changed

+45
-53
lines changed

src/main/kotlin/org/phpinnacle/toblerone/RadixTransform.kt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,23 @@ abstract class RadixTransform<R : ConnectRecord<R>?> : Transformation<R> {
4343
).filter { it.value != 0 }
4444
}
4545

46-
override fun apply(record: R): R {
47-
return when {
48-
operatingValue(record) == null -> {
49-
record
50-
}
51-
operatingSchema(record) == null -> {
52-
applySchemaless(record)
53-
}
54-
else -> {
55-
applyWithSchema(record)
56-
}
46+
override fun apply(record: R): R = when {
47+
operatingValue(record) == null -> {
48+
record
49+
}
50+
operatingSchema(record) == null -> {
51+
applySchemaless(record)
52+
}
53+
else -> {
54+
applyWithSchema(record)
5755
}
5856
}
5957

6058
@Suppress("EmptyFunctionBlock")
6159
override fun close() {
6260
}
6361

64-
override fun config(): ConfigDef {
65-
return CONFIG_DEF
66-
}
62+
override fun config(): ConfigDef = CONFIG_DEF
6763

6864
protected abstract fun operatingSchema(record: R?): Schema?
6965
protected abstract fun operatingValue(record: R?): Any?

src/main/kotlin/org/phpinnacle/toblerone/SubstringTransform.kt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ abstract class SubstringTransform<R : ConnectRecord<R>?> : Transformation<R> {
1313
val OVERVIEW_DOC = (
1414
"Extracts parts of string fields or the entire key or value." +
1515
"Use the concrete transformation type designed for " +
16-
"the record key (<code>" + RadixTransform.Key::class.java.getName() + "</code>) or " +
17-
"the record value (<code>" + RadixTransform.Value::class.java.getName() + "</code>)."
16+
"the record key (<code>" + Key::class.java.getName() + "</code>) or " +
17+
"the record value (<code>" + Value::class.java.getName() + "</code>)."
1818
)
1919

2020
val CONFIG_DEF: ConfigDef = ConfigDef().define(
@@ -37,27 +37,23 @@ abstract class SubstringTransform<R : ConnectRecord<R>?> : Transformation<R> {
3737
).filter { it.value.isNotEmpty() }
3838
}
3939

40-
override fun apply(record: R): R {
41-
return when {
42-
operatingValue(record) == null -> {
43-
record
44-
}
45-
operatingSchema(record) == null -> {
46-
applySchemaless(record)
47-
}
48-
else -> {
49-
applyWithSchema(record)
50-
}
40+
override fun apply(record: R): R = when {
41+
operatingValue(record) == null -> {
42+
record
43+
}
44+
operatingSchema(record) == null -> {
45+
applySchemaless(record)
46+
}
47+
else -> {
48+
applyWithSchema(record)
5149
}
5250
}
5351

5452
@Suppress("EmptyFunctionBlock")
5553
override fun close() {
5654
}
5755

58-
override fun config(): ConfigDef {
59-
return CONFIG_DEF
60-
}
56+
override fun config(): ConfigDef = CONFIG_DEF
6157

6258
protected abstract fun operatingSchema(record: R?): Schema?
6359
protected abstract fun operatingValue(record: R?): Any?

src/main/kotlin/org/phpinnacle/toblerone/TrimTransform.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ abstract class TrimTransform<R : ConnectRecord<R>?> : Transformation<R> {
1313
val OVERVIEW_DOC = (
1414
"Extracts parts of string fields or the entire key or value." +
1515
"Use the concrete transformation type designed for " +
16-
"the record key (<code>" + RadixTransform.Key::class.java.getName() + "</code>) or " +
17-
"the record value (<code>" + RadixTransform.Value::class.java.getName() + "</code>)."
16+
"the record key (<code>" + Key::class.java.getName() + "</code>) or " +
17+
"the record value (<code>" + Value::class.java.getName() + "</code>)."
1818
)
1919

2020
val CONFIG_DEF: ConfigDef = ConfigDef().define(
@@ -35,38 +35,38 @@ abstract class TrimTransform<R : ConnectRecord<R>?> : Transformation<R> {
3535
fields = config.getList("fields").map { it.trim() }
3636
}
3737

38-
override fun apply(record: R): R {
39-
return when {
40-
operatingValue(record) == null -> {
41-
record
42-
}
38+
override fun apply(record: R): R = when {
39+
operatingValue(record) == null -> {
40+
record
41+
}
4342

44-
operatingSchema(record) == null -> {
45-
applySchemaless(record)
46-
}
43+
operatingSchema(record) == null -> {
44+
applySchemaless(record)
45+
}
4746

48-
else -> {
49-
applyWithSchema(record)
50-
}
47+
else -> {
48+
applyWithSchema(record)
5149
}
5250
}
5351

5452
@Suppress("EmptyFunctionBlock")
5553
override fun close() {
5654
}
5755

58-
override fun config(): ConfigDef {
59-
return CONFIG_DEF
60-
}
56+
override fun config(): ConfigDef = CONFIG_DEF
6157

6258
protected abstract fun operatingSchema(record: R?): Schema?
6359
protected abstract fun operatingValue(record: R?): Any?
64-
protected abstract fun newRecord(record: R?, updatedValue: Any?): R
60+
protected abstract fun newRecord(record: R, updatedValue: Any?): R
6561

6662
private fun applySchemaless(record: R): R {
6763
val value = Requirements.requireMap(operatingValue(record), PURPOSE)
6864
val output = value.mapValues {
69-
if (it.key in fields && it.value is String) (it.value as String).trim() else it.value
65+
if (it.key in fields && it.value is String) {
66+
(it.value as String).trim()
67+
} else {
68+
it.value
69+
}
7070
}
7171

7272
return newRecord(record, output)
@@ -96,7 +96,7 @@ abstract class TrimTransform<R : ConnectRecord<R>?> : Transformation<R> {
9696

9797
override fun operatingValue(record: R?): Any? = record?.key()
9898

99-
override fun newRecord(record: R?, updatedValue: Any?): R = record!!.newRecord(
99+
override fun newRecord(record: R, updatedValue: Any?): R = record!!.newRecord(
100100
record.topic(),
101101
record.kafkaPartition(),
102102
record.keySchema(),
@@ -112,7 +112,7 @@ abstract class TrimTransform<R : ConnectRecord<R>?> : Transformation<R> {
112112

113113
override fun operatingValue(record: R?): Any? = record?.value()
114114

115-
override fun newRecord(record: R?, updatedValue: Any?): R = record!!.newRecord(
115+
override fun newRecord(record: R, updatedValue: Any?): R = record!!.newRecord(
116116
record.topic(),
117117
record.kafkaPartition(),
118118
record.keySchema(),

src/test/kotlin/org/phpinnacle/toblerone/RadixTransformTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.util.*
1111
import kotlin.test.Test
1212
import kotlin.test.assertNull
1313

14-
class RadixTransformTest {
14+
internal class RadixTransformTest {
1515
private val xformKey: RadixTransform<SourceRecord> = RadixTransform.Key()
1616
private val xformValue: RadixTransform<SourceRecord> = RadixTransform.Value()
1717

src/test/kotlin/org/phpinnacle/toblerone/SubstringTransformTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.util.*
1111
import kotlin.test.Test
1212
import kotlin.test.assertNull
1313

14-
class SubstringTransformTest {
14+
internal class SubstringTransformTest {
1515
private val xformKey: SubstringTransform<SourceRecord> = SubstringTransform.Key()
1616
private val xformValue: SubstringTransform<SourceRecord> = SubstringTransform.Value()
1717

src/test/kotlin/org/phpinnacle/toblerone/TrimTransformTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.util.*
1111
import kotlin.test.Test
1212
import kotlin.test.assertNull
1313

14-
class TrimTransformTest {
14+
internal class TrimTransformTest {
1515
private val xformKey: TrimTransform<SourceRecord> = TrimTransform.Key()
1616
private val xformValue: TrimTransform<SourceRecord> = TrimTransform.Value()
1717

0 commit comments

Comments
 (0)