forked from scala/scala-java8-compat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStepsIterator.scala
58 lines (48 loc) · 2.2 KB
/
StepsIterator.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Scala (https://www.scala-lang.org)
*
* Copyright EPFL and Lightbend, Inc. dba Akka
*
* Licensed under Apache License 2.0
* (http://www.apache.org/licenses/LICENSE-2.0).
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/
package scala.compat.java8.converterImpl
import scala.annotation.switch
import scala.compat.java8.collectionImpl._
/////////////////////////////
// Stepper implementations //
/////////////////////////////
private[java8] class StepsAnyIterator[A](_underlying: Iterator[A])
extends StepsLikeIterator[A, StepsAnyIterator[A]](_underlying) {
def semiclone() = new StepsAnyIterator(null)
def next() = if (proxied ne null) proxied.nextStep else underlying.next
}
private[java8] class StepsDoubleIterator(_underlying: Iterator[Double])
extends StepsDoubleLikeIterator[StepsDoubleIterator](_underlying) {
def semiclone() = new StepsDoubleIterator(null)
def nextDouble() = if (proxied ne null) proxied.nextStep else underlying.next
}
private[java8] class StepsIntIterator(_underlying: Iterator[Int])
extends StepsIntLikeIterator[StepsIntIterator](_underlying) {
def semiclone() = new StepsIntIterator(null)
def nextInt() = if (proxied ne null) proxied.nextStep else underlying.next
}
private[java8] class StepsLongIterator(_underlying: Iterator[Long])
extends StepsLongLikeIterator[StepsLongIterator](_underlying) {
def semiclone() = new StepsLongIterator(null)
def nextLong() = if (proxied ne null) proxied.nextStep else underlying.next
}
//////////////////////////
// Value class adapters //
//////////////////////////
final class RichIteratorCanStep[T](private val underlying: Iterator[T]) extends AnyVal with MakesStepper[T, Any] {
def stepper[S <: Stepper[_]](implicit ss: StepperShape[T, S]) = ((ss.shape: @switch) match {
case StepperShape.IntValue => new StepsIntIterator (underlying.asInstanceOf[Iterator[Int]])
case StepperShape.LongValue => new StepsLongIterator (underlying.asInstanceOf[Iterator[Long]])
case StepperShape.DoubleValue => new StepsDoubleIterator(underlying.asInstanceOf[Iterator[Double]])
case _ => ss.seqUnbox(new StepsAnyIterator[T](underlying))
}).asInstanceOf[S]
}