Package com.mckoi.util

## Class IntegerVector

- java.lang.Object
- - com.mckoi.util.IntegerVector

All Implemented Interfaces:
  `java.io.Serializable`

    public final class IntegerVector
    extends java.lang.Object
    implements java.io.Serializable

Similar to the Vector class, except this can only store integer values.

Author:
  Tobias Downer
See Also:
  Serialized Form

### Field Summary

Fields
`protected int` `index` The index of the last value of the array.
`protected int[]` `list` The int array.

### Constructor Summary

Constructors
`IntegerVector()` The Constructors.
`IntegerVector​(int initial_list_size)`
`IntegerVector​(IntegerListInterface i_list)`
`IntegerVector​(IntegerVector vec)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `addInt​(int val)` Adds an int to the vector.
`IntegerVector` `append​(IntegerVector vec)` Appends an IntegerVector to the end of the array.
`void` `clear()` 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` `equals​(IntegerVector ivec)` Returns true if this vector is equal to the given vector.
`int` `getSize()` 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` `isSorted()` 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.
`void` `quickSort()` Performs a quick sort on the entire vector.
`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` `reverse()` 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` `size()` Returns the size of the vector.
`int` `sortedIndexOf​(int val)` Searches the entire sorted list for the given value and returns the index of it.
`int` `sortedIndexOf​(int val, int lower, int higher)` This is a very quick search for a value given a sorted array.
`int` `sortedIntCount​(int val)` Given a sorted list, this will return the count of this value in the list.
`int[]` `toIntArray()` Converts the vector into an int[] array.
`java.lang.String` `toString()` Converts the vector into a String.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### list

    protected int[] list

The int array.

#### index

    protected int index

The index of the last value of the array.

### Constructor Detail

#### IntegerVector

    public IntegerVector()

The Constructors.

#### IntegerVector

    public IntegerVector​(int initial_list_size)

#### IntegerVector

    public IntegerVector​(IntegerVector vec)

#### IntegerVector

    public IntegerVector​(IntegerListInterface i_list)

### Method Detail

#### 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 java.lang.String toString()

Converts the vector into a String.

Overrides:
  `toString` in class `java.lang.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.