ObjectArrayRef extends ArrayRef<T[]> { @Override public int totalBufferSize(T[] buf) {return (buf == null ? 0 : buf.length);} ObjectArrayRef(T[] src, Allocator<T[]> allocator);  ObjectArrayRef(ObjectArrayRef<T> src, Allocator<T[]> allocator);  ObjectArrayRef(ObjectArrayRef<T> src, int off, int len, Allocator<T[]> allocator);  ObjectArrayRef(Collection<T> src, Allocator<T[]> allocator);  ObjectArrayRef(int capacity, Allocator<T[]> allocator);  ObjectArrayRef(T[] src, int off, int len, Allocator<T[]> allocator);  ObjectArrayRef(Collection<T> src, int off, int len, Allocator<T[]> allocator); @Override int totalBufferSize(T[] buf); T getElement(int idx); void setElement(int idx, T val); @Override int hashCode(); @Override boolean equals(Object obj); @Override boolean canEqual(Object obj);  }
@Test public void testAllocation() { ObjectArrayRef<String> lst = new ObjectArrayRef<>(0, (n) -> new String[n]); Assert.assertNull(lst.buffer()); Assert.assertEquals(0, lst.totalBufferSize()); lst = new ObjectArrayRef<>(5, (n) -> new String[n]); Assert.assertEquals(0, lst.size()); Assert.assertEquals(5, lst.totalBufferSize()); Assert.assertEquals(5, Array.getLength(lst.buffer())); lst.ensureCapacity(7); Assert.assertEquals(0, lst.size()); Assert.assertEquals(7, lst.totalBufferSize()); Assert.assertEquals(7, Array.getLength(lst.buffer())); lst = new ObjectArrayRef<>(0, null); Assert.assertEquals(0, lst.size()); Assert.assertEquals(0, lst.totalBufferSize()); Assert.assertNull(lst.buffer()); try { lst.ensureCapacity(1); Assert.fail("Expected growth to fail without Allocator"); } catch (UnsupportedOperationException ex) {} try { lst = new ObjectArrayRef<>(5, null); Assert.fail("Expected allocation to fail without Allocator"); } catch (UnsupportedOperationException ex) {} }