From e96db77fe56e091ae4d064bc9d9c0077d08e5641 Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 14 Dec 2011 18:11:12 +0100 Subject: [PATCH] make infinite durations compare true to themselves, see #1514 --- .../src/test/scala/akka/util/DurationSpec.scala | 10 ++++++++++ akka-actor/src/main/scala/akka/util/Duration.scala | 6 ++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/akka-actor-tests/src/test/scala/akka/util/DurationSpec.scala b/akka-actor-tests/src/test/scala/akka/util/DurationSpec.scala index 6a291872b8..4a04a648bf 100644 --- a/akka-actor-tests/src/test/scala/akka/util/DurationSpec.scala +++ b/akka-actor-tests/src/test/scala/akka/util/DurationSpec.scala @@ -38,6 +38,16 @@ class DurationSpec extends WordSpec with MustMatchers { (inf - minf) must be(inf) (minf - inf) must be(minf) (minf + minf) must be(minf) + assert(inf == inf) + assert(minf == minf) + inf.compareTo(inf) must be(0) + inf.compareTo(one) must be(1) + minf.compareTo(minf) must be(0) + minf.compareTo(one) must be(-1) + assert(inf != minf) + assert(minf != inf) + assert(one != inf) + assert(minf != one) } "support fromNow" in { diff --git a/akka-actor/src/main/scala/akka/util/Duration.scala b/akka-actor/src/main/scala/akka/util/Duration.scala index 6e9310e5d8..fba61c8a48 100644 --- a/akka-actor/src/main/scala/akka/util/Duration.scala +++ b/akka-actor/src/main/scala/akka/util/Duration.scala @@ -148,8 +148,6 @@ object Duration { trait Infinite { this: Duration ⇒ - override def equals(other: Any) = false - def +(other: Duration): Duration = other match { case _: this.type ⇒ this @@ -192,7 +190,7 @@ object Duration { */ val Inf: Duration = new Duration with Infinite { override def toString = "Duration.Inf" - def compare(other: Duration) = 1 + def compare(other: Duration) = if (other eq this) 0 else 1 def unary_- : Duration = MinusInf } @@ -202,7 +200,7 @@ object Duration { */ val MinusInf: Duration = new Duration with Infinite { override def toString = "Duration.MinusInf" - def compare(other: Duration) = -1 + def compare(other: Duration) = if (other eq this) 0 else -1 def unary_- : Duration = Inf }