Class DataList
java.lang.Object
net.mtrop.doom.struct.DataList
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault capacity for a new list. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(byte b) Appends a byte to the end of this buffer.append(byte[] b) Appends a series of bytes to the end of this buffer.append(byte[] b, int offset, int length) Appends a series of bytes to the end of this buffer.protected voidcapacityCheck(int additionalLength) Increases the size of the internal buffer if necessary.clear()Deletes all bytes from this buffer.delete(int startIndex, int length) Deletes a series of bytes from this buffer.intGets the capacity of this buffer.intReturns the capacity increment value.bytegetData(int index) Gets a byte of data from this buffer.voidgetData(int offset, byte[] out) Gets a subset of data from this buffer.voidgetData(int offset, byte[] out, int outOffset, int length) Gets a subset of data from this buffer.byte[]getData(int offset, int length) Gets a subset of data from this buffer.insertAt(byte[] b, int startIndex) Inserts a series of bytes into this buffer at a specific index.booleanisEmpty()voidsetCapacity(int capacity) Sets this buffer's capacity to some value.voidsetCapacityIncrement(int capacityInc) Sets the capacity increment value.voidsetData(int offset, byte[] data) Sets a subset of data in this buffer.intsize()byte[]Returns the bytes in this vector into an array.toString()
-
Field Details
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYDefault capacity for a new list.- See Also:
-
-
Constructor Details
-
DataList
public DataList()Makes a new volatile list. -
DataList
public DataList(int capacity) Makes a new buffer that doubles every resize.- Parameters:
capacity- the initial capacity of this list. If 0 or less, it is 1.
-
DataList
public DataList(int capacity, int capacityInc) Makes a new buffer.- Parameters:
capacity- the initial capacity of this list.capacityInc- what to increase the capacity of this list by if this reaches the max. if 0 or less, it will double.
-
-
Method Details
-
getData
public byte getData(int index) Gets a byte of data from this buffer.- Parameters:
index- the byte index.- Returns:
- a byte array of the requested data.
- Throws:
ArrayIndexOutOfBoundsException- if index exceeds or meets size.
-
getData
public byte[] getData(int offset, int length) Gets a subset of data from this buffer.- Parameters:
offset- the offset into the vector.length- the length of data in bytes to copy.- Returns:
- a byte array of the requested data.
- Throws:
IndexOutOfBoundsException- if offset plus length exceeds size.
-
getData
public void getData(int offset, byte[] out) Gets a subset of data from this buffer.- Parameters:
offset- the offset into the vector.out- the target array to copy into.- Throws:
IndexOutOfBoundsException- if offset plus length exceeds size.
-
getData
public void getData(int offset, byte[] out, int outOffset, int length) Gets a subset of data from this buffer.- Parameters:
offset- the offset into the vector.out- the target array to copy into.outOffset- the offset into the output buffer.length- the amount of bytes to copy.- Throws:
IndexOutOfBoundsException- if offset plus length exceeds size.
-
setData
public void setData(int offset, byte[] data) Sets a subset of data in this buffer.- Parameters:
offset- the offset into the vector.data- the data to overwrite with.- Throws:
IndexOutOfBoundsException- if offset plus length exceeds size.
-
getCapacity
public int getCapacity()Gets the capacity of this buffer.- Returns:
- the current capacity in bytes.
-
setCapacity
public void setCapacity(int capacity) Sets this buffer's capacity to some value. If this buffer is set to a capacity that is less than the current one, it will cut the buffer short. If the capacity argument is 0 or less, it is set to 1.- Parameters:
capacity- the new capacity of this buffer.
-
getCapacityIncrement
public int getCapacityIncrement()Returns the capacity increment value.- Returns:
- the current capacity increment.
-
setCapacityIncrement
public void setCapacityIncrement(int capacityInc) Sets the capacity increment value.- Parameters:
capacityInc- what to increase the capacity of this list by if this reaches the max. if 0 or less, it will double.
-
size
public int size()- Returns:
- the amount of bytes in the buffer.
-
isEmpty
public boolean isEmpty() -
append
Appends a byte to the end of this buffer.- Parameters:
b- the byte to add.- Returns:
- this buffer, so that these commands can be chained.
-
append
Appends a series of bytes to the end of this buffer.- Parameters:
b- the bytes to add.- Returns:
- this buffer, so that these commands can be chained.
-
append
Appends a series of bytes to the end of this buffer.- Parameters:
b- the bytes to add.offset- the offset into the array to start the copy.length- the amount of bytes to copy from the source array into the buffer.- Returns:
- this buffer, so that these commands can be chained.
-
insertAt
Inserts a series of bytes into this buffer at a specific index.- Parameters:
b- the bytes to add.startIndex- the starting index into the buffer for removing bytes.- Returns:
- this buffer, so that these commands can be chained.
-
delete
Deletes a series of bytes from this buffer.- Parameters:
startIndex- the starting index into the buffer for removing bytes.length- the amount of bytes to copy from the source array into the buffer.- Returns:
- this buffer, so that these commands can be chained.
-
clear
Deletes all bytes from this buffer.- Returns:
- this buffer, so that these commands can be chained.
-
capacityCheck
protected void capacityCheck(int additionalLength) Increases the size of the internal buffer if necessary.- Parameters:
additionalLength- the additional length that needs to be contained in the buffer.
-
toByteArray
public byte[] toByteArray()Returns the bytes in this vector into an array.- Returns:
- a new array with this list's data.
-
toString
-