From f63d6a53edc5ca2e92b9a8524daf740121bae8be Mon Sep 17 00:00:00 2001 From: Sebastian Reddig Date: Tue, 3 Sep 2024 09:35:53 +0200 Subject: [PATCH] Example why Kotlin is not the holy grail and why Lombok is not bad --- .../hattrickdata/HattrickDataInfoKotlin.kt | 121 ++++++++++++++++++ .../hattrickdata/HattrickDataInfoKotlin2.kt | 121 ++++++++++++++++++ .../hattrickdata/HattrickDataInfoTest.java | 78 +++++++++++ 3 files changed, 320 insertions(+) create mode 100644 src/main/java/hattrickdata/HattrickDataInfoKotlin.kt create mode 100644 src/main/java/hattrickdata/HattrickDataInfoKotlin2.kt create mode 100644 src/test/java/hattrickdata/HattrickDataInfoTest.java diff --git a/src/main/java/hattrickdata/HattrickDataInfoKotlin.kt b/src/main/java/hattrickdata/HattrickDataInfoKotlin.kt new file mode 100644 index 000000000..0ba8ca027 --- /dev/null +++ b/src/main/java/hattrickdata/HattrickDataInfoKotlin.kt @@ -0,0 +1,121 @@ +package hattrickdata + +import core.util.HODateTime + +open class HattrickDataInfoKotlin { + var fileName: String? = null + private set + var version: String? = null + private set + var userId: Int = 0 + private set + var fetchedDate: HODateTime? = null + private set + + constructor(fileName: String?, version: String?, userId: Int, fetchedDate: HODateTime?) { + this.fileName = fileName + this.version = version + this.userId = userId + this.fetchedDate = fetchedDate + } + + constructor() + + protected constructor(b: HattrickDataInfoKotlinBuilder<*, *>) { + this.fileName = b.fileName + this.version = b.version + this.userId = b.userId + this.fetchedDate = b.fetchedDate + } + + override fun equals(o: Any?): Boolean { + if (o === this) return true + if (o !is HattrickDataInfoKotlin) return false + val other = o + if (!other.canEqual(this as Any)) return false + val `this$fileName`: Any? = this.fileName + val `other$fileName`: Any? = other.fileName + if (if (`this$fileName` == null) `other$fileName` != null else (`this$fileName` != `other$fileName`)) return false + val `this$version`: Any? = this.version + val `other$version`: Any? = other.version + if (if (`this$version` == null) `other$version` != null else (`this$version` != `other$version`)) return false + if (this.userId != other.userId) return false + val `this$fetchedDate`: Any? = this.fetchedDate + val `other$fetchedDate`: Any? = other.fetchedDate + if (if (`this$fetchedDate` == null) `other$fetchedDate` != null else (`this$fetchedDate` != `other$fetchedDate`)) return false + return true + } + + protected fun canEqual(other: Any?): Boolean { + return other is HattrickDataInfoKotlin + } + + override fun hashCode(): Int { + val PRIME = 59 + var result = 1 + val `$fileName`: Any? = this.fileName + result = result * PRIME + (`$fileName`?.hashCode() ?: 43) + val `$version`: Any? = this.version + result = result * PRIME + (`$version`?.hashCode() ?: 43) + result = result * PRIME + this.userId + val `$fetchedDate`: Any? = this.fetchedDate + result = result * PRIME + (`$fetchedDate`?.hashCode() ?: 43) + return result + } + + override fun toString(): String { + return "HattrickDataInfoKotlin(fileName=" + this.fileName + ", version=" + this.version + ", userId=" + this.userId + ", fetchedDate=" + this.fetchedDate + ")" + } + + abstract class HattrickDataInfoKotlinBuilder?> { + internal var fileName: String? = null + var version: String? = null + var userId: Int = 0 + var fetchedDate: HODateTime? = null + + fun fileName(fileName: String?): B { + this.fileName = fileName + return self() + } + + fun version(version: String?): B { + this.version = version + return self() + } + + fun userId(userId: Int): B { + this.userId = userId + return self() + } + + fun fetchedDate(fetchedDate: HODateTime?): B { + this.fetchedDate = fetchedDate + return self() + } + + protected abstract fun self(): B + + abstract fun build(): C + + override fun toString(): String { + return "HattrickDataInfoKotlin.HattrickDataInfoKotlinBuilder(fileName=" + this.fileName + ", version=" + this.version + ", userId=" + this.userId + ", fetchedDate=" + this.fetchedDate + ")" + } + } + + private class HattrickDataInfoKotlinBuilderImpl : + HattrickDataInfoKotlinBuilder() { + override fun self(): HattrickDataInfoKotlinBuilderImpl { + return this + } + + override fun build(): HattrickDataInfoKotlin { + return HattrickDataInfoKotlin(this) + } + } + + companion object { + fun builder(): HattrickDataInfoKotlinBuilder<*, *> { + return HattrickDataInfoKotlinBuilderImpl() + } + } +} \ No newline at end of file diff --git a/src/main/java/hattrickdata/HattrickDataInfoKotlin2.kt b/src/main/java/hattrickdata/HattrickDataInfoKotlin2.kt new file mode 100644 index 000000000..17286b1ad --- /dev/null +++ b/src/main/java/hattrickdata/HattrickDataInfoKotlin2.kt @@ -0,0 +1,121 @@ +package hattrickdata + +import core.util.HODateTime + +open class HattrickDataInfoKotlin2 { + var fileName: String? = null + private set + var version: String? = null + private set + var userId: Int = 0 + private set + var fetchedDate: HODateTime? = null + private set + + constructor(fileName: String?, version: String?, userId: Int, fetchedDate: HODateTime?) { + this.fileName = fileName + this.version = version + this.userId = userId + this.fetchedDate = fetchedDate + } + + constructor() + + protected constructor(b: HattrickDataInfoKotlinBuilder<*, *>) { + this.fileName = b.fileName + this.version = b.version + this.userId = b.userId + this.fetchedDate = b.fetchedDate + } + +// override fun equals(o: Any?): Boolean { +// if (o === this) return true +// if (o !is HattrickDataInfoKotlin2) return false +// val other = o +// if (!other.canEqual(this as Any)) return false +// val `this$fileName`: Any? = this.fileName +// val `other$fileName`: Any? = other.fileName +// if (if (`this$fileName` == null) `other$fileName` != null else (`this$fileName` != `other$fileName`)) return false +// val `this$version`: Any? = this.version +// val `other$version`: Any? = other.version +// if (if (`this$version` == null) `other$version` != null else (`this$version` != `other$version`)) return false +// if (this.userId != other.userId) return false +// val `this$fetchedDate`: Any? = this.fetchedDate +// val `other$fetchedDate`: Any? = other.fetchedDate +// if (if (`this$fetchedDate` == null) `other$fetchedDate` != null else (`this$fetchedDate` != `other$fetchedDate`)) return false +// return true +// } +// +// protected fun canEqual(other: Any?): Boolean { +// return other is HattrickDataInfoKotlin2 +// } +// +// override fun hashCode(): Int { +// val PRIME = 59 +// var result = 1 +// val `$fileName`: Any? = this.fileName +// result = result * PRIME + (`$fileName`?.hashCode() ?: 43) +// val `$version`: Any? = this.version +// result = result * PRIME + (`$version`?.hashCode() ?: 43) +// result = result * PRIME + this.userId +// val `$fetchedDate`: Any? = this.fetchedDate +// result = result * PRIME + (`$fetchedDate`?.hashCode() ?: 43) +// return result +// } + + override fun toString(): String { + return "HattrickDataInfoKotlin2(fileName=" + this.fileName + ", version=" + this.version + ", userId=" + this.userId + ", fetchedDate=" + this.fetchedDate + ")" + } + + abstract class HattrickDataInfoKotlinBuilder?> { + internal var fileName: String? = null + var version: String? = null + var userId: Int = 0 + var fetchedDate: HODateTime? = null + + fun fileName(fileName: String?): B { + this.fileName = fileName + return self() + } + + fun version(version: String?): B { + this.version = version + return self() + } + + fun userId(userId: Int): B { + this.userId = userId + return self() + } + + fun fetchedDate(fetchedDate: HODateTime?): B { + this.fetchedDate = fetchedDate + return self() + } + + protected abstract fun self(): B + + abstract fun build(): C + + override fun toString(): String { + return "HattrickDataInfoKotlin2.HattrickDataInfoKotlinBuilder(fileName=" + this.fileName + ", version=" + this.version + ", userId=" + this.userId + ", fetchedDate=" + this.fetchedDate + ")" + } + } + + private class HattrickDataInfoKotlinBuilderImpl : + HattrickDataInfoKotlinBuilder() { + override fun self(): HattrickDataInfoKotlinBuilderImpl { + return this + } + + override fun build(): HattrickDataInfoKotlin2 { + return HattrickDataInfoKotlin2(this) + } + } + + companion object { + fun builder(): HattrickDataInfoKotlinBuilder<*, *> { + return HattrickDataInfoKotlinBuilderImpl() + } + } +} \ No newline at end of file diff --git a/src/test/java/hattrickdata/HattrickDataInfoTest.java b/src/test/java/hattrickdata/HattrickDataInfoTest.java new file mode 100644 index 000000000..b01c52133 --- /dev/null +++ b/src/test/java/hattrickdata/HattrickDataInfoTest.java @@ -0,0 +1,78 @@ +package hattrickdata; + +import core.util.HODateTime; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; + +class HattrickDataInfoTest { + + private static final class ValueFactory { + + public static String createFileName() { + return "ValueFactory.createFileName()"; + } + + public static String createVersion() { + return "1.2"; + } + + public static HODateTime createFetchedDate() { + return HODateTime.fromHT("2024-09-03 09:00:00"); + } + } + + @Test + void testEquals_HattrickDataInfo() { + final HattrickDataInfo hattrickDataInfo = HattrickDataInfo.builder() + .fileName(ValueFactory.createFileName()) + .version(ValueFactory.createVersion()) + .fetchedDate(ValueFactory.createFetchedDate()) + .build(); + final HattrickDataInfo hattrickDataInfoEqual = HattrickDataInfo.builder() + .fileName(ValueFactory.createFileName()) + .version(ValueFactory.createVersion()) + .fetchedDate(ValueFactory.createFetchedDate()) + .build(); + + assertThat(hattrickDataInfo).isEqualTo(hattrickDataInfo); + assertThat(hattrickDataInfoEqual).isEqualTo(hattrickDataInfoEqual); + assertThat(hattrickDataInfo).isEqualTo(hattrickDataInfoEqual); + } + + @Test + void testEquals_HattrickDataInfoKotlin() { + final HattrickDataInfoKotlin hattrickDataInfo = HattrickDataInfoKotlin.Companion.builder() + .fileName(ValueFactory.createFileName()) + .version(ValueFactory.createVersion()) + .fetchedDate(ValueFactory.createFetchedDate()) + .build(); + final HattrickDataInfoKotlin hattrickDataInfoEqual = HattrickDataInfoKotlin.Companion.builder() + .fileName(ValueFactory.createFileName()) + .version(ValueFactory.createVersion()) + .fetchedDate(ValueFactory.createFetchedDate()) + .build(); + + assertThat(hattrickDataInfo).isEqualTo(hattrickDataInfo); + assertThat(hattrickDataInfoEqual).isEqualTo(hattrickDataInfoEqual); + assertThat(hattrickDataInfo).isEqualTo(hattrickDataInfoEqual); + } + + @Test + void testEquals_HattrickDataInfoKotlin2() { + final HattrickDataInfoKotlin2 hattrickDataInfo = HattrickDataInfoKotlin2.Companion.builder() + .fileName(ValueFactory.createFileName()) + .version(ValueFactory.createVersion()) + .fetchedDate(ValueFactory.createFetchedDate()) + .build(); + final HattrickDataInfoKotlin2 hattrickDataInfoEqual = HattrickDataInfoKotlin2.Companion.builder() + .fileName(ValueFactory.createFileName()) + .version(ValueFactory.createVersion()) + .fetchedDate(ValueFactory.createFetchedDate()) + .build(); + + assertThat(hattrickDataInfo).isEqualTo(hattrickDataInfo); + assertThat(hattrickDataInfoEqual).isEqualTo(hattrickDataInfoEqual); + assertThat(hattrickDataInfo).isEqualTo(hattrickDataInfoEqual); + } +} \ No newline at end of file