CharBag implements AnyBag<CharBag> { @Override public void copyPartFrom(CharBag from, int fromOffset, int toOffset, int length) { ensureCapacity(toOffset + length); int maxLength = from.buffer.length - fromOffset; System.arraycopy(from.buffer, fromOffset, buffer, toOffset, Math.min(length, maxLength)); if (maxLength < length) { char[] buffer = this.buffer; for (int i = toOffset + maxLength, n = toOffset + length; i < n; i++) buffer[i] = (char) 0; } } CharBag(); @Override void copyFrom(CharBag from); @Override void copyFrom(CharBag from, boolean clearExceeding); @Override void copyFrom(CharBag from, int length); @Override void copyFrom(CharBag from, int length, boolean clearExceeding); @Override void copyFrom(CharBag from, int fromOffset, int length); @Override void copyFrom(CharBag from, int fromOffset, int length, boolean clearExceeding); @Override void copyPartFrom(CharBag from, int fromOffset, int toOffset, int length); @Override void ensureCapacity(int capacity); char get(int index); void set(int index, char value); @Override void clear(); @Override void clear(Mask mask); @Experimental
    public char[] buffer; }
@Test public void testCopyPartFrom() { CharBag b0, b1; char e0 = (char) 1, e1 = (char) 1, e2 = (char) 1, e3 = (char) 1; b0 = new CharBag(); b0.set(5, e0); b0.set(14, e1); b0.set(21, e2); b1 = new CharBag(); b1.set(0, e3); b1.set(33, e0); b1.copyPartFrom(b0, 14, 1, 33); assertEquals((Character) e1, (Character) b1.get(1)); assertEquals((Character) e2, (Character) b1.get(8)); assertEquals((Character) e3, (Character) b1.get(0)); assertEquals((Character) (char) 0, (Character) b1.get(32)); assertEquals((Character) (char) 0, (Character) b1.get(33)); assertEquals((Character) (char) 0, (Character) b1.get(34)); assertEquals((Character) (char) 0, (Character) b1.get(35)); b0 = new CharBag(); b0.set(5, e0); b0.set(14, e1); b0.set(21, e2); b1 = new CharBag(); b1.set(0, e3); b1.copyPartFrom(b0, 14, 1, 8); assertEquals((Character) e1, (Character) b1.get(1)); assertEquals((Character) e2, (Character) b1.get(8)); assertEquals((Character) e3, (Character) b1.get(0)); assertEquals((Character) (char) 0, (Character) b1.get(32)); assertEquals((Character) (char) 0, (Character) b1.get(33)); assertEquals((Character) (char) 0, (Character) b1.get(34)); assertEquals((Character) (char) 0, (Character) b1.get(35)); }