Skip to content

Commit 8ca53f0

Browse files
committed
Use a self-type on StepperLike instead of typedPrecisely
1 parent d3606b7 commit 8ca53f0

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

src/main/scala/scala/compat/java8/collectionImpl/Stepper.scala

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ trait EfficientSubstep {}
5353

5454
/** Provides functionality for Stepper while keeping track of a more precise type of the collection.
5555
*/
56-
trait StepperLike[@specialized(Double, Int, Long) A, +CC] { self =>
56+
trait StepperLike[@specialized(Double, Int, Long) A, +CC] { self: CC =>
5757
/** Characteristics are bit flags that indicate runtime characteristics of this Stepper.
5858
*
5959
* - `Distinct` means that no duplicates exist
@@ -90,9 +90,6 @@ trait StepperLike[@specialized(Double, Int, Long) A, +CC] { self =>
9090
*/
9191
def substep(): CC
9292

93-
/** Returns the precise underlying type of this `Stepper`. */
94-
def typedPrecisely: CC
95-
9693
/** Warns this `Stepper` that it is likely to be used in a parallel context (used for efficiency only) */
9794
def anticipateParallelism: this.type = this
9895

@@ -236,8 +233,7 @@ trait AnyStepper[A] extends Stepper[A] with java.util.Iterator[A] with Spliterat
236233
def nextStep = next
237234
def tryAdvance(c: java.util.function.Consumer[_ >: A]): Boolean = if (hasNext) { c.accept(next); true } else false
238235
def tryStep(f: A => Unit): Boolean = if (hasNext) { f(next); true } else false
239-
def trySplit() = substep match { case null => null; case x => x.typedPrecisely }
240-
final def typedPrecisely: AnyStepper[A] = this
236+
def trySplit() = substep
241237
override def spliterator: Spliterator[A] = this
242238
def seqStream: java.util.stream.Stream[A] = java.util.stream.StreamSupport.stream(this, false)
243239
def parStream: java.util.stream.Stream[A] = java.util.stream.StreamSupport.stream(this, true)
@@ -253,8 +249,7 @@ trait DoubleStepper extends Stepper[Double] with java.util.PrimitiveIterator.OfD
253249
def tryAdvance(c: java.util.function.Consumer[_ >: java.lang.Double]): Boolean = if (hasNext) { c.accept(java.lang.Double.valueOf(nextDouble)); true } else false
254250
def tryAdvance(c: java.util.function.DoubleConsumer): Boolean = if (hasNext) { c.accept(nextDouble); true } else false
255251
def tryStep(f: Double => Unit): Boolean = if (hasNext) { f(nextDouble); true } else false
256-
def trySplit() = substep match { case null => null; case x => x.typedPrecisely }
257-
final def typedPrecisely: DoubleStepper = this
252+
def trySplit() = substep
258253
override def spliterator: Spliterator[Double] = this.asInstanceOf[Spliterator[Double]] // Scala and Java disagree about whether it's java.lang.Double or double
259254
def seqStream: java.util.stream.DoubleStream = java.util.stream.StreamSupport.doubleStream(this, false)
260255
def parStream: java.util.stream.DoubleStream = java.util.stream.StreamSupport.doubleStream(this, true)
@@ -270,8 +265,7 @@ trait IntStepper extends Stepper[Int] with java.util.PrimitiveIterator.OfInt wit
270265
def tryAdvance(c: java.util.function.Consumer[_ >: java.lang.Integer]): Boolean = if (hasNext) { c.accept(java.lang.Integer.valueOf(nextInt)); true } else false
271266
def tryAdvance(c: java.util.function.IntConsumer): Boolean = if (hasNext) { c.accept(nextInt); true } else false
272267
def tryStep(f: Int => Unit): Boolean = if (hasNext) { f(nextInt); true } else false
273-
def trySplit() = substep match { case null => null; case x => x.typedPrecisely }
274-
final def typedPrecisely = this
268+
def trySplit() = substep
275269
override def spliterator: Spliterator[Int] = this.asInstanceOf[Spliterator[Int]] // Scala and Java disagree about whether it's java.lang.Integer or int
276270
def seqStream: java.util.stream.IntStream = java.util.stream.StreamSupport.intStream(this, false)
277271
def parStream: java.util.stream.IntStream = java.util.stream.StreamSupport.intStream(this, true)
@@ -287,8 +281,7 @@ trait LongStepper extends Stepper[Long] with java.util.PrimitiveIterator.OfLong
287281
def tryAdvance(c: java.util.function.Consumer[_ >: java.lang.Long]): Boolean = if (hasNext) { c.accept(java.lang.Long.valueOf(nextLong)); true } else false
288282
def tryAdvance(c: java.util.function.LongConsumer): Boolean = if (hasNext) { c.accept(nextLong); true } else false
289283
def tryStep(f: Long => Unit): Boolean = if (hasNext) { f(nextLong); true } else false
290-
def trySplit() = substep match { case null => null; case x => x.typedPrecisely }
291-
final def typedPrecisely = this
284+
def trySplit() = substep
292285
override def spliterator: Spliterator[Long] = this.asInstanceOf[Spliterator[Long]] // Scala and Java disagree about whether it's java.lang.Long or long
293286
def seqStream: java.util.stream.LongStream = java.util.stream.StreamSupport.longStream(this, false)
294287
def parStream: java.util.stream.LongStream = java.util.stream.StreamSupport.longStream(this, true)

src/test/scala/scala/compat/java8/StepperTest.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class IncStepperA(private val size0: Long) extends NextStepper[Int] {
2121
i = sub.size0
2222
sub
2323
}
24-
def typedPrecisely = this
2524
}
2625

2726
class IncStepperB(private val size0: Long) extends TryStepper[Int] {
@@ -37,7 +36,6 @@ class IncStepperB(private val size0: Long) extends TryStepper[Int] {
3736
i = sub.size0
3837
sub
3938
}
40-
def typedPrecisely = this
4139
}
4240

4341
class IncSpliterator(private val size0: Long) extends Spliterator.OfInt {
@@ -67,7 +65,6 @@ class MappingStepper[@specialized (Double, Int, Long) A, @specialized(Double, In
6765
if (undersub == null) null
6866
else new MappingStepper(undersub, mapping)
6967
}
70-
def typedPrecisely = this
7168
def spliterator: Spliterator[B] = new MappingSpliterator[A, B](underlying.spliterator, mapping)
7269
}
7370

@@ -211,12 +208,6 @@ class StepperTest {
211208
sources.foreach{ case (i,s) => if (i > 0) subs(0)(s)(x => { assertEquals(x.knownSize, 1L); 0 }, _ + _) }
212209
}
213210

214-
@Test
215-
def consistentPrecision() {
216-
sources.foreach{ case (_,s) => assert(s eq s.typedPrecisely) }
217-
sources.foreach{ case (_,s) => subs(0)(s)(x => { assert(x eq x.typedPrecisely); 0}, _ + _) }
218-
}
219-
220211
@Test
221212
def count_only() {
222213
sources.foreach{ case (i, s) => assertEquals(i, s.count) }

0 commit comments

Comments
 (0)