Class DataList


  • public class DataList
    extends Object
    A mutable buffer of data.
    Author:
    Matthew Tropiano
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_CAPACITY
      Default capacity for a new list.
    • Constructor Summary

      Constructors 
      Constructor Description
      DataList()
      Makes a new volatile list.
      DataList​(int capacity)
      Makes a new buffer that doubles every resize.
      DataList​(int capacity, int capacityInc)
      Makes a new buffer.
    • Field Detail

      • DEFAULT_CAPACITY

        public static final int DEFAULT_CAPACITY
        Default capacity for a new list.
        See Also:
        Constant Field Values
    • Constructor Detail

      • 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 Detail

      • 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.
      • 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

        public DataList append​(byte b)
        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

        public DataList append​(byte[] b)
        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

        public DataList append​(byte[] b,
                               int offset,
                               int length)
        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

        public DataList insertAt​(byte[] b,
                                 int startIndex)
        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

        public DataList delete​(int startIndex,
                               int length)
        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

        public DataList clear()
        Deletes all bytes from this buffer.
        Returns:
        this buffer, so that these commands can be chained.
      • capacityCheck

        protected void capacityCheck​(int requiredLength)
        Increases the size of the internal buffer if necessary.
        Parameters:
        requiredLength - the required length that the buffer needs to be.
      • toByteArray

        public byte[] toByteArray()
        Returns the bytes in this vector into an array.
        Returns:
        a new array with this list's data.