@Test public void testNegativeArraySizeException() { LongBag bag = new LongBag(); for (int i = 0; i < 32; i++) { try { bag.ensureCapacity(-(1 << i)); } catch (NegativeArraySizeException ex) { if (ex.getClass() == NegativeArraySizeException.class) continue; } fail("NegativeArraySizeException expected for capacity " + (-(1 << i))); } }
@Override public void ensureCapacity(int capacity) { if (capacity < 0) throw new NegativeArraySizeException(String.valueOf(capacity)); if (this.buffer.length >= capacity) return; int newCapacity = Bag.nextPowerOfTwo(capacity); long[] newBuffer = new long[newCapacity]; System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); this.buffer = newBuffer; }
LongBag implements AnyBag<LongBag> { @Override public void ensureCapacity(int capacity) { if (capacity < 0) throw new NegativeArraySizeException(String.valueOf(capacity)); if (this.buffer.length >= capacity) return; int newCapacity = Bag.nextPowerOfTwo(capacity); long[] newBuffer = new long[newCapacity]; System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); this.buffer = newBuffer; } }
LongBag implements AnyBag<LongBag> { @Override public void ensureCapacity(int capacity) { if (capacity < 0) throw new NegativeArraySizeException(String.valueOf(capacity)); if (this.buffer.length >= capacity) return; int newCapacity = Bag.nextPowerOfTwo(capacity); long[] newBuffer = new long[newCapacity]; System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); this.buffer = newBuffer; } LongBag(); }
LongBag implements AnyBag<LongBag> { @Override public void ensureCapacity(int capacity) { if (capacity < 0) throw new NegativeArraySizeException(String.valueOf(capacity)); if (this.buffer.length >= capacity) return; int newCapacity = Bag.nextPowerOfTwo(capacity); long[] newBuffer = new long[newCapacity]; System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); this.buffer = newBuffer; } LongBag(); @Override void copyFrom(LongBag from); @Override void copyFrom(LongBag from, boolean clearExceeding); @Override void copyFrom(LongBag from, int length); @Override void copyFrom(LongBag from, int length, boolean clearExceeding); @Override void copyFrom(LongBag from, int fromOffset, int length); @Override void copyFrom(LongBag from, int fromOffset, int length, boolean clearExceeding); @Override void copyPartFrom(LongBag from, int fromOffset, int toOffset, int length); @Override void ensureCapacity(int capacity); long get(int index); void set(int index, long value); @Override void clear(); @Override void clear(Mask mask); }
LongBag implements AnyBag<LongBag> { @Override public void ensureCapacity(int capacity) { if (capacity < 0) throw new NegativeArraySizeException(String.valueOf(capacity)); if (this.buffer.length >= capacity) return; int newCapacity = Bag.nextPowerOfTwo(capacity); long[] newBuffer = new long[newCapacity]; System.arraycopy(buffer, 0, newBuffer, 0, buffer.length); this.buffer = newBuffer; } LongBag(); @Override void copyFrom(LongBag from); @Override void copyFrom(LongBag from, boolean clearExceeding); @Override void copyFrom(LongBag from, int length); @Override void copyFrom(LongBag from, int length, boolean clearExceeding); @Override void copyFrom(LongBag from, int fromOffset, int length); @Override void copyFrom(LongBag from, int fromOffset, int length, boolean clearExceeding); @Override void copyPartFrom(LongBag from, int fromOffset, int toOffset, int length); @Override void ensureCapacity(int capacity); long get(int index); void set(int index, long value); @Override void clear(); @Override void clear(Mask mask); @Experimental
    public long[] buffer; }