Hi Michael,
thanks for your contribution!
Commons-primitives was moved to dormant one and a half year ago (see:
http://mail-archives.apache.org/mod_mbox/commons-user/201607.mbox/%3CCAB917R%2Bsku6f4gJVAicWUgrzAauuuPc4zoAbsuVgbKeWXbhvEA%40mail.gmail.com%3E).
New releases are unlikely. Best not spend any effort on this.
Sorry,
Pascal
Am 20.02.2018 um 01:34 schrieb Michael Mirwaldt:
Hi.
I am using your library for one of my projects.
Given the ByteArrayList, the following two methods can be very handy:
public byte[] removeElementsFromTo(int fromIndex,int toIndex,boolean
returnArray) {
if (fromIndex <0 ||this._size < fromIndex) {
throw new IndexOutOfBoundsException("From-index should be at
least 0 and less than " +this._size +", found " + fromIndex);
}
if (toIndex <1 ||this._size <= toIndex) {
throw new IndexOutOfBoundsException("To-index should be at
least 1 and less than or equal to " +this._size +", found " + toIndex);
}
if (toIndex <= fromIndex) {
throw new IndexOutOfBoundsException("From-index must lie
before to-index." +"from-index=" + fromIndex +", to-index=" + toIndex);
}
int length = toIndex - fromIndex;
byte[] removedBytes =null;
this.incrModCount();
if (0 < length) {
if (returnArray) {
removedBytes =new byte[length];
System.arraycopy(this._data, fromIndex, removedBytes,0,
length);
}
System.arraycopy(this._data, fromIndex + length,this._data,
fromIndex, length);
this._size -= length;
}else {
if (returnArray) {
removedBytes =new byte[0];
}
}
return removedBytes;
}
public void addElementsAt(int index,byte[] elements) {
this.checkRangeIncludingEndpoint(index);
this.incrModCount();
this.ensureCapacity(this._size + elements.length);
int numtomove =this._size - index - elements.length;
System.arraycopy(this._data, index,this._data, index +
elements.length, numtomove);
System.arraycopy(elements,0,this._data, index, elements.length);
this._size+=elements.length;
}
They avoid copying arrays for every single byte.
Maybe you want to add them.
Best regards,'
Michael MIrwaldt
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]