use fromIndex and toIndex for remove instead of from and length
The new API is consistent with the internal API of ArrayList.
This commit is contained in:
@@ -295,25 +295,31 @@ public class IntListTest {
|
||||
|
||||
list.addAll(ints);
|
||||
|
||||
list.remove(2, 0);
|
||||
// remove nothing
|
||||
list.remove(2, 2);
|
||||
Assert.assertArrayEquals(ints, list.toArray());
|
||||
|
||||
list.remove(9, 1);
|
||||
// remove the last element
|
||||
list.remove(9, 10);
|
||||
final int[] expectedA = removeElements(ints, 9);
|
||||
Assert.assertArrayEquals(expectedA, list.toArray());
|
||||
|
||||
// remove the first element
|
||||
list.remove(0, 1);
|
||||
final int[] expectedB = removeElements(expectedA, 0);
|
||||
Assert.assertArrayEquals(expectedB, list.toArray());
|
||||
|
||||
list.remove(7, 1);
|
||||
final int[] expectedC = removeElements(expectedB, 7);
|
||||
// remove single element in the middle
|
||||
list.remove(3, 4);
|
||||
final int[] expectedC = removeElements(expectedB, 3);
|
||||
Assert.assertArrayEquals(expectedC, list.toArray());
|
||||
|
||||
list.remove(3, 3);
|
||||
final int[] expectedD = removeElements(expectedC, 3, 4, 5);
|
||||
// remove several elements in the middle
|
||||
list.remove(2, 5);
|
||||
final int[] expectedD = removeElements(expectedC, 2, 3, 4);
|
||||
Assert.assertArrayEquals(expectedD, list.toArray());
|
||||
|
||||
// remove all elements
|
||||
list.remove(0, 4);
|
||||
final int[] expectedE = removeElements(expectedD, 0, 1, 2, 3);
|
||||
Assert.assertArrayEquals(expectedE, list.toArray());
|
||||
@@ -332,19 +338,19 @@ public class IntListTest {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
list.remove(1, -1);
|
||||
list.remove(1, 0);
|
||||
Assert.fail();
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
list.remove(3, 2);
|
||||
list.remove(3, 5);
|
||||
Assert.fail();
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
list.remove(4, 1);
|
||||
list.remove(4, 5);
|
||||
Assert.fail();
|
||||
} catch (final IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
@@ -387,7 +393,7 @@ public class IntListTest {
|
||||
Assert.assertEquals(a.hashCode(), b.hashCode());
|
||||
|
||||
// change one value
|
||||
a.remove(2, 1);
|
||||
a.remove(2, 3);
|
||||
a.insert(2, 99);
|
||||
Assert.assertFalse(a.equals(b));
|
||||
Assert.assertNotEquals(a.hashCode(), b.hashCode());
|
||||
@@ -404,9 +410,9 @@ public class IntListTest {
|
||||
Assert.assertArrayEquals(expectedE, list.toArray());
|
||||
}
|
||||
|
||||
private int[] removeElements(final int[] data, final int... removedElements) {
|
||||
final int[] result = new int[data.length - removedElements.length];
|
||||
final List<Integer> blacklist = Arrays.stream(removedElements).boxed().collect(Collectors.toList());
|
||||
private int[] removeElements(final int[] data, final int... removedIndices) {
|
||||
final int[] result = new int[data.length - removedIndices.length];
|
||||
final List<Integer> blacklist = Arrays.stream(removedIndices).boxed().collect(Collectors.toList());
|
||||
|
||||
int j = 0;
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user