Class PageIndex

java.lang.Object
org.htmlparser.lexer.PageIndex
All Implemented Interfaces:
Serializable, Sortable

public class PageIndex extends Object implements Serializable, Sortable
A sorted array of integers, the positions of the first characters of each line. To facilitate processing the first element should be maintained at position 0. Facilities to add, remove, search and determine row and column are provided. This class provides similar functionality to a Vector but does not incur the overhead of an Integer object per element.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The number of valid elements.
    protected int
    Increment for allocations.
    protected int[]
    The elements.
    protected Page
    The page associated with this index.
    protected static final int
    Starting increment for allocations.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an empty index.
    PageIndex(Page page, int cursor)
    Create an index with the one element given.
    PageIndex(Page page, int[] cursors)
    Create an index with the elements given.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    add(int cursor)
    Add an element to the list
    int
    add(Cursor cursor)
    Add an element to the list
    protected int
    bsearch(int cursor)
    Binary search for the element.
    protected int
    bsearch(int cursor, int first, int last)
    Binary search for the element.
    int
    Get the capacity for elements without reallocation.
    int
    column(int cursor)
    Get the column number for a position.
    int
    column(Cursor cursor)
    Get the column number for a cursor.
    int
    elementAt(int index)
    Get an element from the list.
    fetch(int index, Ordered reuse)
    Fetch the object at the given index.
    int
    Returns the first index of the Sortable.
    int[]
    get()
    Get the elements as an array of int.
    Get this index's page.
    protected void
    insertElementAt(int cursor, int index)
    Inserts an element into the list.
    int
    Returns the last index of the Sortable.
    void
    remove(int cursor)
    Remove an element from the list
    void
    remove(Cursor cursor)
    Remove an element from the list
    protected void
    removeElementAt(int index)
    Remove an element from the list.
    int
    row(int cursor)
    Get the line number for a position.
    int
    row(Cursor cursor)
    Get the line number for a cursor.
    int
    Get the count of elements.
    void
    swap(int i, int j)
    Swaps the elements at the given indicies.

    Methods inherited from class java.lang.Object

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

    • mStartIncrement

      protected static final int mStartIncrement
      Starting increment for allocations.
      See Also:
    • mIncrement

      protected int mIncrement
      Increment for allocations.
    • mCount

      protected int mCount
      The number of valid elements.
    • mIndices

      protected int[] mIndices
      The elements.
    • mPage

      protected Page mPage
      The page associated with this index.
  • Constructor Details

    • PageIndex

      public PageIndex(Page page)
      Create an empty index.
      Parameters:
      page - The page associated with this index.
    • PageIndex

      public PageIndex(Page page, int cursor)
      Create an index with the one element given.
      Parameters:
      page - The page associated with this index.
      cursor - The single element for the new index.
    • PageIndex

      public PageIndex(Page page, int[] cursors)
      Create an index with the elements given.
      Parameters:
      page - The page associated with this index.
      cursors - The initial elements of the index. NOTE: The list must be sorted in ascending order.
  • Method Details

    • getPage

      public Page getPage()
      Get this index's page.
      Returns:
      The page associated with this index.
    • size

      public int size()
      Get the count of elements.
      Returns:
      The number of valid elements.
    • capacity

      public int capacity()
      Get the capacity for elements without reallocation.
      Returns:
      The number of spaces for elements.
    • add

      public int add(Cursor cursor)
      Add an element to the list
      Parameters:
      cursor - The element to add.
      Returns:
      The position at which the element was inserted or the index of the existing element if it is a duplicate.
    • add

      public int add(int cursor)
      Add an element to the list
      Parameters:
      cursor - The element to add.
      Returns:
      The position at which the element was inserted or the index of the existing element if it is a duplicate.
    • remove

      public void remove(Cursor cursor)
      Remove an element from the list
      Parameters:
      cursor - The element to remove.
    • remove

      public void remove(int cursor)
      Remove an element from the list
      Parameters:
      cursor - The element to remove.
    • elementAt

      public int elementAt(int index)
      Get an element from the list.
      Parameters:
      index - The index of the element to get.
      Returns:
      The element.
    • row

      public int row(Cursor cursor)
      Get the line number for a cursor.
      Parameters:
      cursor - The character offset into the page.
      Returns:
      The line number the character is in.
    • row

      public int row(int cursor)
      Get the line number for a position.
      Parameters:
      cursor - The character offset into the page.
      Returns:
      The line number the character is in.
    • column

      public int column(Cursor cursor)
      Get the column number for a cursor.
      Parameters:
      cursor - The character offset into the page.
      Returns:
      The character offset into the line this cursor is on.
    • column

      public int column(int cursor)
      Get the column number for a position.
      Parameters:
      cursor - The character offset into the page.
      Returns:
      The character offset into the line this cursor is on.
    • get

      public int[] get()
      Get the elements as an array of int.
      Returns:
      A new array containing the elements, i.e. a snapshot of the index.
    • bsearch

      protected int bsearch(int cursor)
      Binary search for the element.
      Parameters:
      cursor - The element to search for.
      Returns:
      The index at which the element was found or is to be inserted.
    • bsearch

      protected int bsearch(int cursor, int first, int last)
      Binary search for the element.
      Parameters:
      cursor - The element to search for.
      first - The index to start at.
      last - The index to stop at.
      Returns:
      The index at which the element was found or is to be inserted.
    • insertElementAt

      protected void insertElementAt(int cursor, int index)
      Inserts an element into the list. The index must be a value greater than or equal to 0 and less than or equal to the current size of the array.
      Parameters:
      cursor - The element to insert.
      index - The index in the list to insert it at.
    • removeElementAt

      protected void removeElementAt(int index)
      Remove an element from the list.
      Parameters:
      index - The index of the item to remove.
    • first

      public int first()
      Returns the first index of the Sortable.
      Specified by:
      first in interface Sortable
      Returns:
      The index of the first element.
    • last

      public int last()
      Returns the last index of the Sortable.
      Specified by:
      last in interface Sortable
      Returns:
      The index of the last element. If this were an array object this would be (object.length - 1). For an empty index this will return -1.
    • fetch

      public Ordered fetch(int index, Ordered reuse)
      Fetch the object at the given index.
      Specified by:
      fetch in interface Sortable
      Parameters:
      index - The item number to get.
      reuse - If this argument is not null, it is an object acquired from a previous fetch that is no longer needed and may be returned as the result if it makes mores sense to alter and return it than to fetch or create a new element. That is, the reuse object is garbage and may be used to avoid allocating a new object if that would normally be the strategy.
      Returns:
      The Ordered object at that index.
    • swap

      public void swap(int i, int j)
      Swaps the elements at the given indicies.
      Specified by:
      swap in interface Sortable
      Parameters:
      i - One index.
      j - The other index.