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