add clear() method
This commit is contained in:
@@ -18,7 +18,6 @@ public final class IntList implements Serializable, Cloneable {
|
|||||||
// TODO support Iterator
|
// TODO support Iterator
|
||||||
// TODO add mod counts
|
// TODO add mod counts
|
||||||
// TODO support sublists
|
// TODO support sublists
|
||||||
// TODO use sorted flag in indexOf
|
|
||||||
// TODO add lastIndexOf
|
// TODO add lastIndexOf
|
||||||
// TODO remove bounds checks that are handled by java, e.g. negative indices
|
// TODO remove bounds checks that are handled by java, e.g. negative indices
|
||||||
// TODO clear
|
// TODO clear
|
||||||
@@ -518,6 +517,18 @@ public final class IntList implements Serializable, Cloneable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all elements from this list.
|
||||||
|
* <p>
|
||||||
|
* The implementation is equivalent to calling {@code remove(0, size())} and
|
||||||
|
* {@code trim()}.
|
||||||
|
*/
|
||||||
|
public void clear() {
|
||||||
|
data = EMPTY_ARRAY;
|
||||||
|
size = 0;
|
||||||
|
sorted = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a sequential {@link IntStream} with this collection as its source.
|
* Returns a sequential {@link IntStream} with this collection as its source.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -447,6 +447,16 @@ public class IntListTest {
|
|||||||
Assert.assertEquals(0, list.getCapacity());
|
Assert.assertEquals(0, list.getCapacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClear() {
|
||||||
|
final IntList list = IntList.of(2, 0, 1); // unsorted list
|
||||||
|
list.clear();
|
||||||
|
|
||||||
|
Assert.assertEquals(0, list.size());
|
||||||
|
Assert.assertEquals(0, list.getCapacity());
|
||||||
|
Assert.assertTrue(list.isSorted());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHashCodeEquals() {
|
public void testHashCodeEquals() {
|
||||||
final IntList a = new IntList();
|
final IntList a = new IntList();
|
||||||
|
|||||||
Reference in New Issue
Block a user