Class AbstractDataBuffer<T>

    • Constructor Detail

      • AbstractDataBuffer

        public AbstractDataBuffer()
    • Method Detail

      • read

        public DataBuffer<T> read​(T[] dst,
                                  int offset,
                                  int length)
        Description copied from interface: DataBuffer
        Read the references of the objects in this buffer into the destination array.

        This method transfers values from this buffer into the given destination array. If there are fewer values in the buffer than are required to satisfy the request, that is, if length > size(), then no values are transferred and a BufferUnderflowException is thrown.

        Otherwise, this method copies n = length values from this buffer into the given array starting at the given offset.

        Specified by:
        read in interface DataBuffer<T>
        Parameters:
        dst - the array into which values are to be written
        offset - the offset within the array of the first value to be written; must be non-negative and no larger than dst.length
        length - the maximum number of values to be written to the given array; must be non-negative and no larger than dst.length - offset
        Returns:
        this buffer
      • write

        public DataBuffer<T> write​(T[] src,
                                   int offset,
                                   int length)
        Description copied from interface: DataBuffer
        Bulk put method, using int arrays.

        This method transfers the values in the given source array into this buffer. If there are more values in the source array than in this buffer, that is, if length > size(), then no values are transferred and a BufferOverflowException is thrown.

        Otherwise, this method copies n = length values from the given array into this buffer, starting at the given offset.

        Specified by:
        write in interface DataBuffer<T>
        Parameters:
        src - the source array from which values are to be read
        offset - the offset within the array of the first value to be read; must be non-negative and no larger than src.length
        length - the number of values to be read from the given array; must be non-negative and no larger than src.length - offset
        Returns:
        this buffer
      • copyTo

        public DataBuffer<T> copyTo​(DataBuffer<T> dst,
                                    long size)
        Description copied from interface: DataBuffer
        Write the references of the objects in the source array into this buffer.

        If there are more values to copy than the destination buffer size, i.e. size > dst.size(), then no values are transferred and a BufferOverflowException is thrown. On the other hand, if there are more values to copy that the source buffer size, i.e. > src.size(), then a BufferUnderfloatException is thrown.

        Otherwise, this method copies n = size values from this buffer into the destination buffer.

        Specified by:
        copyTo in interface DataBuffer<T>
        Parameters:
        dst - the destination buffer into which values are copied; must not be this buffer
        size - number of values to copy to the destination buffer
        Returns:
        this buffer
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        public boolean equals​(Object obj)
        Description copied from interface: DataBuffer
        Checks equality between data buffers.

        A data buffer is equal to another object if this object is another DataBuffer of the same size, type and the elements are equal and in the same order. For example:

        
         IntDataBuffer buffer = DataBuffers.of(1, 2, 3);
        
         assertEquals(buffer, DataBuffers.of(1, 2, 3));  // true
         assertEquals(buffer, DataBuffers.ofObjects(1, 2, 3));  // true, as Integers are equal to ints
         assertNotEquals(buffer, DataBuffers.of(1, 2, 3, 0));  // false, different sizes
         assertNotEquals(buffer, DataBuffers.of(1, 3, 2));  // false, different order
         assertNotEquals(buffer, DataBuffers.of(1L, 2L, 3L));  // false, different types
         

        Note that the computation required to verify equality between two buffers can be expensive in some cases and therefore, it is recommended to not use this method in a critical path where performances matter.

        Specified by:
        equals in interface DataBuffer<T>
        Overrides:
        equals in class Object
        Parameters:
        obj - object to compare this buffer with
        Returns:
        true if this buffer is equal to the provided object
      • slowHashCode

        protected int slowHashCode()
      • slowEquals

        protected boolean slowEquals​(DataBuffer<?> other)