Skip to content

Commit

Permalink
Ensure the Scala Ordering is used in the java PriorityQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
ssaavedra committed Aug 30, 2018
1 parent 80593ad commit 1f85bcb
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ package org.scalafmt.internal
*
* @tparam T the values inside the queue
*/
class PriorityQueue[T] {
private[this] val q = new java.util.PriorityQueue[T]
class PriorityQueue[T <: Ordered[T]] {
private[this] val q =
new java.util.PriorityQueue[T](11, (t: T, t1: T) => t1.compare(t))

def dequeueAll: Unit = q.clear()

Expand All @@ -20,9 +21,12 @@ class PriorityQueue[T] {

def enqueue(x: T): Unit = q.add(x)

def +=(x: T): Unit = q.add(x)
def +=(x: T): PriorityQueue[T] = {
q.add(x)
this
}

def nonEmpty: Boolean = !q.isEmpty
def nonEmpty: Boolean = !isEmpty

def isEmpty: Boolean = q.isEmpty

Expand Down

0 comments on commit 1f85bcb

Please sign in to comment.