Class SmallLongBuffer

java.lang.Object
tech.bitey.bufferstuff.SmallBuffer
tech.bitey.bufferstuff.SmallLongBuffer

public final class SmallLongBuffer extends SmallBuffer
This class has an API similar to LongBuffer. All implementations are backed by a BigByteBuffer. "Small" refers to the fact that these buffers are indexed by ints rather than longs.

Differences from LongBuffer include:

  • mark and reset are not supported
  • read-only is not supported
  • byte order is preserved in duplicate() and slice().
  • Method Details

    • put

      public SmallLongBuffer put(long value)
      Relative put method

      Writes the given long into this buffer at the current position, and then increments the position.

      Parameters:
      value - The long to be written
      Returns:
      This buffer
      Throws:
      BufferOverflowException - If this buffer's current position is not smaller than its limit
    • put

      public SmallLongBuffer put(int index, long value)
      Absolute put method

      Writes the given long into this buffer at the given index.

      Parameters:
      index - The index at which the long will be written
      value - The long value to be written
      Returns:
      This buffer
      Throws:
      IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit
    • put

      public final SmallLongBuffer put(long[] src)
      Relative bulk put method

      This method transfers the entire content of the given source Long array into this buffer.

      Parameters:
      src - The source array
      Returns:
      This buffer
      Throws:
      BufferOverflowException - If there is insufficient space in this buffer
    • put

      public SmallLongBuffer put(LongBuffer src)
      Relative bulk put method

      This method transfers the longs remaining in the given source buffer into this buffer. If there are more longs remaining in the source buffer than in this buffer, that is, if src.remaining() > remaining(), then no shorts are transferred and a BufferOverflowException is thrown.

      Otherwise, this method copies n = src.remaining() longs from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.

      In other words, an invocation of this method of the form dst.put(src) has exactly the same effect as the loop

       while (src.hasRemaining())
              dst.put(src.get());
       
      except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient. If this buffer and the source buffer share the same backing array or memory, then the result will be as if the source elements were first copied to an intermediate location before being written into this buffer.
      Parameters:
      src - The source buffer from which longs are to be read; must not be this buffer
      Returns:
      This buffer
      Throws:
      BufferOverflowException - If there is insufficient space in this buffer for the remaining longs in the source buffer
    • put

      public SmallLongBuffer put(SmallLongBuffer src)
      Relative bulk put method

      This method transfers the longs remaining in the given source buffer into this buffer. If there are more longs remaining in the source buffer than in this buffer, that is, if src.remaining() > remaining(), then no shorts are transferred and a BufferOverflowException is thrown.

      Otherwise, this method copies n = src.remaining() longs from the given buffer into this buffer, starting at each buffer's current position. The positions of both buffers are then incremented by n.

      In other words, an invocation of this method of the form dst.put(src) has exactly the same effect as the loop

       while (src.hasRemaining())
              dst.put(src.get());
       
      except that it first checks that there is sufficient space in this buffer and it is potentially much more efficient. If this buffer and the source buffer share the same backing array or memory, then the result will be as if the source elements were first copied to an intermediate location before being written into this buffer.
      Parameters:
      src - The source buffer from which longs are to be read; must not be this buffer
      Returns:
      This buffer
      Throws:
      BufferOverflowException - If there is insufficient space in this buffer for the remaining longs in the source buffer
    • get

      public long get()
      Relative get method. Reads the long at this buffer's current position, and then increments the position.
      Returns:
      The long at the buffer's current position
      Throws:
      BufferUnderflowException - If the buffer's current position is not smaller than its limit
    • get

      public long get(int index)
      Absolute get method. Reads the long at the given index.
      Parameters:
      index - The index from which the long will be read
      Returns:
      The long at the given index
      Throws:
      IndexOutOfBoundsException - If index is negative or not smaller than the buffer's limit
    • duplicate

      public SmallLongBuffer duplicate()
      Description copied from class: SmallBuffer
      Creates a new buffer that shares this buffer's content.

      The content of the new buffer will be that of this buffer. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position and limit values will be independent.

      The new buffer's capacity, limit, position, and byte order values will be identical to those of this buffer. The new buffer will be direct if, and only if, this buffer is direct.

      Specified by:
      duplicate in class SmallBuffer
      Returns:
      The new buffer
    • slice

      public SmallLongBuffer slice()
      Description copied from class: SmallBuffer
      Creates a new buffer whose content is a shared subsequence of this buffer's content.

      The content of the new buffer will start at this buffer's current position. Changes to this buffer's content will be visible in the new buffer, and vice versa; the two buffers' position and limit values will be independent.

      The new buffer's position will be zero, its capacity and its limit will be the number of elements remaining in this buffer, and the byte order will be the same as this buffer. The new buffer will be direct if, and only if, this buffer is direct.

      Specified by:
      slice in class SmallBuffer
      Returns:
      The new buffer
    • toString

      public String toString()
      Overrides:
      toString in class Object