Returns a range that contains every value of type T
.
Returns a range that contains every value of type T
.
Returns a range that contains all values greater than or equal to
endpoint
.
Returns a range that contains all values greater than or equal to
endpoint
.
Returns a range that contains all values less than or equal to
endpoint
.
Returns a range that contains all values less than or equal to
endpoint
.
Returns a range that contains all values greater than or equal to
lower
and less than or equal to upper
.
Returns a range that contains all values greater than or equal to
lower
and less than or equal to upper
.
IllegalArgumentException
if lower
is greater than upper
Returns a range that contains all values greater than or equal to
lower
and strictly less than upper
.
Returns a range that contains all values greater than or equal to
lower
and strictly less than upper
.
IllegalArgumentException
if lower
is greater than upper
Returns a range from the given endpoint, which may be either inclusive (closed) or exclusive (open), with no upper bound.
Returns the minimal range that contains all of the given values.
Returns the minimal range that contains all of the given values. The returned range is closed on both ends.
ClassCastException
if the parameters are not mutually
comparable
NoSuchElementException
if values
is empty
NullPointerException
if any of values
is null
Returns a range that contains all values strictly greater than
endpoint
.
Returns a range that contains all values strictly greater than
endpoint
.
Returns a range that contains all values strictly less than
endpoint
.
Returns a range that contains all values strictly less than
endpoint
.
Returns a range that contains all values strictly greater than
lower
and strictly less than upper
.
Returns a range that contains all values strictly greater than
lower
and strictly less than upper
.
IllegalArgumentException
if lower
is greater than or
equal to upper
Returns a range that contains all values strictly greater than
lower
and less than or equal to upper
.
Returns a range that contains all values strictly greater than
lower
and less than or equal to upper
.
IllegalArgumentException
if lower
is greater than upper
Returns a range that contains any value from lower
to
upper
, where each endpoint may be either inclusive (closed) or exclusive
(open).
Returns a range that contains any value from lower
to
upper
, where each endpoint may be either inclusive (closed) or exclusive
(open).
IllegalArgumentException
if lower
is greater than upper
Returns a range that contains only the given value.
Returns a range that contains only the given value. The returned range is closed on both ends.
Extractor to pattern match Range
Extractor to pattern match Range
For example:
val range = Range.atLeast(6) // Range[Int,math.Ordering.Int.type] = [6..inf) range match { case Range(FiniteBound(lower, lowerType),InfiniteBound) => // matches lower = 6 // lowerType = Closed }
Returns a range with no lower bound up to the given endpoint, which may be either inclusive (closed) or exclusive (open).
A range (or "interval") defines the boundaries around a contiguous span of values of some type which an
Ordering
exists; for example, "integers from 1 to 100 inclusive." Note that it is not possible to iterate over these contained values. To do so, pass this range instance and an appropriateDiscreteDomain
toContiguousSet#create
.Types of ranges
Each end of the range may be bounded or unbounded. If bounded, there is an associated endpoint value, and the range is considered to be either open (does not include the endpoint) or closed (includes the endpoint) on that side. With three possibilities on each side, this yields nine basic types of ranges, enumerated below. (Notation: a square bracket
[ ]
indicates that the range is closed on that side; a parenthesis( )
means it is either open or unbounded. The construct{x | statement}
is read "the set of all x such that statement.")When both endpoints exist, the upper endpoint may not be less than the lower. The endpoints may be equal only if at least one of the bounds is closed:
[a..a]
: a singleton range[a..a); (a..a]
: empty ranges; also valid(a..a)
: invalid; an exception will be thrownWarnings
Ordering#compare
returns zero, not whether equals returnstrue
.Other notes
c1 <= c2 <= c3
of typeC
,r.contains(c1) && r.contains(c3)
impliesr.contains(c2)
). This means that aRange[Int,Ordering[Int]
can never be used to represent, say, "all prime numbers from 1 to 100."#contains
.a
is said to be the maximal range having property P if, for all rangesb
also having property P,a.encloses(b)
. Likewise,a
is minimal whenb.encloses(a)
for allb
having property P. See, for example, the definition ofintersection
.Pattern matching
Extractors are defined for general ranges with finite and infinite bounds. For example:
Difference between Mango and Guava implementation
Since most Scala classes don't implement
Ordered
a Range of typeT
needs a "companion" type class ofOrdering[T]
.Further reading
See the Guava User Guide article on
Range
.0.8 (copied from Guava-libraries)