Compares another object for equality.
Compares another object for equality.
If the passed object is a Span
, this method will return true
only if the other
Span
returns the exact same value as this Span
for totalNanos
.
the object to compare with this one for equality
true if the other object is a Span
with the same totalNanos
value.
Returns a hash code for this Span
.
Returns a hash code for this Span
.
a hash code based only on the totalNanos
field.
This time span converted to milliseconds, computed via totalNanos / 1000000
, which
truncates off any leftover nanoseconds.
This time span converted to milliseconds, computed via totalNanos / 1000000
, which
truncates off any leftover nanoseconds.
The millisPart
and nanosPart
can be used, for example, when invoking
Thread.sleep
. For example, given a Span
named span
, you could
write:
Thread.sleep(span.millisPart, span.nanosPart)
The number of nanoseconds remaining when this time span is converted to milliseconds, computed via
(totalNanos % 1000000).toInt
.
The number of nanoseconds remaining when this time span is converted to milliseconds, computed via
(totalNanos % 1000000).toInt
.
The millisPart
and nanosPart
can be used, for example, when invoking
Thread.sleep
. For example, given a Span
named span
, you could
write:
Thread.sleep(span.millisPart, span.nanosPart)
Returns a localized string suitable for presenting to a user that describes the time span represented
by this Span
.
Returns a localized string suitable for presenting to a user that describes the time span represented
by this Span
.
For example, for Span(1, Millisecond)
, this method would return "1 millisecond"
.
For Span(9.99, Seconds)
, this method would return "9.9 seconds"
.
a localized string describing this Span
Returns a Span
representing this Span
scaled by the passed factor.
Returns a Span
representing this Span
scaled by the passed factor.
The passed factor
can be any positive number or zero, including fractional numbers. A number
greater than one will scale the Span
up to a larger value. A fractional number will scale it
down to a smaller value. A factor of 1.0 will cause the exact same Span
to be returned. A
factor of zero will cause Span.ZeroLength
to be returned.
If overflow occurs, Span.Max
will be returned. If underflow occurs, Span.ZeroLength
will be returned.
if the passed value is less than zero
Returns a string that looks similar to a factory method call that would have produced this Span
.
Returns a string that looks similar to a factory method call that would have produced this Span
.
For example, for Span(1, Millisecond)
, this method would return "Span(1, Millisecond)"
.
For Span(9.99, Seconds)
, this method would return "Span(9.99, Seconds)"
.
a string that looks like a factory method call that would produce this Span
The total number of nanoseconds in this time span.
The total number of nanoseconds in this time span.
This number will never be negative, but can be zero.
A time span.
A
Span
is used to express time spans in ScalaTest, in constructs such as thefailAfter
method of traitTimeouts
, thetimeLimit
field of traitTimeLimitedTests
, and the timeouts of traitsEventually
, , andAsyncAssertions
. Here's an example:If you prefer you can mix in or import the members of
SpanSugar
and place a units value after the timeout value. Here are some examples:In addition to expression the numeric value with an
Int
or aLong
, you can also express it via aFloat
orDouble
. Here are some examples:Internally, a
Span
is expressed in terms of aLong
number of nanoseconds. Thus, the maximum time span that can be represented isLong.MaxValue
nanoseconds, or approximately 292 years. Hopefully these won't be "famous last words," but 292 years should be sufficient for software testing purposes. Any attempt to create aSpan
longer thanLong.MaxValue
nanoseconds will be met with anIllegalArgumentException
:All of class
Span
's constructors are private. The only way you can create a newSpan
is via one of the twoapply
factory methods inSpan
's companion object. Here is a table showing one example of each numeric type and unit value:Int
Long
Float
Double