org.feijoas.mango.common

collect

package collect

This package contains generic collection traits and implementations for working with Guava collections.

Since

0.8

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

Type Members

  1. sealed trait Bound[+T] extends Serializable

    A Bound describes the to bounds of a Range.

    A Bound describes the to bounds of a Range. For example the range (4,7] has the two (finite) bounds "open" 4 and 7 "closed". A bound is either a FiniteBound[T] with a value of type T and a BoundType or an InifinteBound. An InifinteBound is used to describe unbounded ranges as for example [a..+∞)

    Since

    0.8

  2. sealed trait BoundType extends Serializable

    Indicates whether an endpoint of some range is contained in the range itself ("closed") or not ("open").

    Indicates whether an endpoint of some range is contained in the range itself ("closed") or not ("open"). If a range is unbounded on a side, it is neither open nor closed on that side; the bound simply does not exist.

    Since

    0.8 (copied from Guava-libraries)

  3. trait DiscreteDomain[C] extends AnyRef

    A descriptor for a discrete domain such as all Int instances.

    A descriptor for a discrete domain such as all Int instances. A discrete domain is one that supports the three basic operations: #next, #previous and #distance, according to their specifications. The methods #minValue and #maxValue should also be overridden for bounded types.

    A discrete domain always represents the entire set of values of its type; it cannot represent partial domains such as "prime integers" or "strings of length 5."

    See the Guava User Guide section on DiscreteDomain.

    Annotations
    @Beta()
    Since

    0.8 (copied from Guava-libraries)

  4. final class Range[T, O <: Ordering[T]] extends (T) ⇒ Boolean with 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.

    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:

    • [a..a] : a singleton range
    • [a..a); (a..a] : empty ranges; also valid
    • (a..a) : invalid; an exception will be thrown
    Warnings
    • Use immutable value types only, if at all possible. If you must use a mutable type, do not allow the endpoint instances to mutate after the range is created!
    • Your value type's comparison method should be consistent with equals if at all possible. Otherwise, be aware that concepts used throughout this documentation such as "equal", "same", "unique" and so on actually refer to whether Ordering#compare returns zero, not whether equals returns true.
    Other notes
    • Instances of this type are obtained using the static factory methods in this class.
    • Ranges are convex: whenever two values are contained, all values in between them must also be contained. More formally, for any c1 <= c2 <= c3 of type C, r.contains(c1) && r.contains(c3) implies r.contains(c2)). This means that a Range[Int,Ordering[Int] can never be used to represent, say, "all prime numbers from 1 to 100."
    • When evaluated as a predicate, a range yields the same result as invoking #contains.
    • Terminology note: a range a is said to be the maximal range having property P if, for all ranges b also having property P, a.encloses(b). Likewise, a is minimal when b.encloses(a) for all b having property P. See, for example, the definition of intersection.
    Pattern matching

    Extractors are defined for general ranges with finite and infinite bounds.

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

    Annotations
    @SerialVersionUID()
    Since

    0.8 (copied from Guava-libraries)

  5. trait RangeMap[K, V, O <: Ordering[K]] extends RangeMapLike[K, V, O, RangeMap[K, V, O]]

    A base trait for all RangeMap, mutable as well as immutable

    A base trait for all RangeMap, mutable as well as immutable

    A mapping from disjoint nonempty ranges to non-null values. Queries look up the value associated with the range (if any) that contains a specified key.

    In contrast to RangeSet, no "coalescing" is done of connected ranges, even if they are mapped to the same value.

    Usage example:

    import org.feijoas.mango.common.collect.mutable
    import org.feijoas.mango.common.collect.Range
    import math.Ordering.Int
    
    // mutable range map
    val rangeMap = mutable.RangeMap(Range.open(3, 7) -> "1") //Map((3..7) -> 1)
    rangeMap += Range.closed(9, 10) -> "2"              // Map((3..7) -> 1, [9..10] -> 2)
    rangeMap += Range.closed(12, 16) -> "3"             // Map((3..7) -> 1, [9..10] -> 2, [12..16] -> 3)
    
    val sub = rangeMap.subRangeMap(Range.closed(5, 11)) // Map([5..7) -> 1, [9..10] -> 2)
    sub.put(Range.closed(7, 9), "4")                    // sub = Map([5..7) -> 1, [7..9] -> 4, (9..10] -> 2)
    
    // rangeMap = Map((3..7) -> 1, [7..9] -> 4, (9..10] -> 2, [12..16] -> 3)
    Annotations
    @Beta()
    Since

    0.9

  6. trait RangeMapFactory[Repr[K, V, O <: Ordering[K]] <: RangeMap[K, V, O] with RangeMapLike[K, V, O, Repr[K, V, O]]] extends AnyRef

    Factory for RangeMap implementations

    Factory for RangeMap implementations

    Annotations
    @Beta()
    Since

    0.9

  7. trait RangeMapLike[K, V, O <: Ordering[K], +Repr <: RangeMapLike[K, V, O, Repr] with RangeMap[K, V, O]] extends HasNewBuilder[(Range[K, O], V), Repr]

    Implementation trait for RangeMap

    Implementation trait for RangeMap

    A mapping from disjoint nonempty ranges to non-null values. Queries look up the value associated with the range (if any) that contains a specified key.

    In contrast to RangeSet, no "coalescing" is done of connected ranges, even if they are mapped to the same value.

    Usage example:

    import org.feijoas.mango.common.collect.mutable
    import org.feijoas.mango.common.collect.Range
    import math.Ordering.Int
    
    // mutable range map
    val rangeMap = mutable.RangeMap(Range.open(3, 7) -> "1") //Map((3..7) -> 1)
    rangeMap += Range.closed(9, 10) -> "2"              // Map((3..7) -> 1, [9..10] -> 2)
    rangeMap += Range.closed(12, 16) -> "3"             // Map((3..7) -> 1, [9..10] -> 2, [12..16] -> 3)
    
    val sub = rangeMap.subRangeMap(Range.closed(5, 11)) // Map([5..7) -> 1, [9..10] -> 2)
    sub.put(Range.closed(7, 9), "4")                    // sub = Map([5..7) -> 1, [7..9] -> 4, (9..10] -> 2)
    
    // rangeMap = Map((3..7) -> 1, [7..9] -> 4, (9..10] -> 2, [12..16] -> 3)
    Annotations
    @Beta()
    Since

    0.9

  8. trait RangeSet[C, O <: Ordering[C]] extends RangeSetLike[C, O, RangeSet[C, O]]

    A base trait for all RangeSet, mutable as well as immutable

    A base trait for all RangeSet, mutable as well as immutable

    A range set is a set comprising zero or more nonempty, disconnected ranges of type C for which an Ordering[C] is defined.

    Note that the behavior of Range#isEmpty() and Range#isConnected(Range) may not be as expected on discrete ranges. See the Scaladoc of those methods for details.

    For a Set whose contents are specified by a Range, see ContiguousSet.

    Usage example:

    import org.feijoas.mango.common.collect.Bound._
    import org.feijoas.mango.common.collect._
    import math.Ordering.Int
    
    // immutable range set:
    val rangeSet = RangeSet(Range.open(1, 3), Range.closed(4, 9)) // {(1,3), [4,9]}
    val subSet = rangeSet.subRangeSet(Range.closed(2, 6))         // union view {[2,3), [4,6]}
    
    // mutable range set:
    val mutableRangeSet = mutable.RangeSet(Range.closed(1, 10))   // {[1, 10]}
    mutableRangeSet += Range.closedOpen(11, 15)                   // disconnected range: {[1, 10], [11, 15)}
    mutableRangeSet += Range.closedOpen(15, 20)                   // connected range; {[1, 10], [11, 20)}
    mutableRangeSet += Range.openClosed(0, 0)                     // empty range; {[1, 10], [11, 20)}
    mutableRangeSet -= Range.open(5, 10)                          // splits [1, 10]; {[1, 5], [10, 10], [11, 20)}
    Annotations
    @Beta()
    Since

    0.8

  9. trait RangeSetFactory[Repr[C, O <: Ordering[C]] <: RangeSet[C, O] with RangeSetLike[C, O, Repr[C, O]]] extends AnyRef

    Factory for RangeSet implementations

    Factory for RangeSet implementations

    Annotations
    @Beta()
    Since

    0.8

  10. trait RangeSetLike[C, O <: Ordering[C], +Repr <: RangeSetLike[C, O, Repr] with RangeSet[C, O]] extends HasNewBuilder[Range[C, O], Repr]

    Implementation trait for RangeSet

    Implementation trait for RangeSet

    A range set is a set comprising zero or more nonempty, disconnected ranges of type C for which an Ordering[C] is defined.

    Note that the behavior of Range#isEmpty() and Range#isConnected(Range) may not be as expected on discrete ranges. See the Scaladoc of those methods for details.

    For a Set whose contents are specified by a Range, see ContiguousSet.

    Usage example:

    import org.feijoas.mango.common.collect.Bound._
    import org.feijoas.mango.common.collect._
    import math.Ordering.Int
    
    // immutable range set:
    val rangeSet = RangeSet(Range.open(1, 3), Range.closed(4, 9)) // {(1,3), [4,9]}
    val subSet = rangeSet.subRangeSet(Range.closed(2, 6))         // union view {[2,3), [4,6]}
    
    // mutable range set:
    val mutableRangeSet = mutable.RangeSet(Range.closed(1, 10))   // {[1, 10]}
    mutableRangeSet += Range.closedOpen(11, 15)                   // disconnected range: {[1, 10], [11, 15)}
    mutableRangeSet += Range.closedOpen(15, 20)                   // connected range; {[1, 10], [11, 20)}
    mutableRangeSet += Range.openClosed(0, 0)                     // empty range; {[1, 10], [11, 20)}
    mutableRangeSet -= Range.open(5, 10)                          // splits [1, 10]; {[1, 5], [10, 10], [11, 20)}
    Annotations
    @Beta()
    Since

    0.8

Value Members

  1. object Bound extends Serializable

    A Bound describes the to bounds of a Range.

    A Bound describes the to bounds of a Range. For example the range (4,7] has the two (finite) bounds "open" 4 and 7 "closed". A bound is either a FiniteBound[T] with a value of type T and a BoundType or an InifinteBound. An InifinteBound is used to describe unbounded ranges as for example [a..+∞)

    Since

    0.8

  2. object BoundType extends Serializable

    Indicates whether an endpoint of some range is contained in the range itself ("closed") or not ("open").

    Indicates whether an endpoint of some range is contained in the range itself ("closed") or not ("open"). If a range is unbounded on a side, it is neither open nor closed on that side; the bound simply does not exist.

    Since

    0.8 (copied from Guava-libraries)

  3. object DiscreteDomain

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

    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:

    • [a..a] : a singleton range
    • [a..a); (a..a] : empty ranges; also valid
    • (a..a) : invalid; an exception will be thrown
    Warnings
    • Use immutable value types only, if at all possible. If you must use a mutable type, do not allow the endpoint instances to mutate after the range is created!
    • Your value type's comparison method should be consistent with equals if at all possible. Otherwise, be aware that concepts used throughout this documentation such as "equal", "same", "unique" and so on actually refer to whether Ordering#compare returns zero, not whether equals returns true.
    Other notes
    • Instances of this type are obtained using the static factory methods in this class.
    • Ranges are convex: whenever two values are contained, all values in between them must also be contained. More formally, for any c1 <= c2 <= c3 of type C, r.contains(c1) && r.contains(c3) implies r.contains(c2)). This means that a Range[Int,Ordering[Int] can never be used to represent, say, "all prime numbers from 1 to 100."
    • When evaluated as a predicate, a range yields the same result as invoking #contains.
    • Terminology note: a range a is said to be the maximal range having property P if, for all ranges b also having property P, a.encloses(b). Likewise, a is minimal when b.encloses(a) for all b having property P. See, for example, the definition of intersection.
    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)

  5. object RangeMap extends RangeMapFactory[RangeMap]

    Factory for immutable RangeMap

  6. object RangeSet extends RangeSetFactory[RangeSet]

    Factory for immutable RangeSet

  7. package immutable

  8. package mutable

Inherited from AnyRef

Inherited from Any

Ungrouped