I have this case class:
case class Offer(id: Int, amount: Int, interestRate: Double) extends Ordered[Offer] {
def compare(that: Offer) = interestRate.compareTo(that.interestRate)
}
As you can see, I defined the ordering based upon Offer.interestRate
. I want the ordering to be increasing.
I created these offers:
Offer(1, 5, 4.0)
Offer(2, 5, 0.5)
Offer(3, 5, 1.5)
and added them to a priority queue:
val currentOffers: mutable.PriorityQueue[Offer] = mutable.PriorityQueue.empty[Offer]
The problem is that when I do currentOffers.dequeue()
I get Offer(1, 5, 4.0)
.
Instead, I would like to get:
Offer(2, 5, 0.5)
What do I need to change?