Skip to content
This repository has been archived by the owner on Apr 4, 2021. It is now read-only.

Commit

Permalink
Handle comparison of nulls #310
Browse files Browse the repository at this point in the history
  • Loading branch information
szarnyasg committed Mar 4, 2018
1 parent 21de72c commit 31814c6
Showing 1 changed file with 42 additions and 33 deletions.
75 changes: 42 additions & 33 deletions ire/src/main/scala/hu/bme/mit/ire/util/GenericMath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,40 +202,49 @@ object GenericMath extends Ordering[Any] {
}
}

override def compare(a: Any, b: Any): Int = a match {
case a: Float =>
b match {
case b: Float => if (a > b) 1 else if (a < b) -1 else 0
case b: Double => if (a > b) 1 else if (a < b) -1 else 0
case b: Int => if (a > b) 1 else if (a < b) -1 else 0
case b: Long => if (a > b) 1 else if (a < b) -1 else 0
}
override def compare(a: Any, b: Any): Int = {
if (a == null && b == null) {
return 0
} else if (a == null) {
return 1
} else if (b == null) {
return -1
}
a match {
case a: Float =>
b match {
case b: Float => if (a > b) 1 else if (a < b) -1 else 0
case b: Double => if (a > b) 1 else if (a < b) -1 else 0
case b: Int => if (a > b) 1 else if (a < b) -1 else 0
case b: Long => if (a > b) 1 else if (a < b) -1 else 0
}

case a: Double =>
b match {
case b: Float => if (a > b) 1 else if (a < b) -1 else 0
case b: Double => if (a > b) 1 else if (a < b) -1 else 0
case b: Int => if (a > b) 1 else if (a < b) -1 else 0
case b: Long => if (a > b) 1 else if (a < b) -1 else 0
}
case a: Int =>
b match {
case b: Float => if (a > b) 1 else if (a < b) -1 else 0
case b: Double => if (a > b) 1 else if (a < b) -1 else 0
case b: Int => if (a > b) 1 else if (a < b) -1 else 0
case b: Long => if (a > b) 1 else if (a < b) -1 else 0
}
case a: Long =>
b match {
case b: Float => if (a > b) 1 else if (a < b) -1 else 0
case b: Double => if (a > b) 1 else if (a < b) -1 else 0
case b: Int => if (a > b) 1 else if (a < b) -1 else 0
case b: Long => if (a > b) 1 else if (a < b) -1 else 0
}
case a: String =>
b match {
case b: String => a.compareTo(b)
}
case a: Double =>
b match {
case b: Float => if (a > b) 1 else if (a < b) -1 else 0
case b: Double => if (a > b) 1 else if (a < b) -1 else 0
case b: Int => if (a > b) 1 else if (a < b) -1 else 0
case b: Long => if (a > b) 1 else if (a < b) -1 else 0
}
case a: Int =>
b match {
case b: Float => if (a > b) 1 else if (a < b) -1 else 0
case b: Double => if (a > b) 1 else if (a < b) -1 else 0
case b: Int => if (a > b) 1 else if (a < b) -1 else 0
case b: Long => if (a > b) 1 else if (a < b) -1 else 0
}
case a: Long =>
b match {
case b: Float => if (a > b) 1 else if (a < b) -1 else 0
case b: Double => if (a > b) 1 else if (a < b) -1 else 0
case b: Int => if (a > b) 1 else if (a < b) -1 else 0
case b: Long => if (a > b) 1 else if (a < b) -1 else 0
}
case a: String =>
b match {
case b: String => a.compareTo(b)
}
}
}

def toLong(a: Any): Long = a match {
Expand Down

0 comments on commit 31814c6

Please sign in to comment.