@Test(expected = NullPointerException.class) public void tryToAddANullItem() { RandomizedBag<Integer> bag = new RandomizedBag<>(); bag.add(null); }
@Override public boolean add(E e) { if (e == null) { throw new NullPointerException(); } elems.add(e); final int idx = rnd.nextInt(elems.size()); elems.set(elems.size() - 1, elems.get(idx)); elems.set(idx, e); return true; }
RandomizedBag extends AbstractCollection<E> implements Serializable { @Override public boolean add(E e) { if (e == null) { throw new NullPointerException(); } elems.add(e); final int idx = rnd.nextInt(elems.size()); elems.set(elems.size() - 1, elems.get(idx)); elems.set(idx, e); return true; } }
RandomizedBag extends AbstractCollection<E> implements Serializable { @Override public boolean add(E e) { if (e == null) { throw new NullPointerException(); } elems.add(e); final int idx = rnd.nextInt(elems.size()); elems.set(elems.size() - 1, elems.get(idx)); elems.set(idx, e); return true; } RandomizedBag();  RandomizedBag(long seed);  RandomizedBag(Collection<E> c);  RandomizedBag(long seed, Collection<E> c); }
RandomizedBag extends AbstractCollection<E> implements Serializable { @Override public boolean add(E e) { if (e == null) { throw new NullPointerException(); } elems.add(e); final int idx = rnd.nextInt(elems.size()); elems.set(elems.size() - 1, elems.get(idx)); elems.set(idx, e); return true; } RandomizedBag();  RandomizedBag(long seed);  RandomizedBag(Collection<E> c);  RandomizedBag(long seed, Collection<E> c); @Override boolean add(E e); E remove(); Iterator<E> iterator(); @Override int size(); }
RandomizedBag extends AbstractCollection<E> implements Serializable { @Override public boolean add(E e) { if (e == null) { throw new NullPointerException(); } elems.add(e); final int idx = rnd.nextInt(elems.size()); elems.set(elems.size() - 1, elems.get(idx)); elems.set(idx, e); return true; } RandomizedBag();  RandomizedBag(long seed);  RandomizedBag(Collection<E> c);  RandomizedBag(long seed, Collection<E> c); @Override boolean add(E e); E remove(); Iterator<E> iterator(); @Override int size();  }