forked from scala/scala-java8-compat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStepsLikeIndexed.scala
62 lines (54 loc) · 2.27 KB
/
StepsLikeIndexed.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
59
60
61
62
/*
* 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.compat.java8.collectionImpl._
import Stepper._
/** Abstracts all the generic operations of stepping over an indexable collection */
private[java8] abstract class AbstractStepsLikeIndexed[Sub >: Null, Semi <: Sub](protected var i0: Int, protected var iN: Int)
extends EfficientSubstep {
def semiclone(half: Int): Semi
def characteristics(): Int = Ordered + Sized + SubSized
def estimateSize(): Long = iN - i0
def hasNext(): Boolean = i0 < iN
def substep(): Sub = {
if (iN-1 > i0) {
val half = (i0+iN) >>> 1
val ans = semiclone(half)
i0 = half
ans
}
else null
}
}
/** Abstracts the operation of stepping over a generic indexable collection */
private[java8] abstract class StepsLikeIndexed[A, STA >: Null <: StepsLikeIndexed[A, _]](_i0: Int, _iN: Int)
extends AbstractStepsLikeIndexed[AnyStepper[A], STA](_i0, _iN)
with AnyStepper[A]
{}
/** Abstracts the operation of stepping over an indexable collection of Doubles */
private[java8] abstract class StepsDoubleLikeIndexed[STD >: Null <: StepsDoubleLikeIndexed[_]](_i0: Int, _iN: Int)
extends AbstractStepsLikeIndexed[DoubleStepper, STD](_i0, _iN)
with DoubleStepper
with java.util.Spliterator.OfDouble // Compiler wants this for mixin forwarder
{}
/** Abstracts the operation of stepping over an indexable collection of Ints */
private[java8] abstract class StepsIntLikeIndexed[STI >: Null <: StepsIntLikeIndexed[_]](_i0: Int, _iN: Int)
extends AbstractStepsLikeIndexed[IntStepper, STI](_i0, _iN)
with IntStepper
with java.util.Spliterator.OfInt // Compiler wants this for mixin forwarder
{}
/** Abstracts the operation of stepping over an indexable collection of Longs */
private[java8] abstract class StepsLongLikeIndexed[STL >: Null <: StepsLongLikeIndexed[_]](_i0: Int, _iN: Int)
extends AbstractStepsLikeIndexed[LongStepper, STL](_i0, _iN)
with LongStepper
with java.util.Spliterator.OfLong // Compiler wants this for mixin forwarder
{}