@Test public void testRemove() { Rnd rnd = new Rnd(); ObjHashSet<CharSequence> set = new ObjHashSet<>(); final int N = 1000; for (int i = 0; i < N; i++) { CharSequence cs = rnd.nextChars(15); Assert.assertTrue(set.add(cs.toString())); } Assert.assertEquals(N, set.size()); rnd.reset(); for (int i = 0; i < N; i++) { CharSequence cs = rnd.nextChars(15); Assert.assertTrue(set.contains(cs.toString())); } Rnd rnd2 = new Rnd(); rnd.reset(); int removed = 0; for (int i = 0; i < N; i++) { CharSequence cs = rnd.nextChars(15); if (rnd2.nextPositiveInt() % 16 == 0) { Assert.assertTrue(set.remove(cs.toString())); removed++; Assert.assertEquals(N - removed, set.size()); } } Assert.assertTrue(removed > 0); rnd2.reset(); rnd.reset(); for (int i = 0; i < N; i++) { CharSequence cs = rnd.nextChars(15); if (rnd2.nextPositiveInt() % 16 == 0) { Assert.assertFalse(set.contains(cs.toString())); } else { Assert.assertTrue(set.contains(cs.toString())); } } Assert.assertFalse(set.add("ZTXZCXTOLXDJDKV")); Assert.assertFalse(set.remove("hello")); }
@Override @SuppressWarnings("unchecked") public boolean remove(Object key) { int keyIndex = keyIndex((T) key); if (keyIndex < 0) { list.remove(keys[-keyIndex - 1]); removeAt(keyIndex); return true; } return false; }
ObjHashSet extends AbstractSet<T> implements Mutable { @Override @SuppressWarnings("unchecked") public boolean remove(Object key) { int keyIndex = keyIndex((T) key); if (keyIndex < 0) { list.remove(keys[-keyIndex - 1]); removeAt(keyIndex); return true; } return false; } }
ObjHashSet extends AbstractSet<T> implements Mutable { @Override @SuppressWarnings("unchecked") public boolean remove(Object key) { int keyIndex = keyIndex((T) key); if (keyIndex < 0) { list.remove(keys[-keyIndex - 1]); removeAt(keyIndex); return true; } return false; } ObjHashSet();  ObjHashSet(int initialCapacity); @SuppressWarnings("unchecked") private  ObjHashSet(int initialCapacity, double loadFactor, double hashFactor); }
ObjHashSet extends AbstractSet<T> implements Mutable { @Override @SuppressWarnings("unchecked") public boolean remove(Object key) { int keyIndex = keyIndex((T) key); if (keyIndex < 0) { list.remove(keys[-keyIndex - 1]); removeAt(keyIndex); return true; } return false; } ObjHashSet();  ObjHashSet(int initialCapacity); @SuppressWarnings("unchecked") private  ObjHashSet(int initialCapacity, double loadFactor, double hashFactor); void addAll(ObjHashSet<? extends T> that); boolean addAt(int index, T key); T get(int index); @Override @NotNull Iterator<T> iterator(); int size(); @SuppressWarnings("unchecked") @Override boolean contains(Object o); boolean add(T key); int keyIndex(T key); @Override @SuppressWarnings("unchecked") boolean remove(Object key); final void clear(); @Override String toString(); }
ObjHashSet extends AbstractSet<T> implements Mutable { @Override @SuppressWarnings("unchecked") public boolean remove(Object key) { int keyIndex = keyIndex((T) key); if (keyIndex < 0) { list.remove(keys[-keyIndex - 1]); removeAt(keyIndex); return true; } return false; } ObjHashSet();  ObjHashSet(int initialCapacity); @SuppressWarnings("unchecked") private  ObjHashSet(int initialCapacity, double loadFactor, double hashFactor); void addAll(ObjHashSet<? extends T> that); boolean addAt(int index, T key); T get(int index); @Override @NotNull Iterator<T> iterator(); int size(); @SuppressWarnings("unchecked") @Override boolean contains(Object o); boolean add(T key); int keyIndex(T key); @Override @SuppressWarnings("unchecked") boolean remove(Object key); final void clear(); @Override String toString();  }