Class UnsignedShortBuffer
ShortBuffer
but automatically performs conversion to int
.
The conversion applies to ShortBuffer.get()
and ShortBuffer.put(short)
of single
elements, but not to any mass get or put operations.
The user has a choice of getting/setting using raw (getRaw()
, putRaw(short)
etc.) or
unsigned-conversion (getUnsigned()
, putUnsigned(int)
etc.) methods. The raw methods
are always more efficient, and so should be preferred when conversion is not needed.
- Author:
- Owen Feehan
-
Method Summary
Modifier and TypeMethodDescriptionstatic UnsignedShortBuffer
allocate
(int capacity) Allocates a new (direct) buffer of unsigned-shorts.final short[]
array()
The array of the buffer alaShortBuffer.array()
.protected boolean
boolean
The underlying storage buffer, to which calls are delegated with our without conversion.short
getRaw()
Gets an unsigned-short (represented as a short) at the current buffer position.short
getRaw
(int index) Gets an unsigned-short (represented as a short) at a particular buffer position.int
Gets an unsigned-byte (represented as a int) at the current buffer position.int
getUnsigned
(int index) Gets an unsigned-byte (represented as a int) at a particular buffer position.int
hashCode()
void
put
(ShortBuffer source) Relative put-method from an unsigned short buffer, represented by aShortBuffer
.void
put
(UnsignedShortBuffer source) Relative put-method from an unsigned short buffer, represented by aUnsignedShortBuffer
.void
putDouble
(double value) Puts a double at the current buffer position.void
putDouble
(int index, double value) Puts a double at a particular buffer position.void
putFloat
(float value) Puts a float at the current buffer position.void
putFloat
(int index, float value) Puts a float at a particular buffer position.void
putFloatClamped
(float value) Puts a float at the current buffer position, clamping to ensure the value is within the range(0,255)
.void
putLong
(long value) Puts a long at the current buffer position.void
putLongClamped
(long value) Puts a long at the current buffer position, clamping to ensure the value is within the range(0,255)
.void
putRaw
(int index, short value) Puts an unsigned-short (represented as a short) a particular buffer position.void
putRaw
(short value) Puts an unsigned-short (represented as a short) at the current buffer position.void
putUnsigned
(int value) Puts an unsigned-byte (represented by an int) at current buffer position.void
putUnsigned
(int index, int value) Puts an unsigned-byte (represented as a int) a particular buffer position.void
putUnsignedClamped
(int value) Puts a long at the current buffer position, clamping to ensure the value is within the range(0,255)
.static UnsignedShortBuffer
wrapRaw
(short[] array) Exposes a raw short-array as a buffer with unsigned-shorts.static UnsignedShortBuffer
wrapRaw
(ShortBuffer bufferRaw) Exposes a rawUnsignedShortBuffer
as a buffer with unsigned-shorts.Methods inherited from class org.anchoranalysis.image.voxel.buffer.primitive.UnsignedBufferAsInt
toString
Methods inherited from class org.anchoranalysis.image.voxel.buffer.primitive.UnsignedBuffer
capacity, clear, hasArray, hasRemaining, isDirect, position, position
-
Method Details
-
allocate
Allocates a new (direct) buffer of unsigned-shorts.- Parameters:
capacity
- size of buffer.- Returns:
- newly created buffer (non-direct, i.e. backed by an array).
-
wrapRaw
Exposes a raw short-array as a buffer with unsigned-shorts.- Parameters:
array
- the short-array.- Returns:
- a new instance of
UnsignedShortBuffer
that reusesarray
internally.
-
wrapRaw
Exposes a rawUnsignedShortBuffer
as a buffer with unsigned-shorts.- Parameters:
bufferRaw
- the raw-buffer- Returns:
- a new instance of
UnsignedShortBuffer
that reusesbufferRaw
internally.
-
getRaw
public short getRaw()Gets an unsigned-short (represented as a short) at the current buffer position.No further conversion occurs, so this method is more efficient than
getUnsigned()
.- Returns:
- unsigned-short (represented by a short)
-
getRaw
public short getRaw(int index) Gets an unsigned-short (represented as a short) at a particular buffer position.No further conversion occurs, so this method is more efficient than
getUnsigned(int)
.- Parameters:
index
- the buffer position- Returns:
- unsigned-short (represented by a short)
-
getUnsigned
public int getUnsigned()Description copied from class:UnsignedBufferAsInt
Gets an unsigned-byte (represented as a int) at the current buffer position.- Specified by:
getUnsigned
in classUnsignedBufferAsInt
- Returns:
- unsigned-byte (represented by a int)
-
getUnsigned
public int getUnsigned(int index) Description copied from class:UnsignedBufferAsInt
Gets an unsigned-byte (represented as a int) at a particular buffer position.- Specified by:
getUnsigned
in classUnsignedBufferAsInt
- Parameters:
index
- the buffer position- Returns:
- unsigned-byte (represented by a int)
-
putRaw
public void putRaw(short value) Puts an unsigned-short (represented as a short) at the current buffer position.No further conversion occurs, so this method is more efficient than
putUnsigned(int)
.- Parameters:
value
- unsigned-short (represented by a short)
-
putRaw
public void putRaw(int index, short value) Puts an unsigned-short (represented as a short) a particular buffer position.No further conversion occurs, so this method is more efficient than
putUnsigned(int,int)
.- Parameters:
index
- the buffer positionvalue
- the unsigned-short (represented by an short)
-
putUnsigned
public void putUnsigned(int value) Description copied from class:UnsignedBufferAsInt
Puts an unsigned-byte (represented by an int) at current buffer position.A conversion occurs from int to byte.
- Specified by:
putUnsigned
in classUnsignedBufferAsInt
- Parameters:
value
- the unsigned-byte (represented by an int)
-
putUnsignedClamped
public void putUnsignedClamped(int value) Puts a long at the current buffer position, clamping to ensure the value is within the range(0,255)
.- Parameters:
value
- the float
-
putUnsigned
public void putUnsigned(int index, int value) Description copied from class:UnsignedBufferAsInt
Puts an unsigned-byte (represented as a int) a particular buffer position.A conversion occurs from int to byte.
- Specified by:
putUnsigned
in classUnsignedBufferAsInt
- Parameters:
index
- the buffer positionvalue
- the unsigned-byte (represented by an int)
-
putLong
public void putLong(long value) Description copied from class:UnsignedBuffer
Puts a long at the current buffer position.- Specified by:
putLong
in classUnsignedBuffer
- Parameters:
value
- the long.
-
putLongClamped
public void putLongClamped(long value) Puts a long at the current buffer position, clamping to ensure the value is within the range(0,255)
.- Parameters:
value
- the float
-
putFloat
public void putFloat(float value) Description copied from class:UnsignedBuffer
Puts a float at the current buffer position.A conversion occurs from float to short.
- Specified by:
putFloat
in classUnsignedBuffer
- Parameters:
value
- the float.
-
putFloatClamped
public void putFloatClamped(float value) Puts a float at the current buffer position, clamping to ensure the value is within the range(0,255)
.- Parameters:
value
- the float
-
putFloat
public void putFloat(int index, float value) Description copied from class:UnsignedBuffer
Puts a float at a particular buffer position.A conversion occurs from float to byte.
- Specified by:
putFloat
in classUnsignedBuffer
- Parameters:
index
- the buffer positionvalue
- the float.
-
putDouble
public void putDouble(double value) Description copied from class:UnsignedBuffer
Puts a double at the current buffer position.- Specified by:
putDouble
in classUnsignedBuffer
- Parameters:
value
- the double
-
putDouble
public void putDouble(int index, double value) Description copied from class:UnsignedBuffer
Puts a double at a particular buffer position.- Specified by:
putDouble
in classUnsignedBuffer
- Parameters:
index
- the buffer positionvalue
- the double
-
put
Relative put-method from an unsigned short buffer, represented by aShortBuffer
.This is identical to
ShortBuffer.put(ShortBuffer)
, with no return value.- Parameters:
source
- source of bytes to put
-
put
Relative put-method from an unsigned short buffer, represented by aUnsignedShortBuffer
.This is identical to
ShortBuffer.put(ShortBuffer)
, with no return value.- Parameters:
source
- source of bytes to put
-
array
public final short[] array()The array of the buffer alaShortBuffer.array()
.Unlike
ShortBuffer.array()
an array will always be returned, copying it into a newly created array, if it cannot be directly accessed.- Returns:
- the array
-
equals
- Overrides:
equals
in classUnsignedBufferAsInt
-
canEqual
- Overrides:
canEqual
in classUnsignedBufferAsInt
-
hashCode
public int hashCode()- Overrides:
hashCode
in classUnsignedBufferAsInt
-
getDelegate
The underlying storage buffer, to which calls are delegated with our without conversion.
-