public class DynamicByteArray extends ModifiedVersionBase implements java.lang.Cloneable
ArrayList)| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_INITIAL_CAPACITY |
| Constructor and Description |
|---|
DynamicByteArray()
Dynamic array of integers with default capacity of 10
|
DynamicByteArray(byte... vals) |
DynamicByteArray(DynamicByteArray array) |
DynamicByteArray(int initialCapacity)
Dynamic array of integers with provided initial capacity
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(byte e) |
void |
addAll(byte[] e) |
void |
addAll(DynamicByteArray array) |
void |
chop(int start,
int size)
Performs an in-place slice, modifying this array directly
|
void |
clear() |
DynamicByteArray |
clone()
Creates a shallow copy
|
void |
ensureCapacity(int cap) |
boolean |
equals(DynamicByteArray array)
Returns
true if this DynamicByteArray is equals to
another one. |
byte |
get(int idx) |
byte[] |
getArray()
Provides direct access to the underlying array.
|
byte |
remove(int idx) |
void |
remove(int idx,
int count)
Remove a specified number of elements starting at the
provided index.
|
void |
resize(int size)
Resizes the array.
|
void |
set(int idx,
byte e)
Sets the value at index
idx to the provided e. |
int |
size() |
DynamicByteArray |
slice(int start,
int size)
Returns a copy of a portion of the array
|
byte[] |
toArray()
Copies the contents of this DynamicByteArray into an array.
|
void |
trimToSize() |
getVersion, notifyModifiedpublic static final int DEFAULT_INITIAL_CAPACITY
public DynamicByteArray()
public DynamicByteArray(int initialCapacity)
initialCapacity - initial capacity. If <= 0, uses
the default capacitypublic DynamicByteArray(byte... vals)
public DynamicByteArray(DynamicByteArray array)
public void ensureCapacity(int cap)
public int size()
public void add(byte e)
public void addAll(byte[] e)
public void addAll(DynamicByteArray array)
public void clear()
public byte remove(int idx)
public void remove(int idx,
int count)
idx - starting index to removecount - number of elements to removepublic void trimToSize()
public void resize(int size)
size - new sizepublic DynamicByteArray slice(int start, int size)
start - starting index to copysize - number of elementspublic void chop(int start,
int size)
start - starting index to keepsize - number of elementspublic byte get(int idx)
public void set(int idx,
byte e)
idx to the provided e.
If idx==size(), then the element is appended to the array.idx - index at which to modify the valuee - new valuepublic byte[] getArray()
ModifiedVersionBase.notifyModified()
is called. The underying array is automatically trimmed to the correct size
before being returned.public byte[] toArray()
public DynamicByteArray clone()
clone in class java.lang.Objectpublic boolean equals(DynamicByteArray array)
true if this DynamicByteArray is equals to
another one.array - array to compare with