diff --git a/chapi-domain/src/main/kotlin/chapi/domain/core/CodeField.kt b/chapi-domain/src/main/kotlin/chapi/domain/core/CodeField.kt index a7c8c58f..d8aad62d 100644 --- a/chapi-domain/src/main/kotlin/chapi/domain/core/CodeField.kt +++ b/chapi-domain/src/main/kotlin/chapi/domain/core/CodeField.kt @@ -11,4 +11,28 @@ open class CodeField( var Modifiers: Array = arrayOf(), // for TypeScript and JavaScript only, examples: `export default sample = createHello() ` var Calls: Array = arrayOf() -) +) { + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is CodeField) return false + + if (TypeType != other.TypeType) return false + if (TypeValue != other.TypeValue) return false + if (TypeKey != other.TypeKey) return false + if (!Annotaiton.contentEquals(other.Annotaiton)) return false + if (!Modifiers.contentEquals(other.Modifiers)) return false + if (!Calls.contentEquals(other.Calls)) return false + + return true + } + + override fun hashCode(): Int { + var result = TypeType.hashCode() + result = 31 * result + TypeValue.hashCode() + result = 31 * result + TypeKey.hashCode() + result = 31 * result + Annotaiton.contentHashCode() + result = 31 * result + Modifiers.contentHashCode() + result = 31 * result + Calls.contentHashCode() + return result + } +} diff --git a/chapi-domain/src/test/kotlin/chapi/domain/core/CodeFieldTest.kt b/chapi-domain/src/test/kotlin/chapi/domain/core/CodeFieldTest.kt new file mode 100644 index 00000000..a2011cb0 --- /dev/null +++ b/chapi-domain/src/test/kotlin/chapi/domain/core/CodeFieldTest.kt @@ -0,0 +1,12 @@ +package chapi.domain.core + +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Test + +internal class CodeFieldTest { + + @Test + fun testEquals() { + assertEquals(CodeField(TypeType = "type"), CodeField(TypeType = "type")) + } +}