com.jogamp.common.nio

## Class AbstractBuffer<B extends AbstractBuffer>

- java.lang.Object
- - com.jogamp.common.nio.AbstractBuffer<B>

- All Implemented Interfaces:
    NativeBuffer<B>
  Direct Known Subclasses:
    PointerBuffer

      public abstract class AbstractBuffer<B extends AbstractBuffer>
      extends Object
      implements NativeBuffer<B>

  Author:
    Sven Gothel, Michael Bien

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Buffer` | `buffer`
    `protected int` | `capacity`
    `protected int` | `elementSize`
    `protected int` | `position`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractBuffer(Buffer buffer, int elementSize, int capacity)` capacity and elementSize should be match the equation w/ target buffer type

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `array()`
    `int` | `arrayOffset()`
    `int` | `capacity()`
    `int` | `elementSize()`
    `Buffer` | `getBuffer()`
    `boolean` | `hasArray()`
    `boolean` | `hasRemaining()`
    `boolean` | `isDirect()`
    `int` | `limit()`
    `int` | `position()`
    `B` | `position(int newPos)`
    `int` | `remaining()`
    `B` | `rewind()`
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface com.jogamp.common.nio.NativeBuffer

      `get, get, put, put, put`

- - ### Field Detail

    - #### buffer

          protected final Buffer buffer

    - #### elementSize

          protected final int elementSize

    - #### capacity

          protected final int capacity

    - #### position

          protected int position

  - ### Constructor Detail

    - #### AbstractBuffer

          protected AbstractBuffer(Buffer buffer,
                        int elementSize,
                        int capacity)

      capacity and elementSize should be match the equation w/ target buffer type

              capacity = elementSizeInBytes(buffer) * buffer.capacity() ) / elementSize

      Parameters:
        `buffer` - shall be in target format.
        `elementSize` - the target element size in bytes.
        `capacity` - the target capacity in elements of size `elementSize`.

  - ### Method Detail

    - #### elementSize

          public final int elementSize()

      Specified by:
        `elementSize` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### limit

          public final int limit()

      Specified by:
        `limit` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### capacity

          public final int capacity()

      Specified by:
        `capacity` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### position

          public final int position()

      Specified by:
        `position` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### position

          public final B position(int newPos)

      Specified by:
        `position` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### remaining

          public final int remaining()

      Specified by:
        `remaining` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### hasRemaining

          public final boolean hasRemaining()

      Specified by:
        `hasRemaining` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### rewind

          public final B rewind()

      Specified by:
        `rewind` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### getBuffer

          public final Buffer getBuffer()

      Specified by:
        `getBuffer` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### isDirect

          public final boolean isDirect()

      Specified by:
        `isDirect` in interface `NativeBuffer<B extends AbstractBuffer>`

    - #### hasArray

          public final boolean hasArray()

      Specified by:
        `hasArray` in interface `NativeBuffer<B extends AbstractBuffer>`
      Returns:
        true if this buffer has a primitive backup array, otherwise false

    - #### arrayOffset

          public final int arrayOffset()

      Specified by:
        `arrayOffset` in interface `NativeBuffer<B extends AbstractBuffer>`
      Returns:
        the array offset of the optional primitive backup array of the buffer if `NativeBuffer.hasArray()` is true, otherwise 0.

    - #### array

          public Object array()
                       throws UnsupportedOperationException

      Specified by:
        `array` in interface `NativeBuffer<B extends AbstractBuffer>`
      Returns:
        the primitive backup array of the buffer if `NativeBuffer.hasArray()` is true, otherwise it throws `UnsupportedOperationException`. The returned primitive array maybe of type `int[]` or `long[]`, etc ..
      Throws:
        `UnsupportedOperationException` - if this object has no backup array
      See Also:
        `NativeBuffer.hasArray()`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`