tfw.immutable.ila.byteila.ByteIlaMutate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tfw Show documentation
Show all versions of tfw Show documentation
The FrameWork for building highly scalable and maintainable applications
The newest version!
package tfw.immutable.ila.byteila;
import java.io.IOException;
import tfw.check.Argument;
public final class ByteIlaMutate {
private ByteIlaMutate() {
// non-instantiable class
}
public static ByteIla create(ByteIla ila, long index, byte value) throws IOException {
Argument.assertNotNull(ila, "ila");
Argument.assertNotLessThan(index, 0, "index");
Argument.assertLessThan(index, ila.length(), "index", "ila.length()");
return new ByteIlaImpl(ila, index, value);
}
private static class ByteIlaImpl extends AbstractByteIla {
private final ByteIla ila;
private final long index;
private final byte value;
private ByteIlaImpl(ByteIla ila, long index, byte value) {
this.ila = ila;
this.index = index;
this.value = value;
}
@Override
protected long lengthImpl() throws IOException {
return ila.length();
}
@Override
protected void getImpl(byte[] array, int offset, long start, int length) throws IOException {
final long startPlusLength = start + length;
if (index < start || index >= startPlusLength) {
ila.get(array, offset, start, length);
} else {
final int indexMinusStart = (int) (index - start);
if (index > start) {
ila.get(array, offset, start, indexMinusStart);
}
array[offset + indexMinusStart] = value;
if (index <= startPlusLength) {
ila.get(array, offset + indexMinusStart + 1, index + 1, length - indexMinusStart - 1);
}
}
}
}
}
// AUTO GENERATED FROM TEMPLATE