/** * Adds the passed element at the given index. Shifts the element currently at that position (if * any) and any subsequent elements to the right * * @param srcBuffer from which the element bytes will be copied. * @param offset at which the element begins. * @param length of the element. * @param idx at which the specified element is to be inserted. */ public void add(DirectBuffer srcBuffer, int offset, int length, int idx) { final int size = size(); final int capacity = capacity(); elementLengthCheck(length); boundsCheck(idx, size); if (capacity == size) { final String errorMessage = String.format("Cannot add element: list is full. Capacity=%d", capacity); throw new IllegalArgumentException(errorMessage); } final int elementOffset = elementOffset(framedElementLength, idx); if (size - idx > 0) { final int copyOffset = elementOffset + framedElementLength; final int copyLength = (size - idx) * framedElementLength; listBuffer.putBytes(copyOffset, listBuffer, elementOffset, copyLength); } setValue(srcBuffer, offset, length, idx, elementOffset); setSize(size + 1); }
/** * Adds the passed element at the given index. Shifts the element currently at that position (if * any) and any subsequent elements to the right * * @param srcBuffer from which the element bytes will be copied. * @param offset at which the element begins. * @param length of the element. * @param idx at which the specified element is to be inserted. */ public void add(DirectBuffer srcBuffer, int offset, int length, int idx) { final int size = size(); final int capacity = capacity(); elementLengthCheck(length); boundsCheck(idx, size); if (capacity == size) { final String errorMessage = String.format("Cannot add element: list is full. Capacity=%d", capacity); throw new IllegalArgumentException(errorMessage); } final int elementOffset = elementOffset(framedElementLength, idx); if (size - idx > 0) { final int copyOffset = elementOffset + framedElementLength; final int copyLength = (size - idx) * framedElementLength; listBuffer.putBytes(copyOffset, listBuffer, elementOffset, copyLength); } setValue(srcBuffer, offset, length, idx, elementOffset); setSize(size + 1); }