/** * Add {@code i} to the set. This is the lower-case '{@code int}' version * of {@link #add} - no autoboxing. Negative values throw * IllegalArgumentException. * @throws IllegalArgumentException if i is negative. * @return <tt>true</tt> if i was added to the set. */ public boolean add( final int i ) { RangeUtil.checkPositiveOrZero(i, "i"); return _nbsi.add(i); } /**
private void initialize( final int initial_sz ) { RangeUtil.checkPositiveOrZero(initial_sz, "initial_sz"); int i; // Convert to next largest power-of-2 for( i=MIN_SIZE_LOG; (1<<i) < initial_sz; i++ ) {/*empty*/} _chm = new CHM(this,new ConcurrentAutoTable(),i); _val_1 = TOMBSTONE; // Always as-if deleted _last_resize_milli = System.currentTimeMillis(); }
private final void initialize( int initial_sz ) { RangeUtil.checkPositiveOrZero(initial_sz, "initial_sz"); int i; // Convert to next largest power-of-2 if( initial_sz > 1024*1024 ) initial_sz = 1024*1024; for( i=MIN_SIZE_LOG; (1<<i) < (initial_sz<<2); i++ ) ; // Double size for K,V pairs, add 1 for CHM and 1 for hashes _kvs = new Object[((1<<i)<<1)+2]; _kvs[0] = new CHM(new ConcurrentAutoTable()); // CHM in slot 0 _kvs[1] = new int[1<<i]; // Matching hash entries _last_resize_milli = System.currentTimeMillis(); } // Version for subclassed readObject calls, to be called after the defaultReadObject
private final void initialize( int initial_sz ) { RangeUtil.checkPositiveOrZero(initial_sz, "initial_sz"); int i; // Convert to next largest power-of-2 if( initial_sz > 1024*1024 ) initial_sz = 1024*1024; for( i=MIN_SIZE_LOG; (1<<i) < (initial_sz<<2); i++ ) ; // Double size for K,V pairs, add 1 for CHM and 1 for hashes _kvs = new Object[((1<<i)<<1)+2]; _kvs[0] = new CHM(new ConcurrentAutoTable()); // CHM in slot 0 _kvs[1] = new int[1<<i]; // Matching hash entries _last_resize_milli = System.currentTimeMillis(); } // Version for subclassed readObject calls, to be called after the defaultReadObject
@Test(expected = IllegalArgumentException.class) public void checkPositiveOrZeroMustFailIfArgumentIsNegative() { RangeUtil.checkPositiveOrZero(-1, "var"); }
@Test public void checkPositiveOrZeroMustPassIfArgumentIsZero() { final int n = 0; final int actual = RangeUtil.checkPositiveOrZero(n, "var"); assertThat(actual, is(equalTo(n))); }
@Test public void checkPositiveOrZeroMustPassIfArgumentIsGreaterThanZero() { final int n = 1; final int actual = RangeUtil.checkPositiveOrZero(n, "var"); assertThat(actual, is(equalTo(n))); }
/** * Add {@code i} to the set. This is the lower-case '{@code int}' version * of {@link #add} - no autoboxing. Negative values throw * IllegalArgumentException. * @throws IllegalArgumentException if i is negative. * @return <tt>true</tt> if i was added to the set. */ public boolean add( final int i ) { RangeUtil.checkPositiveOrZero(i, "i"); return _nbsi.add(i); } /**
private void initialize( final int initial_sz ) { RangeUtil.checkPositiveOrZero(initial_sz, "initial_sz"); int i; // Convert to next largest power-of-2 for( i=MIN_SIZE_LOG; (1<<i) < initial_sz; i++ ) {/*empty*/} _chm = new CHM(this,new ConcurrentAutoTable(),i); _val_1 = TOMBSTONE; // Always as-if deleted _last_resize_milli = System.currentTimeMillis(); }
private final void initialize( int initial_sz ) { RangeUtil.checkPositiveOrZero(initial_sz, "initial_sz"); int i; // Convert to next largest power-of-2 if( initial_sz > 1024*1024 ) initial_sz = 1024*1024; for( i=MIN_SIZE_LOG; (1<<i) < (initial_sz<<2); i++ ) ; // Double size for K,V pairs, add 1 for CHM and 1 for hashes _kvs = new Object[((1<<i)<<1)+2]; _kvs[0] = new CHM(new ConcurrentAutoTable()); // CHM in slot 0 _kvs[1] = new int[1<<i]; // Matching hash entries _last_resize_milli = System.currentTimeMillis(); } // Version for subclassed readObject calls, to be called after the defaultReadObject
private final void initialize( int initial_sz ) { RangeUtil.checkPositiveOrZero(initial_sz, "initial_sz"); int i; // Convert to next largest power-of-2 if( initial_sz > 1024*1024 ) initial_sz = 1024*1024; for( i=MIN_SIZE_LOG; (1<<i) < (initial_sz<<2); i++ ) ; // Double size for K,V pairs, add 1 for CHM and 1 for hashes _kvs = new Object[((1<<i)<<1)+2]; _kvs[0] = new CHM(new ConcurrentAutoTable()); // CHM in slot 0 _kvs[1] = new int[1<<i]; // Matching hash entries _last_resize_milli = System.currentTimeMillis(); } // Version for subclassed readObject calls, to be called after the defaultReadObject