/** * Replaces the element at the specified position in this list with the specified element. * * @param idx of the element to replace * @param srcBuffer from which the element bytes will be copied. * @param offset at which the element begins. * @param length of the element. */ public void set(int idx, DirectBuffer srcBuffer, int offset, int length) { final int size = size(); elementLengthCheck(length); boundsCheckIncludingSize(idx, size); setValue(srcBuffer, offset, length, idx); }
/** * Replaces the element at the specified position in this list with the specified element. * * @param idx of the element to replace * @param srcBuffer from which the element bytes will be copied. * @param offset at which the element begins. * @param length of the element. */ public void set(int idx, DirectBuffer srcBuffer, int offset, int length) { final int size = size(); elementLengthCheck(length); boundsCheckIncludingSize(idx, size); setValue(srcBuffer, offset, length, idx); }
/** * Attach a view of the element to a {@link MutableDirectBuffer} for providing direct access. * * @param idx the element to attach. * @param dstBuffer to which the view of the element is attached. * @return the length of the attached element. */ public int wrap(int idx, MutableDirectBuffer dstBuffer) { final int size = size(); boundsCheckIncludingSize(idx, size); final int elementOffset = elementOffset(framedElementLength, idx); final int length = listBuffer.getInt(elementLengthOffset(elementOffset)); dstBuffer.wrap(listBuffer, elementDataOffset(elementOffset), length); return length; }
/** * Get the element from the list into a supplied {@link MutableDirectBuffer}. * * @param idx the element to supply. * @param dstBuffer into which the element will be copied. * @param offset of the supplied buffer to use. * @return the length of the supplied element. */ public int get(int idx, MutableDirectBuffer dstBuffer, int offset) { final int size = size(); boundsCheckIncludingSize(idx, size); final int elementOffset = elementOffset(framedElementLength, idx); final int length = listBuffer.getInt(elementLengthOffset(elementOffset)); dstBuffer.putBytes(offset, listBuffer, elementDataOffset(elementOffset), length); return length; }
/** * Attach a view of the element to a {@link MutableDirectBuffer} for providing direct access. * * @param idx the element to attach. * @param dstBuffer to which the view of the element is attached. * @return the length of the attached element. */ public int wrap(int idx, MutableDirectBuffer dstBuffer) { final int size = size(); boundsCheckIncludingSize(idx, size); final int elementOffset = elementOffset(framedElementLength, idx); final int length = listBuffer.getInt(elementLengthOffset(elementOffset)); dstBuffer.wrap(listBuffer, elementDataOffset(elementOffset), length); return length; }
/** * Get the element from the list into a supplied {@link MutableDirectBuffer}. * * @param idx the element to supply. * @param dstBuffer into which the element will be copied. * @param offset of the supplied buffer to use. * @return the length of the supplied element. */ public int get(int idx, MutableDirectBuffer dstBuffer, int offset) { final int size = size(); boundsCheckIncludingSize(idx, size); final int elementOffset = elementOffset(framedElementLength, idx); final int length = listBuffer.getInt(elementLengthOffset(elementOffset)); dstBuffer.putBytes(offset, listBuffer, elementDataOffset(elementOffset), length); return length; }
/** * Removes the element at the specified position in this list. Shifts any subsequent elements to * the left (subtracts one from their indices). * * @param idx of the element to be removed. */ public void remove(int idx) { final int size = size(); boundsCheckIncludingSize(idx, size); if (size - idx > 1) { final int elementOffset = elementOffset(framedElementLength, idx); final int copyOffset = elementOffset + framedElementLength; final int copyLength = (size - idx - 1) * framedElementLength; listBuffer.putBytes(elementOffset, listBuffer, copyOffset, copyLength); } final int lastElementOffset = elementOffset(framedElementLength, size - 1); setMemory(lastElementOffset, framedElementLength, (byte) 0); setSize(size - 1); }
/** * Removes the element at the specified position in this list. Shifts any subsequent elements to * the left (subtracts one from their indices). * * @param idx of the element to be removed. */ public void remove(int idx) { final int size = size(); boundsCheckIncludingSize(idx, size); if (size - idx > 1) { final int elementOffset = elementOffset(framedElementLength, idx); final int copyOffset = elementOffset + framedElementLength; final int copyLength = (size - idx - 1) * framedElementLength; listBuffer.putBytes(elementOffset, listBuffer, copyOffset, copyLength); } final int lastElementOffset = elementOffset(framedElementLength, size - 1); setMemory(lastElementOffset, framedElementLength, (byte) 0); setSize(size - 1); }