Class ByteList
- All Implemented Interfaces:
Cloneable,Iterable<Byte>,Collection<Byte>,List<Byte>,ByteOrderedIterable
The ByteOrderedIterable API has been adopted by this class such that
iteration ordering is the same as array ordering. That is, order is by array
indexes, not array values.
This class has been adapted from the
GNU Trove
project's gnu.trove.list.array.TByteArrayList class, which is
released under the LGPL 2.1 licence.
- Since:
- 1.58
- Version:
- 1.0
- Author:
- matt
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default capacity value.static final byteThe default "null" value.Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionByteList()Default constructor.ByteList(byte[] values) Constructor.ByteList(byte[] values, byte nullValue) Constructor.ByteList(int capacity) Constructor.ByteList(int capacity, byte nullValue) Creates a newTByteArrayListinstance with the specified capacity.ByteList(Collection<Byte> other) -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(byte b) Add a byte.voidadd(byte[] src, int srcPos, int length) Add an array of bytes.voidbooleanvoidaddAll(byte[] src) Add an array of bytes.booleanaddAll(int index, byte[] src, int srcPos, int length) Add values from a byte array to this list.booleanaddAll(int index, Collection<? extends Byte> c) voidclear()protected Objectclone()voidcopy(int index, byte[] dest, int destPos, int length) Copy a range of bytes onto a byte array.voidforEachOrdered(int min, int max, ByteConsumer action) Iterate over a range of values in this collection.voidforEachOrdered(ByteConsumer action) Iterate over all primitive values in this collection.get(int index) intGet the current capacity.byteGet the byte value used for "null".bytegetValue(int index) Get the byte at a given index.booleanisEmpty()remove(int index) voidremove(int index, int length) Remove a range of bytes.protected voidremoveRange(int fromIndex, int toIndex) intsize()byte[]slice(int index, int length) Get a copied subset of bytes in this list.byte[]Get a copy of the bytes in this list.Methods inherited from class java.util.AbstractList
equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, set, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, contains, containsAll, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Field Details
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYThe default capacity value.- See Also:
-
DEFAULT_NULL_VALUE
public static final byte DEFAULT_NULL_VALUEThe default "null" value.- See Also:
-
-
Constructor Details
-
ByteList
public ByteList()Default constructor.The
DEFAULT_CAPACITYandDEFAULT_NULL_VALUEvalues will be used. -
ByteList
public ByteList(int capacity) Constructor.The
DEFAULT_NULL_VALUEwill be used.- Parameters:
capacity- the initial capacity
-
ByteList
public ByteList(int capacity, byte nullValue) Creates a newTByteArrayListinstance with the specified capacity.- Parameters:
capacity- the initial capacitynullValue- the value that represents null
-
ByteList
public ByteList(byte[] values) Constructor.The
DEFAULT_NULL_VALUEwill be used.- Parameters:
values- the initial content to add to this list; the values are copied
-
ByteList
public ByteList(byte[] values, byte nullValue) Constructor.- Parameters:
values- the initial content to add to this list; the values are copiednullValue- the value that represents null
-
ByteList
-
-
Method Details
-
clone
- Overrides:
clonein classObject- Throws:
CloneNotSupportedException
-
forEachOrdered
Description copied from interface:ByteOrderedIterableIterate over all primitive values in this collection.This method of iteration can be more efficient than iterating via the
IteratorAPI because no unboxing of primitives is necessary.- Specified by:
forEachOrderedin interfaceByteOrderedIterable- Parameters:
action- the consumer to handle the values
-
forEachOrdered
Description copied from interface:ByteOrderedIterableIterate over a range of values in this collection.This method of iteration can be more efficient than iterating via the
IteratorAPI because no unboxing of primitives is necessary.- Specified by:
forEachOrderedin interfaceByteOrderedIterable- Parameters:
min- the minimum key value (inclusive)max- the maximum key value (exclusive)action- the consumer to handle the values
-
size
public int size()- Specified by:
sizein interfaceCollection<Byte>- Specified by:
sizein interfaceList<Byte>- Specified by:
sizein classAbstractCollection<Byte>
-
getCapacity
public int getCapacity()Get the current capacity.- Returns:
- the capacity
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<Byte>- Specified by:
isEmptyin interfaceList<Byte>- Overrides:
isEmptyin classAbstractCollection<Byte>
-
get
-
getValue
public byte getValue(int index) Get the byte at a given index.- Parameters:
index- the index of the byte to get- Returns:
- the byte
- Throws:
ArrayIndexOutOfBoundsException- ifindexis out of bounds
-
getNullValue
public byte getNullValue()Get the byte value used for "null".- Returns:
- the null value
-
add
- Specified by:
addin interfaceCollection<Byte>- Specified by:
addin interfaceList<Byte>- Overrides:
addin classAbstractList<Byte>
-
add
public boolean add(byte b) Add a byte.- Parameters:
b- the byte to add- Returns:
- true if the byte was added
-
add
-
addAll
-
addAll
public boolean addAll(int index, byte[] src, int srcPos, int length) Add values from a byte array to this list.- Parameters:
index- the index to insert the copied bytes at; all existing elements starting at this index will be shifted to the rightsrc- the array to copy bytes fromsrcPos- the position insrcto start copying fromlength- the number of bytes to copy- Returns:
- true if all bytes were copied
-
addAll
public void addAll(byte[] src) Add an array of bytes.- Parameters:
src- the bytes to add
-
add
public void add(byte[] src, int srcPos, int length) Add an array of bytes.- Parameters:
src- the array to copy bytes fromsrcPos- the position withinvalsto start copying fromlength- the number of bytes to copy
-
toArrayValue
public byte[] toArrayValue()Get a copy of the bytes in this list.- Returns:
- the copied array of bytes
-
slice
public byte[] slice(int index, int length) Get a copied subset of bytes in this list.- Parameters:
index- the position in this list to start copying fromlength- the number of bytes to copy- Returns:
- the new array of bytes
-
copy
public void copy(int index, byte[] dest, int destPos, int length) Copy a range of bytes onto a byte array.- Parameters:
index- the position in this list to start copying fromdest- the destination to copy the bytes todestPos- the position indestto start copying tolength- the number of bytes to copy- Throws:
ArrayIndexOutOfBoundsException- ifindexorlengthare out of bounds
-
clear
public void clear()- Specified by:
clearin interfaceCollection<Byte>- Specified by:
clearin interfaceList<Byte>- Overrides:
clearin classAbstractList<Byte>
-
remove
-
removeRange
protected void removeRange(int fromIndex, int toIndex) - Overrides:
removeRangein classAbstractList<Byte>
-
remove
public void remove(int index, int length) Remove a range of bytes.- Parameters:
index- the position to start removing fromlength- the number of bytes to remove- Throws:
ArrayIndexOutOfBoundsException- ifindexorlengthare out of bounds
-