| 15 | import java.io.ObjectOutputStream; |
| 16 | |
| 17 | public class ArrayList<T> extends AbstractList<T> implements java.io.Serializable, RandomAccess { |
| 18 | private static final int MinimumCapacity = 16; |
| 19 | |
| 20 | private Object[] array; |
| 21 | private int size; |
| 22 | |
| 23 | public ArrayList(int capacity) { |
| 24 | resize(capacity); |
| 25 | } |
| 26 | |
| 27 | public ArrayList() { |
| 28 | this(0); |
| 29 | } |
| 30 | |
| 31 | public ArrayList(Collection<? extends T> source) { |
| 32 | this(source.size()); |
| 33 | addAll(source); |
| 34 | } |
| 35 | |
| 36 | private void grow(int newSize) { |
| 37 | if (array == null || newSize > array.length) { |
| 38 | resize(Math.max(newSize, array == null |
| 39 | ? MinimumCapacity : array.length * 2)); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | private void shrink(int newSize) { |
| 44 | if (array.length / 2 >= MinimumCapacity && newSize <= array.length / 3) { |
| 45 | resize(array.length / 2); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | private void resize(int capacity) { |
| 50 | Object[] newArray = null; |
| 51 | if (capacity != 0) { |
| 52 | if (array != null && array.length == capacity) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | newArray = new Object[capacity]; |
| 57 | if (array != null) { |
| 58 | System.arraycopy(array, 0, newArray, 0, size); |
| 59 | } |
| 60 | } |
| 61 | array = newArray; |
| 62 | } |
| 63 | |
| 64 | private static boolean equal(Object a, Object b) { |
| 65 | return (a == null && b == null) || (a != null && a.equals(b)); |
| 66 | } |
| 67 | |
| 68 | public int size() { |
| 69 | return size; |
| 70 | } |
| 71 | |
| 72 | public void ensureCapacity(int capacity) { |
| 73 | grow(capacity); |
| 74 | } |
nothing calls this directly
no outgoing calls
no test coverage detected