/** * Sets a subsequence of this buffer with the contents of the specified buffer. The subsequence to set starts with * the vector at the specified position, and has size equal to the specified size. The specified buffer must have * the same logical vector size as this buffer (coordsPerVec must be equivalent). * * @param position the starting vector position to set. * @param buffer the input buffer. * @param offset the vector position to start copying values from the specified buffer. * @param size the number of vectors to read copy form the specified buffer. * * @throws ArgumentException if the position is out of range, if the buffer is null or incompatible, if this * buffer has insufficient length to store the sub-buffer at the specified * position, or if the specified offset and size define a range outside of the * specified buffer. */ public void putSubBuffer(int position, VecBuffer buffer, int offset, int size) { if (position < 0 || position >= this.getSize()) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "position < 0 or position >= size"); Logging.logger().severe(message); throw new ArgumentException(message); } if (buffer == null) { String message = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } // Not enough room in buffer. if (buffer.getSize() < (offset + size)) { String message = Logging.getMessage("generic.BufferOverflow", buffer.getSize(), size); Logging.logger().severe(message); throw new ArgumentException(message); } // Buffer is incompatible. if (this.coordsPerVec != buffer.coordsPerVec) { String message = Logging.getMessage("generic.BufferIncompatible", buffer); Logging.logger().severe(message); throw new ArgumentException(message); } // Buffer is too large. int sizeNeeded = position + size; if (this.getSize() < sizeNeeded) { String message = Logging.getMessage("generic.BufferOverflow", this.getSize(), sizeNeeded); Logging.logger().severe(message); throw new ArgumentException(message); } int index = this.indexFromVectorPosition(position); int off = this.indexFromVectorPosition(offset); int length = this.indexFromVectorPosition(size); this.buffer.putSubBuffer(index, buffer.getBufferWrapper(), off, length); }
/** * Appends the contents of the specified sub-buffer to the end of this PackedCompoundVecBuffer, incrementing the * number of sub-buffers by one. The backing buffer grows to accomodate the sub-buffer if it does not already have * enough capacity to hold it. * * @param buffer the sub-buffer to append. * * @return the sub-buffer's index. * * @throws ArgumentException if the subBuffer is null. */ public int append(VecBuffer buffer) { if (buffer == null) { String message = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } int minVecCount = buffer.getSize() + this.vecCount; if (minVecCount > this.buffer.getSize()) { this.expandBufferCapacity(minVecCount); } int newBufferPos = this.vecCount; this.buffer.putSubBuffer(newBufferPos, buffer); this.vecCount += buffer.getSize(); return(this.addSubBuffer(newBufferPos, buffer.getSize())); }
/** * Sets a subsequence of this buffer with the contents of the specified buffer. The subsequence to set starts with * the vector at the specified position, and has size equal to the specified buffer's size. The specified buffer * must have the same logical vector size as this buffer (coordsPerVec must be equivalent). * * @param position the starting vector position to set. * @param buffer the input buffer. * * @throws ArgumentException if the position is out of range, if the buffer is null or incompatible, or if * this buffer has insufficient length to store the sub-buffer at the specified * position. */ public void putSubBuffer(int position, VecBuffer buffer) { if (position < 0 || position >= this.getSize()) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "position < 0 or position >= size"); Logging.logger().severe(message); throw new ArgumentException(message); } if (buffer == null) { String message = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } this.putSubBuffer(position, buffer, 0, buffer.getSize()); }