Skip to content

Commit

Permalink
Example why Kotlin is not the holy grail and why Lombok is not bad
Browse files Browse the repository at this point in the history
  • Loading branch information
sgcr committed Sep 3, 2024
1 parent 7505a3d commit f63d6a5
Show file tree
Hide file tree
Showing 3 changed files with 320 additions and 0 deletions.
121 changes: 121 additions & 0 deletions src/main/java/hattrickdata/HattrickDataInfoKotlin.kt
Original file line number Diff line number Diff line change
@@ -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<C : HattrickDataInfoKotlin?, B : HattrickDataInfoKotlinBuilder<C, B>?> {
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<HattrickDataInfoKotlin?, HattrickDataInfoKotlinBuilderImpl?>() {
override fun self(): HattrickDataInfoKotlinBuilderImpl {
return this
}

override fun build(): HattrickDataInfoKotlin {
return HattrickDataInfoKotlin(this)
}
}

companion object {
fun builder(): HattrickDataInfoKotlinBuilder<*, *> {
return HattrickDataInfoKotlinBuilderImpl()
}
}
}
121 changes: 121 additions & 0 deletions src/main/java/hattrickdata/HattrickDataInfoKotlin2.kt
Original file line number Diff line number Diff line change
@@ -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<C : HattrickDataInfoKotlin2?, B : HattrickDataInfoKotlinBuilder<C, B>?> {
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<HattrickDataInfoKotlin2?, HattrickDataInfoKotlinBuilderImpl?>() {
override fun self(): HattrickDataInfoKotlinBuilderImpl {
return this
}

override fun build(): HattrickDataInfoKotlin2 {
return HattrickDataInfoKotlin2(this)
}
}

companion object {
fun builder(): HattrickDataInfoKotlinBuilder<*, *> {
return HattrickDataInfoKotlinBuilderImpl()
}
}
}
78 changes: 78 additions & 0 deletions src/test/java/hattrickdata/HattrickDataInfoTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit f63d6a5

Please sign in to comment.