Package uk.ac.rdg.resc.edal.util
Class RArray
- java.lang.Object
-
- uk.ac.rdg.resc.edal.util.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
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
append(long i)
Appends an integer to the end of the arrayboolean
equals(Object obj)
abstract int
getInt(int i)
Returns the ith element of the array as a 4-byte integer, irrespective of the underlying storage type.abstract long
getLong(int i)
Returns the ith element of the array as a long integer, irrespective of the underlying storage type.protected abstract long
getMaxValue()
protected abstract long
getMinValue()
protected abstract int
getStorageLength()
int
hashCode()
protected abstract Object
makeStorage(int capacity)
protected abstract void
setElement(int index, long value)
int
size()
abstract void
swapElements(int i1, int i2)
-
-
-
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 arraychunkSize
- 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
- ifi >= 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
- ifi >= 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
- ifi
is too large or small to be stored in the underlying storage array
-
size
public final int size()
-
-