Package com.iizix

Class IntArrayList

java.lang.Object
com.iizix.IntArrayList

public class IntArrayList extends Object
Class mimicking the behavior of ArrayList with Integer without collection support.

This class is NOT thread safe.

Author:
Christopher Mindus
  • Field Summary Link icon

    Fields
    Modifier and Type
    Field
    Description
    static final int[]
    Empty array.
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
    Creates an array with an initial capacity of 16.
    IntArrayList(int size)
    Creates an array with an initial capacity.
    IntArrayList(int[] values)
    Creates an array with a set of values.
    Creates an array from an ArrayList of Integer's.
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    void
    add(int value)
    Adds a value to the end of the array.
    void
    add(int index, int value)
    Adds a value to this list at the given index
    void
    addAll(int[] values)
    Adds an array of values to the end of this array.
    void
    Adds an array of values to the end of this array.
    void
    Clears the array, i.e.
    boolean
    contains(int value)
    Determines if this array contains a given value.
    void
    ensureCapacity(int minCapacity)
    Ensures that this list's capacity is at list the given value.
    int
    get(int index)
    Gets the value in the array at the given index.
    int
    indexOf(int value)
    Finds the index of a value in this array.
    int
    instanceCount(int value)
    Counts the number of times a value is represented in this array.
    boolean
    Checks if the array is empty.
    int
    lastIndexOf(int value)
    Finds the index of a value in this array from the array's tail.
    int
    remove(int index)
    Removes a value from this list
    int
    removeAll(int value)
    Removes all instances of the given value from this array.
    boolean
    removeValue(int value)
    Removes the first occurrence of a value from this array.
    int
    set(int index, int value)
    Replaces a value in this list with another value.
    int
    Returns the size of the array.
    int[]
    Returns a new array of the values in the array.
    Converts the array to an ArrayList of Integer's.
    Returns an array of Integer values of the array.
    void
    Trims this list so that it wastes no space and its capacity is equal to its size.

    Methods inherited from class java.lang.Object Link icon

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

    • EMPTY Link icon

      public static final int[] EMPTY
      Empty array.
  • Constructor Details Link icon

    • IntArrayList Link icon

      public IntArrayList()
      Creates an array with an initial capacity of 16.
    • IntArrayList Link icon

      public IntArrayList(int size)
      Creates an array with an initial capacity.
      Parameters:
      size - The initial capacity of the list.
    • IntArrayList Link icon

      public IntArrayList(int[] values)
      Creates an array with a set of values.
      Parameters:
      values - The values for the list.
    • IntArrayList Link icon

      public IntArrayList(ArrayList<Integer> list)
      Creates an array from an ArrayList of Integer's.
      Parameters:
      list - The ArrayList.
      Throws:
      NullPointerException - If any of the Integer items in the list is null.
  • Method Details Link icon

    • size Link icon

      public int size()
      Returns the size of the array.
      Returns:
      The number of elements in the array.
    • isEmpty Link icon

      public boolean isEmpty()
      Checks if the array is empty.
      Returns:
      Whether this list is empty of elements.
    • clear Link icon

      public void clear()
      Clears the array, i.e. setting its size to 0.
    • get Link icon

      public int get(int index)
      Gets the value in the array at the given index.
      Parameters:
      index - The index of the value to get.
      Returns:
      The value at the given index.
    • add Link icon

      public void add(int value)
      Adds a value to the end of the array.
      Parameters:
      value - The value to add to the array.
    • add Link icon

      public void add(int index, int value)
      Adds a value to this list at the given index
      Parameters:
      index - The index to add the value at
      value - The value to add to the list
    • addAll Link icon

      public void addAll(int[] values)
      Adds an array of values to the end of this array.
      Parameters:
      values - The values to add.
    • addAll Link icon

      public void addAll(IntArrayList list)
      Adds an array of values to the end of this array.
      Parameters:
      list - The list of values to add.
    • set Link icon

      public int set(int index, int value)
      Replaces a value in this list with another value.
      Parameters:
      index - The index of the value to replace.
      value - The value to replace the old value with.
      Returns:
      The old value at the given index.
    • remove Link icon

      public int remove(int index)
      Removes a value from this list
      Parameters:
      index - The index of the value to remove
      Returns:
      The value that was removed
    • removeValue Link icon

      public boolean removeValue(int value)
      Removes the first occurrence of a value from this array.
      Parameters:
      value - The value to remove.
      Returns:
      Whether the value was found and removed.
    • removeAll Link icon

      public int removeAll(int value)
      Removes all instances of the given value from this array.
      Parameters:
      value - The value to remove.
      Returns:
      The count of values removed.
    • contains Link icon

      public boolean contains(int value)
      Determines if this array contains a given value.
      Parameters:
      value - The value to find.
      Returns:
      Whether this array contains the given value.
    • instanceCount Link icon

      public int instanceCount(int value)
      Counts the number of times a value is represented in this array.
      Parameters:
      value - The value to count.
      Returns:
      The count of values in this array.
    • indexOf Link icon

      public int indexOf(int value)
      Finds the index of a value in this array.
      Parameters:
      value - The value to find.
      Returns:
      The first index whose value is the given value.
    • lastIndexOf Link icon

      public int lastIndexOf(int value)
      Finds the index of a value in this array from the array's tail.
      Parameters:
      value - The value to find.
      Returns:
      The last index whose value is the given value.
    • toArray Link icon

      public int[] toArray()
      Returns a new array of the values in the array.
      Returns:
      An array of values currently in this array.
    • toArrayList Link icon

      public ArrayList<Integer> toArrayList()
      Converts the array to an ArrayList of Integer's.
      Returns:
      A new instance of an ArrayList of Integer's.
    • toObjectArray Link icon

      public Integer[] toObjectArray()
      Returns an array of Integer values of the array.
      Returns:
      The array of values currently in this array as Integer's.
    • trimToSize Link icon

      public void trimToSize()
      Trims this list so that it wastes no space and its capacity is equal to its size.
    • ensureCapacity Link icon

      public void ensureCapacity(int minCapacity)
      Ensures that this list's capacity is at list the given value.
      Parameters:
      minCapacity - The minimum capacity for the list.