Class RArray

  • Direct Known Subclasses:
    RLongArray, RUByteArray, RUIntArray, RUShortArray

    public abstract class RArray
    extends Object

    Abstract superclass for resizeable integer arrays. Although values are retrieved and set using long integers, the underlying storage may be any data type.

    GNU Trove implements similar classes with more sophisticated features, but the internal array doubles in capacity with each resize operation. This class grows the internal array linearly, by a constant amount each time. Hence the number of elements in the internal storage array is never greater than size() + chunkSize - 1.

    Author:
    Jon Blower
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int chunkSize  
      protected int size  
      protected Object storage  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected RArray​(int chunkSize)
      Creates an array in which the initial capacity is set the same as the chunk size.
      protected RArray​(int initialCapacity, int chunkSize)
      Creates an array with the given initial capacity and chunk size.
    • Field Detail

      • size

        protected int size
      • chunkSize

        protected final int chunkSize
      • storage

        protected Object storage
    • Constructor Detail

      • RArray

        protected RArray​(int chunkSize)
        Creates an array in which the initial capacity is set the same as the chunk size.
      • RArray

        protected RArray​(int initialCapacity,
                         int chunkSize)
        Creates an array with the given initial capacity and chunk size.
        Parameters:
        initialCapacity - The number of elements in the storage array
        chunkSize - The number of storage elements that will be added each time the storage array grows.
    • Method Detail

      • makeStorage

        protected abstract Object makeStorage​(int capacity)
      • getStorageLength

        protected abstract int getStorageLength()
      • setElement

        protected abstract void setElement​(int index,
                                           long value)
      • getMinValue

        protected abstract long getMinValue()
      • getMaxValue

        protected abstract long getMaxValue()
      • swapElements

        public abstract void swapElements​(int i1,
                                          int i2)
      • getLong

        public abstract long getLong​(int i)
        Returns the ith element of the array as a long integer, irrespective of the underlying storage type.
        Parameters:
        i - The index of the element to return.
        Returns:
        the ith element of the array.
        Throws:
        ArrayIndexOutOfBoundsException - if i >= size()
      • getInt

        public abstract int getInt​(int i)
        Returns the ith element of the array as a 4-byte integer, irrespective of the underlying storage type.
        Parameters:
        i - The index of the element to return.
        Returns:
        the ith element of the array.
        Throws:
        ArrayIndexOutOfBoundsException - if i >= size()
        ArithmeticError - if the element is too large or small to be represented as a 4-byte integer.
      • append

        public final void append​(long i)
        Appends an integer to the end of the array
        Parameters:
        i - The integer to append
        Throws:
        ArithmeticException - if i is too large or small to be stored in the underlying storage array
      • size

        public final int size()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object