BitSetIntSet extends GridSerializableCollection<Integer> implements IntSet { @Override public boolean add(Integer integer) { if (integer == null) throw new IllegalArgumentException("Negative or null values are not supported!"); return add((int)integer); } BitSetIntSet();  BitSetIntSet(int initCap);  BitSetIntSet(int initCap, Collection<Integer> coll); @Override int size(); @Override boolean contains(Object o); @Override boolean contains(int element); @NotNull @Override Iterator<Integer> iterator(); @Override boolean add(Integer integer); @Override boolean add(int element); @Override boolean remove(Object o); @Override boolean remove(int element); @Override int[] toIntArray(); @Override boolean containsAll(@NotNull Collection<?> c); @Override boolean addAll(@NotNull Collection<? extends Integer> c); @Override boolean retainAll(@NotNull Collection<?> c); @Override boolean removeAll(@NotNull Collection<?> c); @Override void clear();  }
@Test public void testToArray() { IntSet intSet = new BitSetIntSet(); assertEquals(0, intSet.toArray().length); intSet.add(1); intSet.add(10); intSet.add(10); intSet.add(11); intSet.add(1025); Object[] arr = intSet.toArray(); assertEquals(4, arr.length); assertEquals(1, (int)arr[0]); assertEquals(10, (int)arr[1]); assertEquals(11, (int)arr[2]); assertEquals(1025, (int)arr[3]); Integer[] input = new Integer[1]; Integer[] output = intSet.toArray(input); assertNotSame(input, output); assertEquals(4, arr.length); assertEquals(1, arr[0]); assertEquals(10, arr[1]); assertEquals(11, arr[2]); assertEquals(1025, arr[3]); input = new Integer[6]; output = intSet.toArray(input); assertSame(input, output); assertEquals(6, output.length); assertEquals(1, (int)output[0]); assertEquals(10, (int)output[1]); assertEquals(11, (int)output[2]); assertEquals(1025, (int)output[3]); assertNull(output[4]); assertNull(output[5]); }