/** * Appends the passed element to the end of the list. * * @param srcBuffer from which the element bytes will be copied. * @param offset at which the element begins. * @param length of the element. */ public void add(DirectBuffer srcBuffer, int offset, int length) { add(srcBuffer, offset, length, max(size(), 0)); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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; }
@Override public boolean hasNext() { return position + 1 < values.size(); }
/** * Appends the passed element to the end of the list. * * @param srcBuffer from which the element bytes will be copied. */ public void add(DirectBuffer srcBuffer) { add(srcBuffer, 0, srcBuffer.capacity()); }
public void moveTo(int element) { context.wrap(element, cursorView); }
public MsgPackQueryExecutor() { this.matchingPositions = new CompactList(RESULT_SIZE, MAX_RESULTS, new HeapBufferAllocator()); }
public void clear() { context.clear(); } }
protected void boundsCheck(final int index, final int size) { if (index < 0 || index > size) { throw indexOutOfBoundsException(index, size); } }
/** * 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); }
/** * 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); }
/** * 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; }
public int size() { return context.size(); }
/** * Appends the passed element to the end of the list. * * @param srcBuffer from which the element bytes will be copied. */ public void add(DirectBuffer srcBuffer) { add(srcBuffer, 0, srcBuffer.capacity()); }