summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/immutable/NumericRange.scala
diff options
context:
space:
mode:
authorSteve Robinson <steve.robinson290391@gmail.com>2016-02-27 09:13:45 -0800
committerSom Snytt <som.snytt@gmail.com>2016-05-19 10:54:33 -0700
commit214ea82573624bffb4d0f16f3e5c49f9370ba7a7 (patch)
tree906b6e646bceab8f43ab4812bcee48181149b3e3 /src/library/scala/collection/immutable/NumericRange.scala
parent4a7f82c9047d04d79aa0fe4c0f8dc249ba221f76 (diff)
downloadscala-214ea82573624bffb4d0f16f3e5c49f9370ba7a7.tar.gz
scala-214ea82573624bffb4d0f16f3e5c49f9370ba7a7.tar.bz2
scala-214ea82573624bffb4d0f16f3e5c49f9370ba7a7.zip
SI-9656 Range.toString distinguishes Numeric step
For Range and NumericRange, toString will indicate the step if it is not 1. Additionally, indicate empty ranges and ranges which are not "exact". For a "mapped" range, used by `Range.Double`, toString includes the underlying range and the simple type of the step (to distinguish Double from BigDecimal).
Diffstat (limited to 'src/library/scala/collection/immutable/NumericRange.scala')
-rw-r--r--src/library/scala/collection/immutable/NumericRange.scala14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/library/scala/collection/immutable/NumericRange.scala b/src/library/scala/collection/immutable/NumericRange.scala
index c8d7519254..fdf50960a3 100644
--- a/src/library/scala/collection/immutable/NumericRange.scala
+++ b/src/library/scala/collection/immutable/NumericRange.scala
@@ -161,6 +161,12 @@ extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
override def isEmpty = underlyingRange.isEmpty
override def apply(idx: Int): A = fm(underlyingRange(idx))
override def containsTyped(el: A) = underlyingRange exists (x => fm(x) == el)
+
+ override def toString = {
+ def simpleOf(x: Any): String = x.getClass.getName.split("\\.").last
+ val stepped = simpleOf(underlyingRange.step)
+ s"${super.toString} (using $underlyingRange of $stepped)"
+ }
}
}
@@ -250,9 +256,11 @@ extends AbstractSeq[T] with IndexedSeq[T] with Serializable {
super.equals(other)
}
- override def toString() = {
- val endStr = if (length > Range.MAX_PRINT) ", ... )" else ")"
- take(Range.MAX_PRINT).mkString("NumericRange(", ", ", endStr)
+ override def toString = {
+ val empty = if (isEmpty) "empty " else ""
+ val preposition = if (isInclusive) "to" else "until"
+ val stepped = if (step == 1) "" else s" by $step"
+ s"${empty}NumericRange $start $preposition $end$stepped"
}
}