@@ -72,17 +72,6 @@ extends AbstractSeq[T]
72
72
else
73
73
super .toArray[U ]
74
74
}
75
- override def slice (from : Int , until : Int ): WrappedArray [T ] = {
76
- val start = if (from < 0 ) 0 else from
77
- if (until <= start || start >= repr.length)
78
- return emptyImpl
79
- val end = if (until > length) length else until
80
- sliceImpl(start, end)
81
- }
82
- // retain existing functionallity for existing implementations outside this file
83
- protected def emptyImpl : WrappedArray [T ] = newBuilder.result()
84
- // retain existing functionallity for existing implementations outside this file
85
- protected def sliceImpl (from : Int , until : Int ): WrappedArray [T ] = super .slice(from, until)
86
75
87
76
override def stringPrefix = " WrappedArray"
88
77
@@ -93,7 +82,20 @@ extends AbstractSeq[T]
93
82
*/
94
83
override protected [this ] def newBuilder : Builder [T , WrappedArray [T ]] =
95
84
new WrappedArrayBuilder [T ](elemTag)
85
+ }
86
+
87
+ private [mutable] abstract class WrappedArrayImpl [T ] extends WrappedArray [T ] {
88
+ override def slice (from : Int , until : Int ): WrappedArray [T ] = {
89
+ val start = if (from < 0 ) 0 else from
90
+ if (until <= start || start >= repr.length)
91
+ return emptyImpl
92
+ val end = if (until > length) length else until
93
+ sliceImpl(start, end)
94
+ }
95
+
96
+ protected def emptyImpl : WrappedArray [T ]
96
97
98
+ protected def sliceImpl (from : Int , until : Int ): WrappedArray [T ]
97
99
}
98
100
99
101
/** A companion object used to create instances of `WrappedArray`.
@@ -143,7 +145,7 @@ object WrappedArray {
143
145
private val emptyWrappedChar = new ofChar(new Array [Char ](0 ))
144
146
private val emptyWrappedBoolean = new ofBoolean(new Array [Boolean ](0 ))
145
147
146
- final class ofRef [T <: AnyRef ](val array : Array [T ]) extends WrappedArray [T ] with Serializable {
148
+ final class ofRef [T <: AnyRef ](val array : Array [T ]) extends WrappedArrayImpl [T ] with Serializable {
147
149
lazy val elemTag = ClassTag [T ](arrayElementClass(array.getClass))
148
150
def length : Int = array.length
149
151
def apply (index : Int ): T = array(index).asInstanceOf [T ]
@@ -152,7 +154,7 @@ object WrappedArray {
152
154
protected override def sliceImpl (from : Int , until : Int ) = new ofRef[T ](util.Arrays .copyOfRange[T ](array, from, until))
153
155
}
154
156
155
- final class ofByte (val array : Array [Byte ]) extends WrappedArray [Byte ] with Serializable {
157
+ final class ofByte (val array : Array [Byte ]) extends WrappedArrayImpl [Byte ] with Serializable {
156
158
def elemTag = ClassTag .Byte
157
159
def length : Int = array.length
158
160
def apply (index : Int ): Byte = array(index)
@@ -161,7 +163,7 @@ object WrappedArray {
161
163
protected override def sliceImpl (from : Int , until : Int ) = new ofByte(util.Arrays .copyOfRange(array, from, until))
162
164
}
163
165
164
- final class ofShort (val array : Array [Short ]) extends WrappedArray [Short ] with Serializable {
166
+ final class ofShort (val array : Array [Short ]) extends WrappedArrayImpl [Short ] with Serializable {
165
167
def elemTag = ClassTag .Short
166
168
def length : Int = array.length
167
169
def apply (index : Int ): Short = array(index)
@@ -170,7 +172,7 @@ object WrappedArray {
170
172
protected override def sliceImpl (from : Int , until : Int ) = new ofShort(util.Arrays .copyOfRange(array, from, until))
171
173
}
172
174
173
- final class ofChar (val array : Array [Char ]) extends WrappedArray [Char ] with Serializable {
175
+ final class ofChar (val array : Array [Char ]) extends WrappedArrayImpl [Char ] with Serializable {
174
176
def elemTag = ClassTag .Char
175
177
def length : Int = array.length
176
178
def apply (index : Int ): Char = array(index)
@@ -179,7 +181,7 @@ object WrappedArray {
179
181
protected override def sliceImpl (from : Int , until : Int ) = new ofChar(util.Arrays .copyOfRange(array, from, until))
180
182
}
181
183
182
- final class ofInt (val array : Array [Int ]) extends WrappedArray [Int ] with Serializable {
184
+ final class ofInt (val array : Array [Int ]) extends WrappedArrayImpl [Int ] with Serializable {
183
185
def elemTag = ClassTag .Int
184
186
def length : Int = array.length
185
187
def apply (index : Int ): Int = array(index)
@@ -188,7 +190,7 @@ object WrappedArray {
188
190
protected override def sliceImpl (from : Int , until : Int ) = new ofInt(util.Arrays .copyOfRange(array, from, until))
189
191
}
190
192
191
- final class ofLong (val array : Array [Long ]) extends WrappedArray [Long ] with Serializable {
193
+ final class ofLong (val array : Array [Long ]) extends WrappedArrayImpl [Long ] with Serializable {
192
194
def elemTag = ClassTag .Long
193
195
def length : Int = array.length
194
196
def apply (index : Int ): Long = array(index)
@@ -197,7 +199,7 @@ object WrappedArray {
197
199
protected override def sliceImpl (from : Int , until : Int ) = new ofLong(util.Arrays .copyOfRange(array, from, until))
198
200
}
199
201
200
- final class ofFloat (val array : Array [Float ]) extends WrappedArray [Float ] with Serializable {
202
+ final class ofFloat (val array : Array [Float ]) extends WrappedArrayImpl [Float ] with Serializable {
201
203
def elemTag = ClassTag .Float
202
204
def length : Int = array.length
203
205
def apply (index : Int ): Float = array(index)
@@ -206,7 +208,7 @@ object WrappedArray {
206
208
protected override def sliceImpl (from : Int , until : Int ) = new ofFloat(util.Arrays .copyOfRange(array, from, until))
207
209
}
208
210
209
- final class ofDouble (val array : Array [Double ]) extends WrappedArray [Double ] with Serializable {
211
+ final class ofDouble (val array : Array [Double ]) extends WrappedArrayImpl [Double ] with Serializable {
210
212
def elemTag = ClassTag .Double
211
213
def length : Int = array.length
212
214
def apply (index : Int ): Double = array(index)
@@ -215,7 +217,7 @@ object WrappedArray {
215
217
protected override def sliceImpl (from : Int , until : Int ) = new ofDouble(util.Arrays .copyOfRange(array, from, until))
216
218
}
217
219
218
- final class ofBoolean (val array : Array [Boolean ]) extends WrappedArray [Boolean ] with Serializable {
220
+ final class ofBoolean (val array : Array [Boolean ]) extends WrappedArrayImpl [Boolean ] with Serializable {
219
221
def elemTag = ClassTag .Boolean
220
222
def length : Int = array.length
221
223
def apply (index : Int ): Boolean = array(index)
@@ -224,7 +226,7 @@ object WrappedArray {
224
226
protected override def sliceImpl (from : Int , until : Int ) = new ofBoolean(util.Arrays .copyOfRange(array, from, until))
225
227
}
226
228
227
- final class ofUnit (val array : Array [Unit ]) extends WrappedArray [Unit ] with Serializable {
229
+ final class ofUnit (val array : Array [Unit ]) extends WrappedArrayImpl [Unit ] with Serializable {
228
230
def elemTag = ClassTag .Unit
229
231
def length : Int = array.length
230
232
def apply (index : Int ): Unit = array(index)
0 commit comments