Class IntegerBuffer

java.lang.Object
org.custommonkey.xmlunit.util.IntegerBuffer

public class IntegerBuffer extends Object
Simplistic dynamically growing buffer of integers used by DoctypeSupport.

No attempt has been made to make this class thread-safe at all. The append methods and indexOf are not too efficient either, but work for what we need.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int[]
     
    private int
     
    private static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new buffer.
    IntegerBuffer(int capacity)
    Creates a new buffer with the given initial capacity.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(int i)
    Appends a single int.
    void
    append(int[] i)
    Appends an array of ints.
    int
    Returns the current capacity (the size the buffer can use before it needs to grow).
    private void
     
    int
    indexOf(int[] sequence)
    finds sequence in current buffer.
    int
    Returns the current size.
    int[]
    Returns an array view of this buffer's content.

    Methods inherited from class java.lang.Object

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

    • INITIAL_SIZE

      private static final int INITIAL_SIZE
      See Also:
    • buffer

      private int[] buffer
    • currentSize

      private int currentSize
  • Constructor Details

    • IntegerBuffer

      public IntegerBuffer()
      Creates a new buffer.
    • IntegerBuffer

      public IntegerBuffer(int capacity)
      Creates a new buffer with the given initial capacity.
      Parameters:
      capacity - intitial capacity
  • Method Details

    • size

      public int size()
      Returns the current size.
      Returns:
      current size
    • capacity

      public int capacity()
      Returns the current capacity (the size the buffer can use before it needs to grow).
      Returns:
      current capacity
    • append

      public void append(int i)
      Appends a single int.
      Parameters:
      i - the int to append
    • append

      public void append(int[] i)
      Appends an array of ints.
      Parameters:
      i - the ints to append
    • toIntArray

      public int[] toIntArray()
      Returns an array view of this buffer's content.
      Returns:
      array view of this buffer's content
    • indexOf

      public int indexOf(int[] sequence)
      finds sequence in current buffer.
      Parameters:
      sequence - the sequence to find
      Returns:
      index of sequence or -1 if not found
    • grow

      private void grow()