Class IntegerArray

    • Field Summary

      Fields 
      Modifier and Type Field Description
      int[] data
      (Reused) store for numerical attributes.
      private static int LAST_GROW_SIZE
      Last value where we can grow by 50%.
      private static int MAX_ARRAY_SIZE
      Maximum array size permitted by Java.
      int size
      Number of numerical attributes.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int attribute)
      Append a value.
      void clear()
      Reset the numeric attribute counter.
      int get​(int pos)
      Get the value at this position.
      java.lang.Integer get​(IntegerArray array, int off)
      Get the off'th item from the array.
      byte getByte​(IntegerArray array, int off)
      Get the off'th item from the array as byte.
      double getDouble​(IntegerArray array, int off)
      Get the off'th item from the array as double.
      float getFloat​(IntegerArray array, int off)
      Get the off'th item from the array as float.
      int getInteger​(IntegerArray array, int off)
      Get the off'th item from the array as integer.
      long getLong​(IntegerArray array, int off)
      Get the off'th item from the array as long.
      short getShort​(IntegerArray array, int off)
      Get the off'th item from the array as short.
      private void grow()
      Grow the current array.
      void insert​(int pos, int val)
      Insert a value at the given position.
      boolean isEmpty()
      Test if the array is empty.
      void remove​(int start, int len)
      Remove a range from the array.
      void set​(int pos, int value)
      Set the value at this position.
      int size()
      Get the size of the array.
      int size​(IntegerArray array)
      Get the size of the array.
      void sort()
      Sort the contents.
      void swap​(int p1, int p2)
      Swap two values.
      int[] toArray()
      Return a copy of the contents as array.
      • Methods inherited from class java.lang.Object

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

      • MAX_ARRAY_SIZE

        private static final int MAX_ARRAY_SIZE
        Maximum array size permitted by Java.

        This is JVM dependent, but 2^31 - 5 is the usual OpenJDK8 value.

        See Also:
        Constant Field Values
      • LAST_GROW_SIZE

        private static final int LAST_GROW_SIZE
        Last value where we can grow by 50%.
        See Also:
        Constant Field Values
      • data

        public int[] data
        (Reused) store for numerical attributes.
      • size

        public int size
        Number of numerical attributes.
    • Constructor Detail

      • IntegerArray

        public IntegerArray()
        Constructor.
      • IntegerArray

        public IntegerArray​(int initialsize)
        Constructor.
        Parameters:
        initialsize - Initial size.
      • IntegerArray

        public IntegerArray​(IntegerArray existing)
        Constructor from an existing array.

        The new array will be allocated as small as possible, so modifications will cause a resize!

        Parameters:
        existing - Existing array
    • Method Detail

      • clear

        public void clear()
        Reset the numeric attribute counter.
      • add

        public void add​(int attribute)
        Append a value.
        Parameters:
        attribute - Attribute value.
      • grow

        private void grow()
                   throws java.lang.OutOfMemoryError
        Grow the current array.
        Throws:
        java.lang.OutOfMemoryError
      • get

        public int get​(int pos)
        Get the value at this position.
        Parameters:
        pos - Position
        Returns:
        Value
      • set

        public void set​(int pos,
                        int value)
        Set the value at this position.
        Parameters:
        pos - Position
        value - Value
      • swap

        public void swap​(int p1,
                         int p2)
        Swap two values.
        Parameters:
        p1 - First position
        p2 - Second position
      • remove

        public void remove​(int start,
                           int len)
        Remove a range from the array.
        Parameters:
        start - Start
        len - Length
      • insert

        public void insert​(int pos,
                           int val)
        Insert a value at the given position.
        Parameters:
        pos - Insert position
        val - Value to insert
      • size

        public int size()
        Get the size of the array.
        Returns:
        Size
      • isEmpty

        public boolean isEmpty()
        Test if the array is empty.
        Returns:
        true if empty.
      • sort

        public void sort()
        Sort the contents.
      • get

        public java.lang.Integer get​(IntegerArray array,
                                     int off)
                              throws java.lang.IndexOutOfBoundsException
        Description copied from interface: ArrayAdapter
        Get the off'th item from the array.
        Specified by:
        get in interface ArrayAdapter<java.lang.Integer,​IntegerArray>
        Specified by:
        get in interface NumberArrayAdapter<java.lang.Integer,​IntegerArray>
        Parameters:
        array - Array to get from
        off - Offset
        Returns:
        Item at offset off
        Throws:
        java.lang.IndexOutOfBoundsException - for an invalid index.
      • getDouble

        public double getDouble​(IntegerArray array,
                                int off)
                         throws java.lang.IndexOutOfBoundsException
        Description copied from interface: NumberArrayAdapter
        Get the off'th item from the array as double.
        Specified by:
        getDouble in interface NumberArrayAdapter<java.lang.Integer,​IntegerArray>
        Parameters:
        array - Array to get from
        off - Offset
        Returns:
        Item at offset off
        Throws:
        java.lang.IndexOutOfBoundsException - for an invalid index.
      • getFloat

        public float getFloat​(IntegerArray array,
                              int off)
                       throws java.lang.IndexOutOfBoundsException
        Description copied from interface: NumberArrayAdapter
        Get the off'th item from the array as float.
        Specified by:
        getFloat in interface NumberArrayAdapter<java.lang.Integer,​IntegerArray>
        Parameters:
        array - Array to get from
        off - Offset
        Returns:
        Item at offset off
        Throws:
        java.lang.IndexOutOfBoundsException - for an invalid index.
      • getInteger

        public int getInteger​(IntegerArray array,
                              int off)
                       throws java.lang.IndexOutOfBoundsException
        Description copied from interface: NumberArrayAdapter
        Get the off'th item from the array as integer.
        Specified by:
        getInteger in interface NumberArrayAdapter<java.lang.Integer,​IntegerArray>
        Parameters:
        array - Array to get from
        off - Offset
        Returns:
        Item at offset off
        Throws:
        java.lang.IndexOutOfBoundsException - for an invalid index.
      • getShort

        public short getShort​(IntegerArray array,
                              int off)
                       throws java.lang.IndexOutOfBoundsException
        Description copied from interface: NumberArrayAdapter
        Get the off'th item from the array as short.
        Specified by:
        getShort in interface NumberArrayAdapter<java.lang.Integer,​IntegerArray>
        Parameters:
        array - Array to get from
        off - Offset
        Returns:
        Item at offset off
        Throws:
        java.lang.IndexOutOfBoundsException - for an invalid index.
      • getLong

        public long getLong​(IntegerArray array,
                            int off)
                     throws java.lang.IndexOutOfBoundsException
        Description copied from interface: NumberArrayAdapter
        Get the off'th item from the array as long.
        Specified by:
        getLong in interface NumberArrayAdapter<java.lang.Integer,​IntegerArray>
        Parameters:
        array - Array to get from
        off - Offset
        Returns:
        Item at offset off
        Throws:
        java.lang.IndexOutOfBoundsException - for an invalid index.
      • getByte

        public byte getByte​(IntegerArray array,
                            int off)
                     throws java.lang.IndexOutOfBoundsException
        Description copied from interface: NumberArrayAdapter
        Get the off'th item from the array as byte.
        Specified by:
        getByte in interface NumberArrayAdapter<java.lang.Integer,​IntegerArray>
        Parameters:
        array - Array to get from
        off - Offset
        Returns:
        Item at offset off
        Throws:
        java.lang.IndexOutOfBoundsException - for an invalid index.
      • toArray

        public int[] toArray()
        Return a copy of the contents as array.
        Returns:
        Copy of the contents.