Package com.iizix

Class IntArrayList


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

    This class is NOT thread safe.

    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static int[]EMPTY
      Empty array.
    • Constructor Summary

      Constructors 
      ConstructorDescription
      IntArrayList()
      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.
      IntArrayList​(java.util.ArrayList<java.lang.Integer> list)
      Creates an array from an ArrayList of Integer's.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voidadd​(int value)
      Adds a value to the end of the array.
      voidadd​(int index, int value)
      Adds a value to this list at the given index
      voidaddAll​(int[] values)
      Adds an array of values to the end of this array.
      voidaddAll​(IntArrayList list)
      Adds an array of values to the end of this array.
      voidclear()
      Clears the array, i.e.
      booleancontains​(int value)
      Determines if this array contains a given value.
      voidensureCapacity​(int minCapacity)
      Ensures that this list's capacity is at list the given value.
      intget​(int index)
      Gets the value in the array at the given index.
      intindexOf​(int value)
      Finds the index of a value in this array.
      intinstanceCount​(int value)
      Counts the number of times a value is represented in this array.
      booleanisEmpty()
      Checks if the array is empty.
      intlastIndexOf​(int value)
      Finds the index of a value in this array from the array's tail.
      intremove​(int index)
      Removes a value from this list
      intremoveAll​(int value)
      Removes all instances of the given value from this array.
      booleanremoveValue​(int value)
      Removes the first occurrence of a value from this array.
      intset​(int index, int value)
      Replaces a value in this list with another value.
      intsize()
      Returns the size of the array.
      int[]toArray()
      Returns a new array of the values in the array.
      java.util.ArrayList<java.lang.Integer>toArrayList()
      Converts the array to an ArrayList of Integer's.
      java.lang.Integer[]toObjectArray()
      Returns an array of Integer values of the array.
      voidtrimToSize()
      Trims this list so that it wastes no space and its capacity is equal to its size.
      • Methods inherited from class java.lang.Object

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

      • EMPTY

        public static final int[] EMPTY
        Empty array.
    • Constructor Detail

      • IntArrayList

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

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

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

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

      • size

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

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

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

        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

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

        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

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

        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

        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

        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

        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

        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

        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

        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

        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

        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

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

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

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

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

        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.