Skip to content

Commit 8d0578e

Browse files
add hashCode and equals in IpInterface
1 parent aac86d2 commit 8d0578e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

cidre/src/commonMain/kotlin/at/asitplus/cidre/IpInterface.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,26 @@ constructor(override val prefix: Prefix, val network: IpNetwork<N, S>) :
1313
IpAddressAndPrefix<N, S> by network {
1414

1515
override fun toString(): String = "$address/$prefix"
16-
1716
override fun toX509Octets(): ByteArray = super.toX509Octets()
1817

18+
override fun equals(other: Any?): Boolean {
19+
if (this === other) return true
20+
if (other == null || this::class != other::class) return false
21+
22+
other as IpInterface<*, *>
23+
24+
if (prefix != other.prefix) return false
25+
if (network != other.network) return false
26+
27+
return true
28+
}
29+
30+
override fun hashCode(): Int {
31+
var result = prefix.hashCode()
32+
result = 31 * result + network.hashCode()
33+
return result
34+
}
35+
1936
companion object {
2037
@Suppress("UNCHECKED_CAST")
2138
internal fun <N : Number, S: CidrNumber<S>> unsafe(

0 commit comments

Comments
 (0)