org.feijoas.mango.common.collect

Range

Related Docs: class Range | package collect

object Range extends Serializable

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 appropriate DiscreteDomain to ContiguousSet#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.")

Notation      Definition         Factory method
(a..b)        {x | a < x < b}    Range#open
[a..b]        {x | a <= x <= b}  Range#closed
(a..b]        {x | a < x <= b}   Range#openClosed
[a..b)        {x | a <= x < b}   Range#closedOpen
(a..+inf)     {x | x > a}        Range#greaterThan
[a..+inf)     {x | x >= a}       Range#atLeast
(-inf..b)     {x | x < b}        Range#lessThan
(-inf..b]     {x | x <= b}       Range#atMost
(-inf..+inf)  {x}                Range#all

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:

Warnings
Other notes
Pattern matching

Extractors are defined for general ranges with finite and infinite bounds. 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
}
Difference between Mango and Guava implementation

Since most Scala classes don't implement Ordered a Range of type T needs a "companion" type class of Ordering[T].

Further reading

See the Guava User Guide article on Range.

Since

0.8 (copied from Guava-libraries)

Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Range
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  4. def all[T, O <: Ordering[T]]()(implicit ord: O): Range[T, O]

    Returns a range that contains every value of type T.

    Returns a range that contains every value of type T.

  5. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  6. def atLeast[T, O <: Ordering[T]](endpoint: T)(implicit ord: O): Range[T, O]

    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.

  7. def atMost[T, O <: Ordering[T]](endpoint: T)(implicit ord: O): Range[T, O]

    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.

  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def closed[T, O <: Ordering[T]](lower: T, upper: T)(implicit ord: O): Range[T, O]

    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.

    Annotations
    @throws( ... )
    Exceptions thrown

    IllegalArgumentException if lower is greater than upper

  10. def closedOpen[T, O <: Ordering[T]](lower: T, upper: T)(implicit ord: O): Range[T, O]

    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.

    Annotations
    @throws( ... )
    Exceptions thrown

    IllegalArgumentException if lower is greater than upper

  11. def downTo[T, O <: Ordering[T]](endpoint: T, boundType: BoundType)(implicit ord: O): Range[T, O]

    Returns a range from the given endpoint, which may be either inclusive (closed) or exclusive (open), with no upper bound.

  12. def encloseAll[T, O <: Ordering[T]](values: Iterable[T])(implicit ord: O): Range[T, O]

    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.

    Annotations
    @throws( ... ) @throws( ... )
    Exceptions thrown

    ClassCastException if the parameters are not mutually comparable

    NoSuchElementException if values is empty

    NullPointerException if any of values is null

  13. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  14. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  15. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  17. def greaterThan[T, O <: Ordering[T]](endpoint: T)(implicit ord: O): Range[T, O]

    Returns a range that contains all values strictly greater than endpoint.

    Returns a range that contains all values strictly greater than endpoint.

  18. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  19. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  20. def lessThan[T, O <: Ordering[T]](endpoint: T)(implicit ord: O): Range[T, O]

    Returns a range that contains all values strictly less than endpoint.

    Returns a range that contains all values strictly less than endpoint.

  21. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  22. final def notify(): Unit

    Definition Classes
    AnyRef
  23. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  24. def open[T, O <: Ordering[T]](lower: T, upper: T)(implicit ord: O): Range[T, O]

    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.

    Annotations
    @throws( ... )
    Exceptions thrown

    IllegalArgumentException if lower is greater than or equal to upper

  25. def openClosed[T, O <: Ordering[T]](lower: T, upper: T)(implicit ord: O): Range[T, O]

    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.

    Annotations
    @throws( ... )
    Exceptions thrown

    IllegalArgumentException if lower is greater than upper

  26. def range[T, O <: Ordering[T]](lower: T, lowerType: BoundType, upper: T, upperType: BoundType)(implicit ord: O): Range[T, O]

    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).

    Annotations
    @throws( ... )
    Exceptions thrown

    IllegalArgumentException if lower is greater than upper

  27. def singleton[T, O <: Ordering[T]](value: T)(implicit ord: O): Range[T, O]

    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.

  28. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  29. def toString(): String

    Definition Classes
    AnyRef → Any
  30. def unapply[T, O <: Ordering[T]](range: Range[T, O]): Option[(Bound[T], Bound[T])]

    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
    }
  31. def upTo[T, O <: Ordering[T]](endpoint: T, boundType: BoundType)(implicit ord: O): Range[T, O]

    Returns a range with no lower bound up to the given endpoint, which may be either inclusive (closed) or exclusive (open).

  32. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped