Skip to content

Commit

Permalink
Add hascode and equals function in order models (#21)
Browse files Browse the repository at this point in the history
* Add function in order

* Add function in order response
  • Loading branch information
Harsh3305 authored Jul 9, 2023
1 parent 7eb390e commit a88c835
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/kotlin/com/hrv/mart/orderlibrary/model/OrderResponse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class OrderResponse (
val status: Status = Status.PROCESS,
val dateTimeOfOrder: LocalDateTime = LocalDateTime.now()
) {

companion object {
fun parseFrom (order: Order, productOrdered: List<ProductOrdered>) =
OrderResponse(
Expand All @@ -30,4 +31,25 @@ data class OrderResponse (
dateTimeOfOrder = order.dateTimeOfOrder
)
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as OrderResponse

if (orderId != other.orderId) return false
if (userId != other.userId) return false
if (products != other.products) return false
if (price != other.price) return false
return status == other.status
}

override fun hashCode(): Int {
var result = orderId.hashCode()
result = 31 * result + userId.hashCode()
result = 31 * result + products.hashCode()
result = 31 * result + price.hashCode()
result = 31 * result + status.hashCode()
return result
}
}
21 changes: 21 additions & 0 deletions src/main/kotlin/com/hrv/mart/orderlibrary/model/order/Order.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,25 @@ data class Order (
price = orderRequest.price
)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Order

if (userId != other.userId) return false
if (price != other.price) return false
if (orderId != other.orderId) return false
return status == other.status
}

override fun hashCode(): Int {
var result = userId.hashCode()
result = 31 * result + price.hashCode()
result = 31 * result + orderId.hashCode()
result = 31 * result + status.hashCode()
return result
}

}

0 comments on commit a88c835

Please sign in to comment.