public class ManagedArray<T> extends Object implements IManagedArray<T>
Note: The backing int[] always has an offset
of ZERO (0) and a
length
equal to the capacity of the backing int[].
This class is NOT thread-safe for mutation. The operation which replaces the
array()
when the capacity of the backing buffer must be extended is
not atomic.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_INITIAL_CAPACITY
The default capacity of the buffer.
|
Constructor and Description |
---|
ManagedArray(Class<? extends T> elementClass,
int initialCapacity)
Creates a buffer with the specified initial capacity.
|
ManagedArray(Class<T> elementClass)
Creates a buffer with an initial capacity of
128 bytes.
|
ManagedArray(T[] array)
Create a view wrapping the entire array.
|
Modifier and Type | Method and Description |
---|---|
T[] |
array()
The backing array.
|
protected static int |
assertNonNegative(String msg,
int v)
Throws exception unless the value is non-negative.
|
int |
capacity()
Return the capacity of the backing buffer.
|
void |
ensureCapacity(int capacity)
Ensure that the buffer capacity is a least capacity total values.
|
T |
get(int pos)
Absolute get of a value at an index.
|
void |
get(int srcoff,
T[] dst)
Absolute bulk get copies
dst.length values
from the specified offset into the slice defined by this buffer into the
caller's array. |
void |
get(int srcoff,
T[] dst,
int dstoff,
int dstlen)
Absolute bulk get copies the specified slice of values
from this buffer into the specified slice of the caller's array.
|
Iterator<T> |
iterator() |
int |
len()
The length of the slice in the
IArraySlice.array() . |
int |
off()
The start of the slice in the
IArraySlice.array() . |
void |
put(int pos,
T v)
Absolute put of a value at an index.
|
void |
put(int pos,
T[] b)
Absolute bulk put copies all values in the caller's array into
this buffer starting at the specified position within the slice defined
by this buffer.
|
void |
put(int pos,
T[] b,
int off,
int len)
Absolute bulk put copies the specified slice of values
from the caller's array into this buffer starting at the specified
position within the slice defined by this buffer.
|
IArraySlice<T> |
slice(int off,
int len)
Return a slice of the backing buffer.
|
T[] |
toArray()
Return a copy of the data in the slice.
|
String |
toString() |
public static final int DEFAULT_INITIAL_CAPACITY
public ManagedArray(Class<T> elementClass)
public ManagedArray(Class<? extends T> elementClass, int initialCapacity)
initialCapacity
- The initial capacity.public ManagedArray(T[] array)
Note: the caller's reference will be used until and unless the array is grown, at which point the caller's reference will be replaced by a larger array having the same data.
array
- The array.public final T[] array()
array
in interface IArraySlice<T>
public final int off()
IArraySlice.array()
.
The offset of the slice into the backing byte[] is always zero.
off
in interface IArraySlice<T>
public final int len()
IArraySlice.array()
.
The length of the slice is always the capacity of the backing byte[].
len
in interface IArraySlice<T>
protected static int assertNonNegative(String msg, int v)
msg
- The exception message.v
- The value.IllegalArgumentException
- unless the value is non-negative.public final void ensureCapacity(int capacity)
IManagedArray
ensureCapacity
in interface IManagedArray<T>
capacity
- The minimum #of values in the buffer.public final int capacity()
IManagedArray
capacity
in interface IManagedArray<T>
public final void put(int pos, T[] b)
IArraySlice
put
in interface IArraySlice<T>
pos
- The starting position within the slice defined by this buffer.b
- The source data.public final void put(int pos, T[] b, int off, int len)
IArraySlice
put
in interface IArraySlice<T>
pos
- The offset into the slice to which the data will be copied.b
- The source data.off
- The offset of the 1st value in the source data to
be copied.len
- The #of values to be copied.public final void get(int srcoff, T[] dst)
IArraySlice
dst.length
values
from the specified offset into the slice defined by this buffer into the
caller's array.get
in interface IArraySlice<T>
srcoff
- The offset into the slice of the first value to be copied.dst
- The array into which the data will be copied.public final void get(int srcoff, T[] dst, int dstoff, int dstlen)
IArraySlice
get
in interface IArraySlice<T>
srcoff
- The offset into the slice defined by this buffer of the first
value to be copied.dst
- The array into which the data will be copied.dstoff
- The offset of the first value in that array onto
which the data will be copied.dstlen
- The #of values to be copied.public final void put(int pos, T v)
IArraySlice
put
in interface IArraySlice<T>
pos
- The index.v
- The value.public final T get(int pos)
IArraySlice
get
in interface IArraySlice<T>
pos
- The index.public final T[] toArray()
IArraySlice
toArray
in interface IArraySlice<T>
public IArraySlice<T> slice(int off, int len)
IArraySlice
IArraySlice.array()
, even when the buffer is extended and
the array reference is replaced.slice
in interface IArraySlice<T>
off
- The starting offset into the backing buffer of the slice.len
- The length of that slice.Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.