Pool { public Pool(T[] members) { this.members = members; this.keys = new long[members.length]; this.locked = new byte[members.length]; } Pool(T[] members); T[] members(); T get(long key); void release(long key); int locks();  }
@Test public void testPool() { Random r = new Random(123); int size = 10; StringBuilder[] members = new StringBuilder[size]; int i = size; long[] keys = new long[size]; while ( --i >= 0 ) { members[i] = new StringBuilder(); keys[i] = r.nextLong(); } Pool<StringBuilder> p = new Pool<StringBuilder>(members); int j = size; while (--j>=0) { StringBuilder b = p.get(keys[j]); assertNotNull(b); b.append(Long.toString(keys[j])); } assertNull(p.get(r.nextLong())); j = size; while (--j>=0) { StringBuilder b = p.get(keys[j]); assertNotNull(b); assertEquals(Long.toString(keys[j]), b.toString()); } assertEquals(size, p.locks()); assertNull(p.get(r.nextLong())); j = size; while (--j>=0) { p.release(keys[j]); assertEquals(j, p.locks()); } assertEquals(0, p.locks()); }