Class IntList


  • public class IntList
    extends Object
    A specific implementation for list of integers. Created by cprudhom on 20/10/2015. Project: choco.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntList()
      Constructs an empty list with the initial capacity of 10
      IntList​(int initialCapacity)
      Constructs an empty list with the specified initial capacity.
      IntList​(int... values)
      Constructs a list containing the elements of values.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(int element)
      Appends the specified element to the end of this list.
      boolean addAll​(IntList list)
      Appends the elements of the specified list to the end of this list.
      boolean addAt​(int index, int element)
      Add the element at the specified position in this list.
      void clear()
      The list will be empty after this call returns.
      int get​(int index)
      Returns the element at the specified position in this list.
      int getQuick​(int index)
      Returns the element at the specified position in this list without doing any bounds checking.
      boolean isEmpty()
      Returns true if this list contains no elements.
      boolean remove​(int value)
      Removes the first occurrence of the specified element from this list, if it is present.
      void removeAt​(int index)
      Removes the element at the specified position in this list.
      void removeRange​(int fromIndex, int toIndex)
      Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive.
      void replace​(int index, int element)
      Replaces the element at the specified position in this list with the specified element.
      void replaceQuick​(int index, int element)
      Replaces the element at the specified position in this list with the specified element without doing any bounds checking.
      int size()
      Returns the number of elements in this list.
      int[] toArray()
      Returns an array containing all of the elements in this list in proper sequence (from first to last element).
    • Constructor Detail

      • IntList

        public IntList()
        Constructs an empty list with the initial capacity of 10
      • IntList

        public IntList​(int initialCapacity)
        Constructs an empty list with the specified initial capacity.
      • IntList

        public IntList​(int... values)
        Constructs a list containing the elements of values.
        Parameters:
        values - the values that are to be placed in this list
    • Method Detail

      • size

        public int size()
        Returns the number of elements in this list.
        Returns:
        the number of elements in this list.
      • isEmpty

        public boolean isEmpty()
        Returns true if this list contains no elements.
        Returns:
        true if this list contains no elements.
      • get

        public int get​(int index)
        Returns the element at the specified position in this list.
        Parameters:
        index - index of the element to return
        Returns:
        the element at the specified position in this list.
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • getQuick

        public int getQuick​(int index)
        Returns the element at the specified position in this list without doing any bounds checking.
        Parameters:
        index - index of the element to return
        Returns:
        the element at the specified position in this list.
      • replace

        public void replace​(int index,
                            int element)
        Replaces the element at the specified position in this list with the specified element.
        Parameters:
        index - index of the element to replace
        element - element to be stored at the specified position
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • replaceQuick

        public void replaceQuick​(int index,
                                 int element)
        Replaces the element at the specified position in this list with the specified element without doing any bounds checking.
        Parameters:
        index - index of the element to replace
        element - element to be stored at the specified position
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • add

        public boolean add​(int element)
        Appends the specified element to the end of this list.
        Parameters:
        element - element to be appended to this list
        Returns:
        true if this list changed as a result of the call
      • addAt

        public boolean addAt​(int index,
                             int element)
        Add the element at the specified position in this list.
        Parameters:
        index - index of the element to put
        element - element to be stored at the specified position
      • addAll

        public boolean addAll​(IntList list)
        Appends the elements of the specified list to the end of this list.
        Parameters:
        list - elements to be appended to this list
        Returns:
        true if this list changed as a result of the call
      • remove

        public boolean remove​(int value)
        Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged.
        Parameters:
        value - element to be removed from this list, if present
        Returns:
        true if this list contained the specified element
      • removeAt

        public void removeAt​(int index)
        Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices).
        Parameters:
        index - the index of the element to be removed
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • removeRange

        public void removeRange​(int fromIndex,
                                int toIndex)
        Removes from this list all of the elements whose index is between fromIndex, inclusive, and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)
        Throws:
        IndexOutOfBoundsException - if fromIndex or toIndex is out of range (fromIndex < 0 || fromIndex >= size() || toIndex > size() || toIndex < fromIndex)
      • clear

        public void clear()
        The list will be empty after this call returns. But no value is removed, only the size is reset to 0.
      • toArray

        public int[] toArray()
        Returns an array containing all of the elements in this list in proper sequence (from first to last element).

        The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.

        Returns:
        an array containing all of the elements in this list in proper sequence