Class DataList

java.lang.Object
net.mtrop.doom.struct.DataList

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

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

    Constructors
    Constructor
    Description
    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.
  • Method Summary

    Modifier and Type
    Method
    Description
    append(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 void
    capacityCheck(int additionalLength)
    Increases the size of the internal buffer if necessary.
    Deletes all bytes from this buffer.
    delete(int startIndex, int length)
    Deletes a series of bytes from this buffer.
    int
    Gets the capacity of this buffer.
    int
    Returns the capacity increment value.
    byte
    getData(int index)
    Gets a byte of data from this buffer.
    void
    getData(int offset, byte[] out)
    Gets a subset of data from this buffer.
    void
    getData(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.
    boolean
     
    void
    setCapacity(int capacity)
    Sets this buffer's capacity to some value.
    void
    setCapacityIncrement(int capacityInc)
    Sets the capacity increment value.
    void
    setData(int offset, byte[] data)
    Sets a subset of data in this buffer.
    int
     
    byte[]
    Returns the bytes in this vector into an array.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • DEFAULT_CAPACITY

      public static final int DEFAULT_CAPACITY
      Default 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

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

      public String toString()
      Overrides:
      toString in class Object