Scala Library: scala.concurrent.duration.Deadline.DeadlineIsOrdered
scala.concurrent.duration.Deadline.DeadlineIsOrdered
implicit object DeadlineIsOrdered extends Ordering[Deadline]The natural ordering for deadline is determined by the natural order of the underlying (finite) duration.
Type Members
class Ops extends AnyRef
This inner class defines comparison operators available for T .
- Definition Classes
- Ordering
Value Members From java.util.Comparator
def reversed(): Comparator[Deadline]
- Definition Classes
- Comparator
(defined at java.util.Comparator)
def thenComparing(arg0: Comparator[_ >: Deadline]): Comparator[Deadline]
- Definition Classes
- Comparator
(defined at java.util.Comparator)
def thenComparingDouble(arg0: ToDoubleFunction[_ >: Deadline]): Comparator[Deadline]
- Definition Classes
- Comparator
(defined at java.util.Comparator)
def thenComparingInt(arg0: ToIntFunction[_ >: Deadline]): Comparator[Deadline]
- Definition Classes
- Comparator
(defined at java.util.Comparator)
def thenComparingLong(arg0: ToLongFunction[_ >: Deadline]): Comparator[Deadline]
- Definition Classes
- Comparator
(defined at java.util.Comparator)
def thenComparing[U <: Comparable[_ >: U]](arg0: java.util.function.Function[_ >: Deadline, _ <: U]): Comparator[Deadline]
- Definition Classes
- Comparator
(defined at java.util.Comparator)
def thenComparing[U](arg0: java.util.function.Function[_ >: Deadline, _ <: U], arg1: Comparator[_ >: U]): Comparator[Deadline]
- Definition Classes
- Comparator
(defined at java.util.Comparator)
Value Members From scala.concurrent.duration.Deadline.DeadlineIsOrdered
def compare(a: Deadline, b: Deadline): Int
Returns an integer whose sign communicates how x compares to y.
The result sign has the following meaning:
- negative if x < y
- positive if x > y
-
zero otherwise (if x == y)
- Definition Classes
- DeadlineIsOrdered → Ordering → Comparator
(defined at scala.concurrent.duration.Deadline.DeadlineIsOrdered)
Value Members From scala.math.Ordering
def equiv(x: Deadline, y: Deadline): Boolean
Return true if x == y in the ordering.
- Definition Classes
- Ordering → PartialOrdering → Equiv
(defined at scala.math.Ordering)
def gt(x: Deadline, y: Deadline): Boolean
Return true if x > y in the ordering.
- Definition Classes
- Ordering → PartialOrdering
(defined at scala.math.Ordering)
def gteq(x: Deadline, y: Deadline): Boolean
Return true if x >= y in the ordering.
- Definition Classes
- Ordering → PartialOrdering
(defined at scala.math.Ordering)
def lt(x: Deadline, y: Deadline): Boolean
Return true if x < y in the ordering.
- Definition Classes
- Ordering → PartialOrdering
(defined at scala.math.Ordering)
def lteq(x: Deadline, y: Deadline): Boolean
Return true if x <= y in the ordering.
- Definition Classes
- Ordering → PartialOrdering
(defined at scala.math.Ordering)
def max(x: Deadline, y: Deadline): Deadline
Return x if x >= y , otherwise y .
- Definition Classes
- Ordering
(defined at scala.math.Ordering)
def min(x: Deadline, y: Deadline): Deadline
Return x if x <= y , otherwise y .
- Definition Classes
- Ordering
(defined at scala.math.Ordering)
implicit def mkOrderingOps(lhs: Deadline): Ops
This implicit method augments T with the comparison operators defined in
scala.math.Ordering.Ops .
- Definition Classes
- Ordering
(defined at scala.math.Ordering)
def on[U](f: (U) ⇒ Deadline): math.Ordering[U]
Given f, a function from U into T, creates an Ordering[U] whose compare function is equivalent to:
def compare(x:U, y:U) = Ordering[T].compare(f(x), f(y))- Definition Classes
- Ordering
(defined at scala.math.Ordering)
def reverse: math.Ordering[Deadline]
Return the opposite ordering of this one.
- Definition Classes
- Ordering → PartialOrdering
(defined at scala.math.Ordering)
def tryCompare(x: Deadline, y: Deadline): Some[Int]
Returns whether a comparison between x and y is defined, and if so the
result of compare(x, y) .
- Definition Classes
- Ordering → PartialOrdering (defined at scala.math.Ordering)
Full Source:
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2013, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
package scala.concurrent.duration
/**
* This class stores a deadline, as obtained via `Deadline.now` or the
* duration DSL:
*
* {{{
* import scala.concurrent.duration._
* 3.seconds.fromNow
* }}}
*
* Its main purpose is to manage repeated attempts to achieve something (like
* awaiting a condition) by offering the methods `hasTimeLeft` and `timeLeft`. All
* durations are measured according to `System.nanoTime` aka wall-time; this
* does not take into account changes to the system clock (such as leap
* seconds).
*/
case class Deadline private (time: FiniteDuration) extends Ordered[Deadline] {
/**
* Return a deadline advanced (i.e., moved into the future) by the given duration.
*/
def +(other: FiniteDuration): Deadline = copy(time = time + other)
/**
* Return a deadline moved backwards (i.e., towards the past) by the given duration.
*/
def -(other: FiniteDuration): Deadline = copy(time = time - other)
/**
* Calculate time difference between this and the other deadline, where the result is directed (i.e., may be negative).
*/
def -(other: Deadline): FiniteDuration = time - other.time
/**
* Calculate time difference between this duration and now; the result is negative if the deadline has passed.
*
* '''''Note that on some systems this operation is costly because it entails a system call.'''''
* Check `System.nanoTime` for your platform.
*/
def timeLeft: FiniteDuration = this - Deadline.now
/**
* Determine whether the deadline still lies in the future at the point where this method is called.
*
* '''''Note that on some systems this operation is costly because it entails a system call.'''''
* Check `System.nanoTime` for your platform.
*/
def hasTimeLeft(): Boolean = !isOverdue()
/**
* Determine whether the deadline lies in the past at the point where this method is called.
*
* '''''Note that on some systems this operation is costly because it entails a system call.'''''
* Check `System.nanoTime` for your platform.
*/
def isOverdue(): Boolean = (time.toNanos - System.nanoTime()) < 0
/**
* The natural ordering for deadline is determined by the natural order of the underlying (finite) duration.
*/
def compare(other: Deadline) = time compare other.time
}
object Deadline {
/**
* Construct a deadline due exactly at the point where this method is called. Useful for then
* advancing it to obtain a future deadline, or for sampling the current time exactly once and
* then comparing it to multiple deadlines (using subtraction).
*/
def now: Deadline = Deadline(Duration(System.nanoTime, NANOSECONDS))
/**
* The natural ordering for deadline is determined by the natural order of the underlying (finite) duration.
*/
implicit object DeadlineIsOrdered extends Ordering[Deadline] {
def compare(a: Deadline, b: Deadline) = a compare b
}
}Interested in Scala?
I send out weekly, personalized emails with articles and conference talks.
Subscribe now.