Hi Michael,

I'm not sure how alive the primitives component is, but the best way to
contribute new methods like these is to provide a GitHub PR with unit
tests. It is very unlikely that new code like this would be accepted
without unit tests and decent code coverage. But, this component is not
mirrored on GitHub so you'll have to do it the old fashioned way:
- Create a JIRA
- Attach a patch in unified diff format for your new methods and their unit
tests

Thank you!
Gary

On Mon, Feb 19, 2018 at 5:34 PM, Michael Mirwaldt <epcfr...@gmail.com>
wrote:

> 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
>

Reply via email to