protected void setValue(DirectBuffer buffer, int offset, int length, int idx) { final int elementOffset = elementOffset(framedElementLength, idx); setValue(buffer, offset, length, idx, elementOffset); }
protected void setValue(DirectBuffer buffer, int offset, int length, int idx) { final int elementOffset = elementOffset(framedElementLength, idx); setValue(buffer, offset, length, idx, elementOffset); }
/** Removes all of the elements from this list. The list will be empty after this call returns. */ public void clear() { final int size = size(); final int start = elementOffset(framedElementLength, 0); final int end = framedElementLength * size; setMemory(start, end, (byte) 0); setSize(0); }
/** Removes all of the elements from this list. The list will be empty after this call returns. */ public void clear() { final int size = size(); final int start = elementOffset(framedElementLength, 0); final int end = framedElementLength * size; setMemory(start, end, (byte) 0); setSize(0); }
/** * 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); }
/** * 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); }
/** * 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; }