SmartList extends AbstractList<E> implements RandomAccess { @NotNull @Override public <T> T[] toArray(@NotNull T[] a) { int aLength = a.length; if (mySize == 1) { if (aLength != 0) { a[0] = (T)myElem; } else { T[] r = (T[])Array.newInstance(a.getClass().getComponentType(), 1); r[0] = (T)myElem; return r; } } else if (aLength < mySize) { return (T[])Arrays.copyOf((E[])myElem, mySize, a.getClass()); } else if (mySize != 0) { System.arraycopy(myElem, 0, a, 0, mySize); } if (aLength > mySize) { a[mySize] = null; } return a; } SmartList();  SmartList(E element);  SmartList(@NotNull Collection<? extends E> elements);  SmartList(@NotNull E... elements); @Override E get(int index); @Override boolean add(E e); @Override void add(int index, E e); @Override int size(); @Override void clear(); @Override E set(final int index, final E element); @Override E remove(final int index); @NotNull @Override Iterator<E> iterator(); void sort(Comparator<? super E> comparator); int getModificationCount(); @NotNull @Override T[] toArray(@NotNull T[] a); void trimToSize();  }
@Test public void testEmptyToArray() { SmartList<Integer> l = new SmartList<Integer>(); assertArrayEquals(l.toArray(), new Integer[]{}); assertArrayEquals(l.toArray(new Integer[]{}), new Integer[]{}); }
@Test public void testSingleToArray() { SmartList<String> l = new SmartList<String>("foo"); assertArrayEquals(l.toArray(ArrayUtilRt.EMPTY_STRING_ARRAY), new String[]{"foo"}); }
@Test public void testToArray() { SmartList<Integer> l = new SmartList<Integer>(0, 1); assertArrayEquals(l.toArray(), new Object[]{0, 1}); assertArrayEquals(l.toArray(), new Integer[]{0, 1}); assertArrayEquals(l.toArray(new Integer[0]), new Integer[]{0, 1}); assertArrayEquals(l.toArray(new Integer[4]), new Integer[]{0, 1, null, null}); l.remove(1); assertArrayEquals(l.toArray(new Integer[4]), new Integer[]{0, null, null, null}); assertArrayEquals(l.toArray(), new Integer[]{0}); }