Skip to content

Commit

Permalink
feat(domain): add equals for field
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 4, 2022
1 parent b04f882 commit c679924
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
26 changes: 25 additions & 1 deletion chapi-domain/src/main/kotlin/chapi/domain/core/CodeField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,28 @@ open class CodeField(
var Modifiers: Array<String> = arrayOf(),
// for TypeScript and JavaScript only, examples: `export default sample = createHello() `
var Calls: Array<CodeCall> = 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
}
}
12 changes: 12 additions & 0 deletions chapi-domain/src/test/kotlin/chapi/domain/core/CodeFieldTest.kt
Original file line number Diff line number Diff line change
@@ -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"))
}
}

0 comments on commit c679924

Please # to comment.