Class UnsignedBuffer

Object
UnsignedBuffer
Direct Known Subclasses:
UnsignedBufferAsInt, UnsignedIntBuffer

public abstract class UnsignedBuffer extends Object
Base class for buffers that represent an unsigned-type in the signed-equivalent-type NIO Buffer.

This class exists as Java does not supported unsigned primitive types (apart from char), so it is necessary to explicitly convert an unsigned primitive type to a larger primitive type for arithmetic operations (e.g. unsigned bytes need to be converted to short or higher, unsigned shorts to int or higher, unsigned int to long or higher).

Subclasses must define a sensible Object.equals(java.lang.Object) and Object.hashCode() that takes account the delegate buffer.

Author:
Owen Feehan
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new UnsignedBuffer instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
     
    final int
    The capacity of the buffer ala Buffer.capacity.
    final void
    Clears the buffer ala Buffer.clear().
    boolean
     
    boolean
    Whether the buffer has an array?
    int
     
    final boolean
    Whether there are elements between the current position and the limit Buffer.hasRemaining().
    boolean
    Is this buffer direct or non-direct?
    final int
    The position of the buffer ala Buffer.position.
    final Buffer
    position(int newPosition)
    Assigns a new position to the buffer.
    abstract void
    putDouble(double value)
    Puts a double at the current buffer position.
    abstract void
    putDouble(int index, double value)
    Puts a double at a particular buffer position.
    abstract void
    putFloat(float value)
    Puts a float at the current buffer position.
    abstract void
    putFloat(int index, float value)
    Puts a float at a particular buffer position.
    abstract void
    putLong(long value)
    Puts a long at the current buffer position.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UnsignedBuffer

      public UnsignedBuffer(Buffer delegate)
      Creates a new UnsignedBuffer instance.
      Parameters:
      delegate - The delegate buffer
  • Method Details

    • putFloat

      public abstract void putFloat(float value)
      Puts a float at the current buffer position.

      A conversion occurs from float to short.

      Parameters:
      value - the float.
    • putFloat

      public abstract void putFloat(int index, float value)
      Puts a float at a particular buffer position.

      A conversion occurs from float to byte.

      Parameters:
      index - the buffer position
      value - the float.
    • putDouble

      public abstract void putDouble(double value)
      Puts a double at the current buffer position.
      Parameters:
      value - the double
    • putDouble

      public abstract void putDouble(int index, double value)
      Puts a double at a particular buffer position.
      Parameters:
      index - the buffer position
      value - the double
    • putLong

      public abstract void putLong(long value)
      Puts a long at the current buffer position.
      Parameters:
      value - the long.
    • hasRemaining

      public final boolean hasRemaining()
      Whether there are elements between the current position and the limit Buffer.hasRemaining().
      Returns:
      true iff elements exist
    • position

      public final int position()
      The position of the buffer ala Buffer.position.
      Returns:
      the position
    • position

      public final Buffer position(int newPosition)
      Assigns a new position to the buffer.

      This is meant in the sense of Java's NIO Buffer classes.

      Parameters:
      newPosition - the index to assign as position.
      Returns:
      the buffer.
    • capacity

      public final int capacity()
      The capacity of the buffer ala Buffer.capacity.
      Returns:
      the capacity
    • clear

      public final void clear()
      Clears the buffer ala Buffer.clear().
    • isDirect

      public boolean isDirect()
      Is this buffer direct or non-direct?

      This is meant in the sense of Java's NIO Buffer classes.

      Returns:
      true iff the buffer is direct.
    • hasArray

      public boolean hasArray()
      Whether the buffer has an array?

      This is meant in the sense of Java's NIO Buffer classes.

      Returns:
      true if the buffer has an array
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object