Class IntegerVector

java.lang.Object
com.mckoi.util.IntegerVector
All Implemented Interfaces:
Serializable

public final class IntegerVector extends Object implements Serializable
Similar to the Vector class, except this can only store integer values.

Author:
Tobias Downer
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    The index of the last value of the array.
    protected int[]
    The int array.
  • Constructor Summary

    Constructors
    Constructor
    Description
    The Constructors.
    IntegerVector(int initial_list_size)
     
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addInt(int val)
    Adds an int to the vector.
    Appends an IntegerVector to the end of the array.
    void
    Clears the object to be re-used.
    boolean
    contains(int val)
    Returns true if the vector contains the given value.
    void
    crop(int start, int end)
    Crops the IntegerVector so it only contains values between start (inclusive) and end (exclusive).
    boolean
    Returns true if this vector is equal to the given vector.
    int
    Returns the size of the vector.
    int
    indexOf(int val)
    Returns the first index of the given row in the array, or -1 if not found.
    void
    insertIntAt(int val, int pos)
    Inserts an int at the given position.
    int
    intAt(int pos)
    Returns the Int at the given position.
    boolean
    Test routine to check vector is sorted.
    int
    placeIntAt(int val, int pos)
    Places an int at the given position, overwriting anything that was previously there.
    final void
    Performs a quick sort on the entire vector.
    final void
    quickSort(int min, int max)
    Performs a quick sort on the array between the min and max bounds.
    void
    removeInt(int val)
    Removes the first Int found that matched the specified value.
    void
    removeIntAt(int pos)
    Removes an Int from the specified position in the list.
    void
    Reverses all the list of integers.
    int
    setIntAt(int val, int pos)
    Sets an int at the given position, overwriting anything that was previously there.
    int
    Returns the size of the vector.
    final int
    sortedIndexOf(int val)
    Searches the entire sorted list for the given value and returns the index of it.
    final int
    sortedIndexOf(int val, int lower, int higher)
    This is a very quick search for a value given a sorted array.
    final int
    sortedIntCount(int val)
    Given a sorted list, this will return the count of this value in the list.
    int[]
    Converts the vector into an int[] array.
    Converts the vector into a String.

    Methods inherited from class java.lang.Object

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

    • list

      protected int[] list
      The int array.
    • index

      protected int index
      The index of the last value of the array.
  • Constructor Details

    • IntegerVector

      public IntegerVector()
      The Constructors.
    • IntegerVector

      public IntegerVector(int initial_list_size)
    • IntegerVector

      public IntegerVector(IntegerVector vec)
    • IntegerVector

      public IntegerVector(IntegerListInterface i_list)
  • Method Details

    • addInt

      public void addInt(int val)
      Adds an int to the vector.
    • removeIntAt

      public void removeIntAt(int pos)
      Removes an Int from the specified position in the list.
    • removeInt

      public void removeInt(int val)
      Removes the first Int found that matched the specified value.
    • crop

      public void crop(int start, int end)
      Crops the IntegerVector so it only contains values between start (inclusive) and end (exclusive). So; crop({ 4, 5, 4, 3, 9, 7 }, 0, 3) would return {4, 5, 4) and, crop({ 4, 5, 4, 3, 9, 7 }, 3, 4) would return {3}
    • insertIntAt

      public void insertIntAt(int val, int pos)
      Inserts an int at the given position.
    • setIntAt

      public int setIntAt(int val, int pos)
      Sets an int at the given position, overwriting anything that was previously there. It returns the value that was previously at the element.
    • placeIntAt

      public int placeIntAt(int val, int pos)
      Places an int at the given position, overwriting anything that was previously there. It returns the value that was previously at the element. If 'pos' points to a place outside the bounds of the list then the list is expanded to include this value.
    • append

      public IntegerVector append(IntegerVector vec)
      Appends an IntegerVector to the end of the array. Returns this object.
    • intAt

      public int intAt(int pos)
      Returns the Int at the given position.
    • indexOf

      public int indexOf(int val)
      Returns the first index of the given row in the array, or -1 if not found.
    • contains

      public boolean contains(int val)
      Returns true if the vector contains the given value.
    • getSize

      public int getSize()
      Returns the size of the vector.
    • size

      public int size()
      Returns the size of the vector.
    • toIntArray

      public int[] toIntArray()
      Converts the vector into an int[] array.
    • clear

      public void clear()
      Clears the object to be re-used.
    • toString

      public String toString()
      Converts the vector into a String.
      Overrides:
      toString in class Object
    • equals

      public boolean equals(IntegerVector ivec)
      Returns true if this vector is equal to the given vector.
    • reverse

      public void reverse()
      Reverses all the list of integers. So integer[0] is swapped with integer[n - 1], integer[1] is swapped with integer[n - 2], etc where n is the size of the vector.
    • quickSort

      public final void quickSort(int min, int max)
      Performs a quick sort on the array between the min and max bounds.
    • quickSort

      public final void quickSort()
      Performs a quick sort on the entire vector.
    • sortedIndexOf

      public final int sortedIndexOf(int val, int lower, int higher)
      This is a very quick search for a value given a sorted array. The search is performed between the lower and higher bounds of the array. If the requested value is not found, it returns the index where the value should be 'inserted' to maintain a sorted list.
    • sortedIndexOf

      public final int sortedIndexOf(int val)
      Searches the entire sorted list for the given value and returns the index of it. If the value is not found, it returns the place in the list where the value should be insorted to maintain a sorted list.
    • sortedIntCount

      public final int sortedIntCount(int val)
      Given a sorted list, this will return the count of this value in the list. This uses a quick search algorithm so should be quite fast.
    • isSorted

      public boolean isSorted()
      Test routine to check vector is sorted.