Class ByteList

All Implemented Interfaces:
Cloneable, Iterable<Byte>, Collection<Byte>, List<Byte>, ByteOrderedIterable

public class ByteList extends AbstractList<Byte> implements ByteOrderedIterable, Cloneable
A list of byte primitives.

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 Details

    • DEFAULT_CAPACITY

      public static final int DEFAULT_CAPACITY
      The default capacity value.
      See Also:
    • DEFAULT_NULL_VALUE

      public static final byte DEFAULT_NULL_VALUE
      The default "null" value.
      See Also:
  • Constructor Details

    • ByteList

      public ByteList()
      Default constructor.

      The DEFAULT_CAPACITY and DEFAULT_NULL_VALUE values will be used.

    • ByteList

      public ByteList(int capacity)
      Constructor.

      The DEFAULT_NULL_VALUE will be used.

      Parameters:
      capacity - the initial capacity
    • ByteList

      public ByteList(int capacity, byte nullValue)
      Creates a new TByteArrayList instance with the specified capacity.
      Parameters:
      capacity - the initial capacity
      nullValue - the value that represents null
    • ByteList

      public ByteList(byte[] values)
      Constructor.

      The DEFAULT_NULL_VALUE will 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 copied
      nullValue - the value that represents null
    • ByteList

      public ByteList(Collection<Byte> other)
      Copy constructor.
      Parameters:
      other - the list to copy
  • Method Details

    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • forEachOrdered

      public void forEachOrdered(ByteConsumer action)
      Description copied from interface: ByteOrderedIterable
      Iterate over all primitive values in this collection.

      This method of iteration can be more efficient than iterating via the Iterator API because no unboxing of primitives is necessary.

      Specified by:
      forEachOrdered in interface ByteOrderedIterable
      Parameters:
      action - the consumer to handle the values
    • forEachOrdered

      public void forEachOrdered(int min, int max, ByteConsumer action)
      Description copied from interface: ByteOrderedIterable
      Iterate over a range of values in this collection.

      This method of iteration can be more efficient than iterating via the Iterator API because no unboxing of primitives is necessary.

      Specified by:
      forEachOrdered in interface ByteOrderedIterable
      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:
      size in interface Collection<Byte>
      Specified by:
      size in interface List<Byte>
      Specified by:
      size in class AbstractCollection<Byte>
    • getCapacity

      public int getCapacity()
      Get the current capacity.
      Returns:
      the capacity
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<Byte>
      Specified by:
      isEmpty in interface List<Byte>
      Overrides:
      isEmpty in class AbstractCollection<Byte>
    • get

      public Byte get(int index)
      Specified by:
      get in interface List<Byte>
      Specified by:
      get in class AbstractList<Byte>
    • 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 - if index is out of bounds
    • getNullValue

      public byte getNullValue()
      Get the byte value used for "null".
      Returns:
      the null value
    • add

      public boolean add(Byte e)
      Specified by:
      add in interface Collection<Byte>
      Specified by:
      add in interface List<Byte>
      Overrides:
      add in class AbstractList<Byte>
    • add

      public boolean add(byte b)
      Add a byte.
      Parameters:
      b - the byte to add
      Returns:
      true if the byte was added
    • add

      public void add(int index, Byte element)
      Specified by:
      add in interface List<Byte>
      Overrides:
      add in class AbstractList<Byte>
    • addAll

      public boolean addAll(int index, Collection<? extends Byte> c)
      Specified by:
      addAll in interface List<Byte>
      Overrides:
      addAll in class AbstractList<Byte>
    • 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 right
      src - the array to copy bytes from
      srcPos - the position in src to start copying from
      length - 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 from
      srcPos - the position within vals to start copying from
      length - 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 from
      length - 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 from
      dest - the destination to copy the bytes to
      destPos - the position in dest to start copying to
      length - the number of bytes to copy
      Throws:
      ArrayIndexOutOfBoundsException - if index or length are out of bounds
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<Byte>
      Specified by:
      clear in interface List<Byte>
      Overrides:
      clear in class AbstractList<Byte>
    • remove

      public Byte remove(int index)
      Specified by:
      remove in interface List<Byte>
      Overrides:
      remove in class AbstractList<Byte>
    • removeRange

      protected void removeRange(int fromIndex, int toIndex)
      Overrides:
      removeRange in class AbstractList<Byte>
    • remove

      public void remove(int index, int length)
      Remove a range of bytes.
      Parameters:
      index - the position to start removing from
      length - the number of bytes to remove
      Throws:
      ArrayIndexOutOfBoundsException - if index or length are out of bounds