Skip to content

Commit ca49475

Browse files
Renames parameters in ArraySeq and ArrayBuffer
1 parent 6dfcda8 commit ca49475

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

src/library/scala/collection/mutable/ArrayBuffer.scala

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import java.lang.{IndexOutOfBoundsException, IllegalArgumentException}
2626
* @define mayNotTerminateInf
2727
* @define willNotTerminateInf
2828
*/
29-
class ArrayBuffer[A] private (initElems: Array[AnyRef], initSize: Int)
29+
class ArrayBuffer[A] private (initialElements: Array[AnyRef], initialSize: Int)
3030
extends AbstractBuffer[A]
3131
with IndexedSeq[A]
3232
with IndexedSeqOps[A, ArrayBuffer, ArrayBuffer[A]]
@@ -35,10 +35,10 @@ class ArrayBuffer[A] private (initElems: Array[AnyRef], initSize: Int)
3535

3636
def this() = this(new Array[AnyRef](16), 0)
3737

38-
def this(initSize: Int) = this(new Array[AnyRef](initSize), 0)
38+
def this(initialSize: Int) = this(new Array[AnyRef](initialSize), 0)
3939

40-
protected var array: Array[AnyRef] = initElems
41-
protected var size0 = initSize
40+
protected var array: Array[AnyRef] = initialElements
41+
protected var size0 = initialSize
4242

4343
/** Ensure that the internal array has at least `n` cells. */
4444
protected def ensureSize(n: Int): Unit =
@@ -63,9 +63,9 @@ class ArrayBuffer[A] private (initElems: Array[AnyRef], initSize: Int)
6363
array(n).asInstanceOf[A]
6464
}
6565

66-
def update(n: Int, elem: A): Unit = {
67-
checkWithinBounds(n, n + 1)
68-
array(n) = elem.asInstanceOf[AnyRef]
66+
def update(@deprecatedName('n, "2.13.0") index: Int, elem: A): Unit = {
67+
checkWithinBounds(index, index + 1)
68+
array(index) = elem.asInstanceOf[AnyRef]
6969
}
7070

7171
def length = size0
@@ -96,55 +96,55 @@ class ArrayBuffer[A] private (initElems: Array[AnyRef], initSize: Int)
9696
this
9797
}
9898

99-
def insert(idx: Int, elem: A): Unit = {
100-
checkWithinBounds(idx, idx)
99+
def insert(@deprecatedName('n, "2.13.0") index: Int, elem: A): Unit = {
100+
checkWithinBounds(index, index)
101101
ensureSize(size0 + 1)
102-
Array.copy(array, idx, array, idx + 1, size0 - idx)
102+
Array.copy(array, index, array, index + 1, size0 - index)
103103
size0 += 1
104-
this(idx) = elem
104+
this(index) = elem
105105
}
106106

107107
def prepend(elem: A): this.type = {
108108
insert(0, elem)
109109
this
110110
}
111111

112-
def insertAll(idx: Int, elems: IterableOnce[A]): Unit = {
113-
checkWithinBounds(idx, idx)
112+
def insertAll(@deprecatedName('n, "2.13.0") index: Int, elems: IterableOnce[A]): Unit = {
113+
checkWithinBounds(index, index)
114114
elems match {
115115
case elems: collection.Iterable[A] =>
116116
val elemsLength = elems.size
117117
ensureSize(length + elemsLength)
118-
Array.copy(array, idx, array, idx + elemsLength, size0 - idx)
118+
Array.copy(array, index, array, index + elemsLength, size0 - index)
119119
size0 = size0 + elemsLength
120120
elems match {
121121
case elems: ArrayBuffer[_] =>
122-
Array.copy(elems.array, 0, array, idx, elemsLength)
122+
Array.copy(elems.array, 0, array, index, elemsLength)
123123
case _ =>
124124
var i = 0
125125
val it = elems.iterator
126126
while (i < elemsLength) {
127-
this(idx + i) = it.next()
127+
this(index + i) = it.next()
128128
i += 1
129129
}
130130
}
131131
case _ =>
132-
insertAll(idx, ArrayBuffer.from(elems))
132+
insertAll(index, ArrayBuffer.from(elems))
133133
}
134134
}
135135

136-
def remove(idx: Int): A = {
137-
checkWithinBounds(idx, idx + 1)
138-
val res = this(idx)
139-
Array.copy(array, idx + 1, array, idx, size0 - (idx + 1))
136+
def remove(@deprecatedName('n, "2.13.0") index: Int): A = {
137+
checkWithinBounds(index, index + 1)
138+
val res = this(index)
139+
Array.copy(array, index + 1, array, index, size0 - (index + 1))
140140
reduceToSize(size0 - 1)
141141
res
142142
}
143143

144-
def remove(idx: Int, count: Int): Unit =
144+
def remove(@deprecatedName('n, "2.13.0") index: Int, count: Int): Unit =
145145
if (count > 0) {
146-
checkWithinBounds(idx, idx + count)
147-
Array.copy(array, idx + count, array, idx, size0 - (idx + count))
146+
checkWithinBounds(index, index + count)
147+
Array.copy(array, index + count, array, index, size0 - (index + count))
148148
reduceToSize(size0 - count)
149149
} else if (count < 0) {
150150
throw new IllegalArgumentException("removing negative number of elements: " + count)

src/library/scala/collection/mutable/ArraySeq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ abstract class ArraySeq[T]
4848
def elemTag: ClassTag[_]
4949

5050
/** Update element at given index */
51-
def update(index: Int, elem: T): Unit
51+
def update(@deprecatedName('idx, "2.13.0") index: Int, elem: T): Unit
5252

5353
/** The underlying array. Its element type does not have to be equal to the element type of this ArraySeq. A primitive
5454
* ArraySeq can be backed by an array of boxed values and a reference ArraySeq can be backed by an array of a supertype

test/junit/scala/collection/mutable/ArrayBufferTest.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -156,39 +156,39 @@ class ArrayBufferTest {
156156

157157
@Test
158158
def testRemoveMany: Unit = {
159-
def testRemoveMany(idx: Int, count: Int, expectation: ArrayBuffer[Int]): Unit = {
159+
def testRemoveMany(index: Int, count: Int, expectation: ArrayBuffer[Int]): Unit = {
160160
val buffer = ArrayBuffer(0, 1, 2)
161-
buffer.remove(idx, count)
161+
buffer.remove(index, count)
162162
assertEquals(expectation, buffer)
163163
}
164164

165-
testRemoveMany(idx = 0, count = 0, expectation = ArrayBuffer(0, 1, 2))
166-
testRemoveMany(idx = 0, count = 1, expectation = ArrayBuffer(1, 2))
167-
testRemoveMany(idx = 0, count = 2, expectation = ArrayBuffer(2))
168-
testRemoveMany(idx = 0, count = 3, expectation = ArrayBuffer())
169-
testRemoveMany(idx = 1, count = 1, expectation = ArrayBuffer(0, 2))
170-
testRemoveMany(idx = 1, count = 2, expectation = ArrayBuffer(0))
171-
testRemoveMany(idx = 2, count = 1, expectation = ArrayBuffer(0, 1))
165+
testRemoveMany(index = 0, count = 0, expectation = ArrayBuffer(0, 1, 2))
166+
testRemoveMany(index = 0, count = 1, expectation = ArrayBuffer(1, 2))
167+
testRemoveMany(index = 0, count = 2, expectation = ArrayBuffer(2))
168+
testRemoveMany(index = 0, count = 3, expectation = ArrayBuffer())
169+
testRemoveMany(index = 1, count = 1, expectation = ArrayBuffer(0, 2))
170+
testRemoveMany(index = 1, count = 2, expectation = ArrayBuffer(0))
171+
testRemoveMany(index = 2, count = 1, expectation = ArrayBuffer(0, 1))
172172
}
173173

174174
@Test(expected = classOf[IndexOutOfBoundsException])
175175
def testRemoveManyWithNegativeIndex: Unit = {
176-
ArrayBuffer(0, 1, 2).remove(idx = -1, count = 1)
176+
ArrayBuffer(0, 1, 2).remove(index = -1, count = 1)
177177
}
178178

179179
@Test(expected = classOf[IndexOutOfBoundsException])
180180
def testRemoveManyWithTooLargeIndex: Unit = {
181-
ArrayBuffer(0).remove(idx = 1, count = 1)
181+
ArrayBuffer(0).remove(index = 1, count = 1)
182182
}
183183

184184
@Test(expected = classOf[IllegalArgumentException])
185185
def testRemoveManyWithNegativeCount: Unit = {
186-
ArrayBuffer(0).remove(idx = 0, count = -1)
186+
ArrayBuffer(0).remove(index = 0, count = -1)
187187
}
188188

189189
@Test(expected = classOf[IndexOutOfBoundsException])
190190
def testRemoveManyWithTooLargeCount: Unit = {
191-
ArrayBuffer(0).remove(idx = 0, count = 100)
191+
ArrayBuffer(0).remove(index = 0, count = 100)
192192
}
193193

194194
@Test

0 commit comments

Comments
 (0)