/** * Add {@code i} to the set. Uppercase {@link Integer} version of add, * requires auto-unboxing. When possible use the {@code int} version of * {@link #add(int)} for efficiency. * @throws IllegalArgumentException if i is negative. * @return <tt>true</tt> if i was added to the set. */ public boolean add ( final Integer i ) { return add(i.intValue()); } /**
void work_helper(NonBlockingSetInt nbsi, String thrd, int d) { final int ITERS = 100000; for (int j = 0; j < 10; j++) { //long start = System.nanoTime(); for (int i = d; i < ITERS; i += 2) { nbsi.add(i); } for (int i = d; i < ITERS; i += 2) { nbsi.remove(i); } //double delta_nanos = System.nanoTime()-start; //double delta_secs = delta_nanos/1000000000.0; //double ops = ITERS*2; //System.out.println("Thrd"+thrd+" "+(ops/delta_secs)+" ops/sec size="+nbsi.size()); } } }
prim.add(k);
@Test public void testIteration() { assertTrue(_nbsi.isEmpty()); assertTrue(_nbsi.add(1)); assertTrue(_nbsi.add(2)); StringBuilder buf = new StringBuilder(); for (Integer val : _nbsi) { buf.append(val); } assertThat("found all vals", buf.toString(), anyOf(is("12"), is("21"))); assertThat("toString works", _nbsi.toString(), anyOf(is("[1, 2]"), is("[2, 1]"))); _nbsi.clear(); }
_nbsi.add(i);
assertTrue(_nbsi.add(1)); checkSizes(1); assertTrue(_nbsi.add(2)); checkSizes(2); assertFalse(_nbsi.add(1)); assertFalse(_nbsi.add(2)); checkSizes(2); assertThat(_nbsi.remove(1), is(true)); assertFalse(_nbsi.remove(3)); assertTrue(_nbsi.isEmpty()); assertTrue(_nbsi.add(63)); checkSizes(1); assertTrue(_nbsi.remove(63)); assertTrue(_nbsi.add(10000)); checkSizes(1); assertTrue(_nbsi.add(20000)); checkSizes(2); assertFalse(_nbsi.add(10000)); assertFalse(_nbsi.add(20000)); checkSizes(2); assertThat(_nbsi.remove(10000), is(true));
/** * Add {@code i} to the set. Uppercase {@link Integer} version of add, * requires auto-unboxing. When possible use the {@code int} version of * {@link #add(int)} for efficiency. * @throws IllegalArgumentException if i is negative. * @return <tt>true</tt> if i was added to the set. */ public boolean add ( final Integer i ) { return add(i.intValue()); } /**