Class DataBuffers


  • public final class DataBuffers
    extends Object
    Helper class for creating DataBuffer instances.
    • Constructor Detail

      • DataBuffers

        public DataBuffers()
    • Method Detail

      • ofBytes

        public static ByteDataBuffer ofBytes​(long size)
        Creates a buffer of bytes that can store up to size values
        Parameters:
        size - size of the buffer to allocate
        Returns:
        a new buffer
      • ofLongs

        public static LongDataBuffer ofLongs​(long size)
        Creates a buffer of longs that can store up to size values
        Parameters:
        size - size of the buffer to allocate
        Returns:
        a new buffer
      • ofInts

        public static IntDataBuffer ofInts​(long size)
        Creates a buffer of integers that can store up to size values
        Parameters:
        size - size of the buffer to allocate
        Returns:
        a new buffer
      • ofShorts

        public static ShortDataBuffer ofShorts​(long size)
        Creates a buffer of shorts that can store up to size values
        Parameters:
        size - size of the buffer to allocate
        Returns:
        a new buffer
      • ofDoubles

        public static DoubleDataBuffer ofDoubles​(long size)
        Creates a buffer of doubles that can store up to size values
        Parameters:
        size - size of the buffer to allocate
        Returns:
        a new buffer
      • ofFloats

        public static FloatDataBuffer ofFloats​(long size)
        Creates a buffer of floats that can store up to size values
        Parameters:
        size - size of the buffer to allocate
        Returns:
        a new buffer
      • ofBooleans

        public static BooleanDataBuffer ofBooleans​(long size)
        Creates a buffer of booleans that can store up to size values
        Parameters:
        size - size of the buffer to allocate
        Returns:
        a new buffer
      • ofObjects

        public static <T> DataBuffer<T> ofObjects​(Class<T> type,
                                                  long size)
        Creates a buffer of references to objects of type clazz` that can store up to `size values.
        Type Parameters:
        T - data type
        Parameters:
        type - the type of object stored in this buffer
        size - size of the buffer to allocate
        Returns:
        a new buffer
      • of

        public static FloatDataBuffer of​(float... values)
        Create a buffer from an array of floats into a data buffer.

        The returned buffer allows read and write operations and share the memory of the source array, which is equivalent to call of(values, false, false}

        Parameters:
        values - float values
        Returns:
        a new buffer
      • of

        public static ByteDataBuffer of​(byte... values)
        Create a buffer from an array of bytes into a data buffer.

        The returned buffer allows read and write operations and share the memory of the source array, which is equivalent to call of(values, false, false}

        Parameters:
        values - byte values
        Returns:
        a new buffer
      • of

        public static LongDataBuffer of​(long... values)
        Create a buffer from an array of longs into a data buffer.

        The returned buffer allows read and write operations and share the memory of the source array, which is equivalent to call of(values, false, false}

        Parameters:
        values - long values
        Returns:
        a new buffer
      • of

        public static IntDataBuffer of​(int... values)
        Create a buffer from an array of ints into a data buffer.

        The returned buffer allows read and write operations and share the memory of the source array, which is equivalent to call of(values, false, false}

        Parameters:
        values - int values
        Returns:
        a new buffer
      • of

        public static ShortDataBuffer of​(short... values)
        Create a buffer from an array of shorts into a data buffer.

        The returned buffer allows read and write operations and share the memory of the source array, which is equivalent to call of(values, false, false}

        Parameters:
        values - short values
        Returns:
        a new buffer
      • of

        public static DoubleDataBuffer of​(double... values)
        Create a buffer from an array of doubles into a data buffer.

        The returned buffer allows read and write operations and share the memory of the source array, which is equivalent to call of(array, false, false}

        Parameters:
        values - double values
        Returns:
        a new buffer
      • of

        public static BooleanDataBuffer of​(boolean... values)
        Create a buffer from an array of booleans into a data buffer.

        The returned buffer allows read and write operations and share the memory of the source array, which is equivalent to call of(values, false, false}

        Parameters:
        values - booleans values
        Returns:
        a new buffer
      • ofObjects

        @SafeVarargs
        public static <T> DataBuffer<T> ofObjects​(T... values)
        Create a buffer from an array of objects into a data buffer.

        The returned buffer allows read and write operations and share the memory of the source array, which is equivalent to call of(values, false, false}

        Type Parameters:
        T - data type
        Parameters:
        values - objects values
        Returns:
        a new buffer
      • of

        public static FloatDataBuffer of​(float[] array,
                                         boolean readOnly,
                                         boolean makeCopy)
        Create a buffer from an array of floats into a data buffer.
        Parameters:
        array - array of floats
        readOnly - true if the buffer created must be read-only
        makeCopy - true if the array must be copied, false will wrap the provided array
        Returns:
        a new buffer
      • of

        public static ByteDataBuffer of​(byte[] array,
                                        boolean readOnly,
                                        boolean makeCopy)
        Create a buffer from an array of bytes into a data buffer.
        Parameters:
        array - array of bytes
        readOnly - true if the buffer created must be read-only
        makeCopy - true if the array must be copied, false will wrap the provided array
        Returns:
        a new buffer
      • of

        public static LongDataBuffer of​(long[] array,
                                        boolean readOnly,
                                        boolean makeCopy)
        Create a buffer from an array of longs into a data buffer.
        Parameters:
        array - array of longs
        readOnly - true if the buffer created must be read-only
        makeCopy - true if the array must be copied, false will wrap the provided array
        Returns:
        a new buffer
      • of

        public static IntDataBuffer of​(int[] array,
                                       boolean readOnly,
                                       boolean makeCopy)
        Create a buffer from an array of ints into a data buffer.
        Parameters:
        array - array of ints
        readOnly - true if the buffer created must be read-only
        makeCopy - true if the array must be copied, false will wrap the provided array
        Returns:
        a new buffer
      • of

        public static ShortDataBuffer of​(short[] array,
                                         boolean readOnly,
                                         boolean makeCopy)
        Create a buffer from an array of shorts into a data buffer.
        Parameters:
        array - array of shorts
        readOnly - true if the buffer created must be read-only
        makeCopy - true if the array must be copied, false will wrap the provided array
        Returns:
        a new buffer
      • of

        public static DoubleDataBuffer of​(double[] array,
                                          boolean readOnly,
                                          boolean makeCopy)
        Create a buffer from an array of doubles into a data buffer.
        Parameters:
        array - array of doubles
        readOnly - true if the buffer created must be read-only
        makeCopy - true if the array must be copied, false will wrap the provided array
        Returns:
        a new buffer
      • of

        public static BooleanDataBuffer of​(boolean[] array,
                                           boolean readOnly,
                                           boolean makeCopy)
        Create a buffer from an array of booleans into a data buffer.
        Parameters:
        array - array of booleans
        readOnly - true if the buffer created must be read-only
        makeCopy - true if the array must be copied, false will wrap the provided array
        Returns:
        a new buffer
      • of

        public static <T> DataBuffer<T> of​(T[] array,
                                           boolean readOnly,
                                           boolean makeCopy)
        Create a buffer from an array of objects into a data buffer.
        Type Parameters:
        T - data type
        Parameters:
        array - array of objects
        readOnly - true if the buffer created must be read-only
        makeCopy - true if the array must be copied, false will wrap the provided array
        Returns:
        a new buffer
      • of

        public static IntDataBuffer of​(IntBuffer buf)
        Wraps a JDK NIO IntBuffer into a data buffer.
        Parameters:
        buf - buffer to wrap
        Returns:
        a new buffer