Class IntegerList

    • Constructor Detail

      • IntegerList

        public IntegerList​(int initialCapacity,
                           int maximalValue)
        Creates an initially empty list with the given initial capacity.
        Parameters:
        initialCapacity - The initial capacity.
        maximalValue - The maximal value to be allowed, inclusive.
      • IntegerList

        public IntegerList​(int initialCapacity,
                           int maximalValue,
                           boolean fill)
        Creates a new list with the given initial size. The value of all elements are initialized to 0.
        Parameters:
        initialCapacity - The initial capacity.
        maximalValue - The maximal value to be allowed, inclusive.
        fill - If true, the initial size is set to the initial capacity with all values set to 0.
    • Method Detail

      • maximalValue

        public int maximalValue()
        Returns the maximal value that can be stored in this list. May be slighly higher than the value given to the constructor.
        Returns:
        The maximal value, inclusive.
      • resize

        public void resize​(int size)
        Sets the list size to the given value. If the new size is lower than previous size, then the elements after the new size are discarted. If the new size is greater than the previous one, then the extra elements are initialized to 0.
        Parameters:
        size - The new size.
      • fill

        public void fill​(int value)
        Fills the list with the given value. Every existing values are overwritten from index 0 inclusive up to size exclusive.
        Parameters:
        value - The value to set.
      • addInteger

        public void addInteger​(int value)
                        throws IllegalArgumentException
        Adds the given element as the int primitive type.
        Parameters:
        value - The value to add.
        Throws:
        IllegalArgumentException - if the given value is out of bounds.
      • getInteger

        public int getInteger​(int index)
                       throws IndexOutOfBoundsException
        Returns the element at the given index as the int primitive type.
        Parameters:
        index - The element index.
        Returns:
        The value at the given index.
        Throws:
        IndexOutOfBoundsException - if the given index is out of bounds.
      • setInteger

        public void setInteger​(int index,
                               int value)
                        throws IndexOutOfBoundsException
        Sets the element at the given index as the int primitive type.
        Parameters:
        index - The element index.
        value - The value at the given index.
        Throws:
        IndexOutOfBoundsException - if the given index is out of bounds.
        IllegalArgumentException - if the given value is out of bounds.
      • occurence

        public int occurence​(int value)
        Returns the occurence of the given value in this list.
        Parameters:
        value - The value to search for.
        Returns:
        The number of time the given value occurs in this list.
      • trimToSize

        public void trimToSize()
        Trims the capacity of this list to be its current size.