diff options
author | Roland <rk@rkuhn.info> | 2012-09-12 08:22:45 +0200 |
---|---|---|
committer | Roland <rk@rkuhn.info> | 2012-09-12 08:22:45 +0200 |
commit | de9e32856297cfa07048883e1a81ca5062398d20 (patch) | |
tree | 393986a908328833367a336c2fa0b9acfbac5548 | |
parent | cd703efbc6565ea83721cab5dcf74b1ce4d5c5af (diff) | |
download | scala-de9e32856297cfa07048883e1a81ca5062398d20.tar.gz scala-de9e32856297cfa07048883e1a81ca5062398d20.tar.bz2 scala-de9e32856297cfa07048883e1a81ca5062398d20.zip |
retronym had one more improvement hidden up his sleeve for Duration
-rw-r--r-- | src/library/scala/concurrent/util/Duration.scala | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/library/scala/concurrent/util/Duration.scala b/src/library/scala/concurrent/util/Duration.scala index ee005114c1..013ec8b07f 100644 --- a/src/library/scala/concurrent/util/Duration.scala +++ b/src/library/scala/concurrent/util/Duration.scala @@ -628,17 +628,19 @@ class FiniteDuration(val length: Long, val unit: TimeUnit) extends Duration { import FiniteDuration._ import Duration._ + private[this] def bounded(max: Long) = -max <= length && length <= max + require(unit match { /* * enforce the 2^63-1 ns limit, must be pos/neg symmetrical because of unary_- */ - case NANOSECONDS ⇒ -max_ns <= length && length <= max_ns - case MICROSECONDS ⇒ -max_µs <= length && length <= max_µs - case MILLISECONDS ⇒ -max_ms <= length && length <= max_ms - case SECONDS ⇒ -max_s <= length && length <= max_s - case MINUTES ⇒ -max_min <= length && length <= max_min - case HOURS ⇒ -max_h <= length && length <= max_h - case DAYS ⇒ -max_d <= length && length <= max_d + case NANOSECONDS ⇒ bounded(max_ns) + case MICROSECONDS ⇒ bounded(max_µs) + case MILLISECONDS ⇒ bounded(max_ms) + case SECONDS ⇒ bounded(max_s) + case MINUTES ⇒ bounded(max_min) + case HOURS ⇒ bounded(max_h) + case DAYS ⇒ bounded(max_d) case _ ⇒ val v = DAYS.convert(length, unit) -max_d <= v && v <= max_d |