Enum Class BufferUtils

java.lang.Object
java.lang.Enum<BufferUtils>
tech.bitey.bufferstuff.BufferUtils
All Implemented Interfaces:
Serializable, Comparable<BufferUtils>, Constable

public enum BufferUtils extends Enum<BufferUtils>
Utility methods for working with nio buffers.
Author:
biteytech@protonmail.com
  • Field Details

  • Method Details

    • values

      public static BufferUtils[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static BufferUtils valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • allocate

      public static ByteBuffer allocate(int capacity)
      Allocates a new ByteBuffer with the specified capacity. The buffer will be direct if the tech.bitey.allocateDirect system property is set to "true", and will have native order.
      Parameters:
      capacity - the new buffer's capacity, in bytes
      Returns:
      the new native order ByteBuffer
    • allocate

      public static ByteBuffer allocate(int capacity, ByteOrder order)
      Allocates a new ByteBuffer with the specified capacity. The buffer will be direct if the tech.bitey.allocateDirect system property is set to "true", and will have the specified ByteOrder.
      Parameters:
      capacity - the new buffer's capacity, in bytes
      order - the ByteOrder
      Returns:
      the new ByteBuffer
    • allocateBig

      public static BigByteBuffer allocateBig(long capacity)
      Allocates a new BigByteBuffer with the specified capacity. The buffer will be direct if the tech.bitey.allocateDirect system property is set to "true", and will have native order.
      Parameters:
      capacity - the new buffer's capacity, in bytes
      Returns:
      the new native order BigByteBuffer
    • allocateBig

      public static BigByteBuffer allocateBig(long capacity, ByteOrder order)
      Allocates a new BigByteBuffer with the specified capacity. The buffer will be direct if the tech.bitey.allocateDirect system property is set to "true", and will have the specified ByteOrder.
      Parameters:
      capacity - the new buffer's capacity, in bytes
      order - the ByteOrder
      Returns:
      the new BigByteBuffer
    • wrap

      public static BigByteBuffer wrap(ByteBuffer[] buffers)
      Returns a new BigByteBuffer backed by the specified ByteBuffers.
      Returns:
      a new BigByteBuffer backed by the specified ByteBuffer ByteBuffers.
    • duplicate

      public static ByteBuffer duplicate(ByteBuffer b)
      Duplicate a ByteBuffer and preserve the order. Equivalent to:
       b.duplicate().order(b.order())
       
      Parameters:
      b - - the buffer to be duplicated
      Returns:
      duplicated buffer with order preserved
      See Also:
    • slice

      public static ByteBuffer slice(ByteBuffer b)
      Slice a ByteBuffer and preserve the order. Equivalent to:
       b.slice().order(b.order())
       
      Parameters:
      b - - the buffer to be sliced
      Returns:
      sliced buffer with order preserved
      See Also:
    • asReadOnlyBuffer

      public static ByteBuffer asReadOnlyBuffer(ByteBuffer b)
      Creates a new, read-only byte buffer that shares the specified buffer's content, and preserves it's order. Equivalent to:
       b.asReadOnlyBuffer().order(b.order())
       
      Parameters:
      b - - the buffer to be made read-only
      Returns:
      read-only byte buffer that shares the specified buffer's content
      See Also:
    • slice

      public static ByteBuffer slice(ByteBuffer b, int fromIndex, int toIndex)
      Slice a range from the specified ByteBuffer. The buffer's order is preserved.
      Parameters:
      b - - the buffer to be sliced
      fromIndex - - the index of the first element in the range (inclusive)
      toIndex - - the index of the last element in the range (exclusive)
      Returns:
      sliced buffer with order preserved
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
      See Also:
    • isSorted

      public static boolean isSorted(IntBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(IntBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(LongBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(LongBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(ByteBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(ByteBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(ShortBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(ShortBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(FloatBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(FloatBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(DoubleBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(DoubleBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • copy

      public static ByteBuffer copy(ByteBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      a copy of a range of data from the specified buffer
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • copy

      public static IntBuffer copy(IntBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      a copy of a range of data from the specified buffer
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • copy

      public static LongBuffer copy(LongBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      a copy of a range of data from the specified buffer
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • copy

      public static ShortBuffer copy(ShortBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      a copy of a range of data from the specified buffer
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • copy

      public static FloatBuffer copy(FloatBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      a copy of a range of data from the specified buffer
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • copy

      public static DoubleBuffer copy(DoubleBuffer b, int fromIndex, int toIndex)
      Returns a copy of a range from the specified buffer. The new buffer will be direct iff the specified buffer is direct, and will have the same byte order. The capacity will be equal to the size of the specified range. The limit will be set to the capacity, and the position will be set to zero.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      a copy of a range of data from the specified buffer
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(IntBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified IntBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(LongBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified LongBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(ShortBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified ShortBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(ByteBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified ByteBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(FloatBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified FloatBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(DoubleBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified DoubleBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • stream

      public static IntStream stream(IntBuffer buffer)
      Returns a sequential IntStream with the specified buffer as its source.

      Note: ignores position and limit, can pass a slice instead.

      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      Returns:
      an IntStream for the buffer
    • stream

      public static IntStream stream(IntBuffer buffer, int startInclusive, int endExclusive, int characteristics)
      Returns a sequential IntStream with the specified range of the specified buffer as its source.
      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      startInclusive - the first index to cover, inclusive
      endExclusive - index immediately past the last index to cover
      characteristics - characteristics of this spliterator's source or elements beyond SIZED, SUBSIZED, ORDERED, NONNULL, and IMMUTABLE, which are are always reported
      Returns:
      an IntStream for the buffer range
      Throws:
      ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the buffer's capacity
    • stream

      public static LongStream stream(LongBuffer buffer)
      Returns a sequential LongStream with the specified buffer as its source.

      Note: ignores position and limit, can pass a slice instead.

      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      Returns:
      an LongStream for the buffer
    • stream

      public static LongStream stream(LongBuffer buffer, int startInclusive, int endExclusive, int characteristics)
      Returns a sequential LongStream with the specified range of the specified buffer as its source.
      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      startInclusive - the first index to cover, inclusive
      endExclusive - index immediately past the last index to cover
      characteristics - characteristics of this spliterator's source or elements beyond SIZED, SUBSIZED, ORDERED, NONNULL, and IMMUTABLE, which are are always reported
      Returns:
      an LongStream for the buffer range
      Throws:
      ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the buffer's capacity
    • stream

      public static DoubleStream stream(DoubleBuffer buffer)
      Returns a sequential DoubleStream with the specified buffer as its source.

      Note: ignores position and limit, can pass a slice instead.

      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      Returns:
      an DoubleStream for the buffer
    • stream

      public static DoubleStream stream(DoubleBuffer buffer, int startInclusive, int endExclusive, int characteristics)
      Returns a sequential DoubleStream with the specified range of the specified buffer as its source.
      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      startInclusive - the first index to cover, inclusive
      endExclusive - index immediately past the last index to cover
      characteristics - characteristics of this spliterator's source or elements beyond SIZED, SUBSIZED, ORDERED, NONNULL, and IMMUTABLE, which are are always reported
      Returns:
      an DoubleStream for the buffer range
      Throws:
      ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the buffer's capacity
    • isSorted

      public static boolean isSorted(SmallIntBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(SmallIntBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(SmallLongBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(SmallLongBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(SmallByteBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(SmallByteBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(SmallShortBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(SmallShortBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(SmallFloatBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(SmallFloatBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSorted

      public static boolean isSorted(SmallDoubleBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted inside the specified range. That is: buffer[i] <= buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • isSortedAndDistinct

      public static boolean isSortedAndDistinct(SmallDoubleBuffer b, int fromIndex, int toIndex)
      Determines if the specified buffer is sorted and distinct inside the specified range. That is: buffer[i] < buffer[i + 1] for all elements in the range. A range of length zero or one is considered sorted and distinct.
      Parameters:
      b - - the buffer to be checked
      fromIndex - - the index of the first element (inclusive) to be checked
      toIndex - - the index of the last element (exclusive) to be checked
      Returns:
      true if the buffer is sorted and distinct inside the specified range
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(SmallIntBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified SmallIntBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(SmallLongBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified SmallLongBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(SmallShortBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified SmallShortBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(SmallByteBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified SmallByteBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(SmallFloatBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified SmallFloatBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • deduplicate

      public static int deduplicate(SmallDoubleBuffer b, int fromIndex, int toIndex)
      Deduplicates a range of the specified SmallDoubleBuffer. The range must be sorted in ascending order prior to making this call. If it is not sorted, the results are undefined.

      This method is useful as a post-processing step after a sort on a buffer which contains duplicate elements.

      Parameters:
      b - the buffer to be deduplicated
      fromIndex - - the index of the first element (inclusive) to be deduplicated
      toIndex - - the index of the last element (exclusive) to be deduplicated
      Returns:
      the (exclusive) highest index in use after deduplicating
      Throws:
      IllegalArgumentException - if fromIndex > toIndex
      IndexOutOfBoundsException - if fromIndex < 0 or toIndex > b.capacity()
    • stream

      public static IntStream stream(SmallIntBuffer buffer)
      Returns a sequential IntStream with the specified buffer as its source.

      Note: ignores position and limit, can pass a slice instead.

      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      Returns:
      an IntStream for the buffer
    • stream

      public static IntStream stream(SmallIntBuffer buffer, int startInclusive, int endExclusive, int characteristics)
      Returns a sequential IntStream with the specified range of the specified buffer as its source.
      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      startInclusive - the first index to cover, inclusive
      endExclusive - index immediately past the last index to cover
      characteristics - characteristics of this spliterator's source or elements beyond SIZED, SUBSIZED, ORDERED, NONNULL, and IMMUTABLE, which are are always reported
      Returns:
      an IntStream for the buffer range
      Throws:
      ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the buffer's capacity
    • stream

      public static LongStream stream(SmallLongBuffer buffer)
      Returns a sequential LongStream with the specified buffer as its source.

      Note: ignores position and limit, can pass a slice instead.

      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      Returns:
      an LongStream for the buffer
    • stream

      public static LongStream stream(SmallLongBuffer buffer, int startInclusive, int endExclusive, int characteristics)
      Returns a sequential LongStream with the specified range of the specified buffer as its source.
      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      startInclusive - the first index to cover, inclusive
      endExclusive - index immediately past the last index to cover
      characteristics - characteristics of this spliterator's source or elements beyond SIZED, SUBSIZED, ORDERED, NONNULL, and IMMUTABLE, which are are always reported
      Returns:
      an LongStream for the buffer range
      Throws:
      ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the buffer's capacity
    • stream

      public static DoubleStream stream(SmallDoubleBuffer buffer)
      Returns a sequential DoubleStream with the specified buffer as its source.

      Note: ignores position and limit, can pass a slice instead.

      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      Returns:
      an DoubleStream for the buffer
    • stream

      public static DoubleStream stream(SmallDoubleBuffer buffer, int startInclusive, int endExclusive, int characteristics)
      Returns a sequential DoubleStream with the specified range of the specified buffer as its source.
      Parameters:
      buffer - the buffer, assumed to be unmodified during use
      startInclusive - the first index to cover, inclusive
      endExclusive - index immediately past the last index to cover
      characteristics - characteristics of this spliterator's source or elements beyond SIZED, SUBSIZED, ORDERED, NONNULL, and IMMUTABLE, which are are always reported
      Returns:
      an DoubleStream for the buffer range
      Throws:
      ArrayIndexOutOfBoundsException - if startInclusive is negative, endExclusive is less than startInclusive, or endExclusive is greater than the buffer's capacity
    • writeFully

      public static void writeFully(WritableByteChannel channel, ByteBuffer buffer) throws IOException
      Writes all remaining bytes from the given buffer into the given channel.
      Parameters:
      channel - - the channel being written to
      buffer - - the buffer being read from
      Throws:
      IOException
    • readFully

      public static void readFully(ReadableByteChannel channel, ByteBuffer buffer) throws IOException
      Reads bytes from the given channel until the given buffer is full (remaining is 0).
      Parameters:
      channel - - the channel being read from
      buffer - - the buffer being written to
      Throws:
      IOException