diff options
author | Stefan Zeiger <szeiger@novocode.com> | 2016-05-24 17:36:41 +0200 |
---|---|---|
committer | Stefan Zeiger <szeiger@novocode.com> | 2016-05-24 17:36:41 +0200 |
commit | 4d28084e36e8c4072ffcd3cab35b7f22983bea4a (patch) | |
tree | 8e1dc06b4178a6c0d85d3bf53399149dc3b4c10e /src/library/scala/collection/immutable/Range.scala | |
parent | 207e32df30fd733e4dd1cb28fb8cb5c3153c21a6 (diff) | |
parent | 214ea82573624bffb4d0f16f3e5c49f9370ba7a7 (diff) | |
download | scala-4d28084e36e8c4072ffcd3cab35b7f22983bea4a.tar.gz scala-4d28084e36e8c4072ffcd3cab35b7f22983bea4a.tar.bz2 scala-4d28084e36e8c4072ffcd3cab35b7f22983bea4a.zip |
Merge pull request #5175 from som-snytt/issue/9656-range-toString
SI-9656 Distinguish Numeric with step type
Diffstat (limited to 'src/library/scala/collection/immutable/Range.scala')
-rw-r--r-- | src/library/scala/collection/immutable/Range.scala | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/src/library/scala/collection/immutable/Range.scala b/src/library/scala/collection/immutable/Range.scala index 2fe75343d1..47be5b507e 100644 --- a/src/library/scala/collection/immutable/Range.scala +++ b/src/library/scala/collection/immutable/Range.scala @@ -396,22 +396,20 @@ extends scala.collection.AbstractSeq[Int] case _ => super.equals(other) } - /** Note: hashCode can't be overridden without breaking Seq's - * equals contract. - */ - override def toString() = { - val endStr = - if (numRangeElements > Range.MAX_PRINT || (!isEmpty && numRangeElements < 0)) ", ... )" else ")" - take(Range.MAX_PRINT).mkString("Range(", ", ", endStr) + /* Note: hashCode can't be overridden without breaking Seq's equals contract. */ + + override def toString = { + val preposition = if (isInclusive) "to" else "until" + val stepped = if (step == 1) "" else s" by $step" + val prefix = if (isEmpty) "empty " else if (!isExact) "inexact " else "" + s"${prefix}Range $start $preposition $end$stepped" } } /** A companion object for the `Range` class. */ object Range { - private[immutable] val MAX_PRINT = 512 // some arbitrary value - /** Counts the number of range elements. * @pre step != 0 * If the size of the range exceeds Int.MaxValue, the @@ -514,6 +512,7 @@ object Range { // we offer a partially constructed object. class Partial[T, U](private val f: T => U) extends AnyVal { def by(x: T): U = f(x) + override def toString = "Range requires step" } // Illustrating genericity with Int Range, which should have the same behavior |