public final class DoubleArrayList
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_SIZE
The standard starting point for the array length
|
protected int |
numElements
The number of used elements in this
|
Constructor and Description |
---|
DoubleArrayList()
Initializes an empty vector with a default allocation.
|
DoubleArrayList(DoubleArrayList copy)
Copy constructor
|
DoubleArrayList(int startSize)
Initializes an empty vector (allocating startSize locations for
additions).
|
Modifier and Type | Method and Description |
---|---|
void |
add(double element)
Adds element to the end of the vector (allocating more space as needed
|
protected void |
checkBounds(int idx)
Checks that idx is in the allowed elements of the vector (distinct from
the space in elements).
|
protected static void |
checkNewSizePositive(int size)
Helper that ensures the input size is positive
|
void |
clear()
Quickly "clears" the contents (sets numElements to 0).
|
void |
decreaseTo(int size)
Effectively remove elements from the vector.
|
protected void |
ensureNotFull()
Simple helper that increases the size if the current vector is full
|
boolean |
equals(java.lang.Object o) |
double |
get(int idx)
Returns the element at idx
|
int |
hashCode() |
void |
increaseTo(int size)
Resizes the background array if it is too small.
|
protected int |
length()
Return the number of elements in the background storage array.
|
void |
plusEquals(int idx,
double val)
Adds val to the element at idx
|
void |
reserve(int size)
Resizes the background array to the specified size.
|
protected void |
resize(int size)
Replace the internal storage with a new buffer.
|
void |
set(int idx,
double val)
Sets the element at idx
|
void |
shrinkToFit()
Resizes the background array to exactly fit the current number of
elements.
|
int |
size()
Returns the number of elements added to the vector (not the size of the
storage)
|
void |
swap(int p1,
int p2)
Swaps the values stored at p1 and p2.
|
static DoubleArrayList |
zeros(int size)
Factory method that initializes a DoubleVector of the input size with
zeros in every entry.
|
protected int numElements
protected static final int DEFAULT_SIZE
public DoubleArrayList()
public DoubleArrayList(int startSize)
startSize
- The number of positions to start the storagepublic DoubleArrayList(DoubleArrayList copy)
copy
- The vector to make a deep copy ofpublic void add(double element)
element
- The element to add to the endpublic double get(int idx)
idx
- The indexjava.lang.ArrayIndexOutOfBoundsException
- if idx is outside the allowed
boundspublic void set(int idx, double val)
idx
- The indexval
- The new value at idxjava.lang.ArrayIndexOutOfBoundsException
- if idx is outside the allowed
boundspublic void plusEquals(int idx, double val)
idx
- The indexval
- The value to add at idxjava.lang.ArrayIndexOutOfBoundsException
- if idx is outside the allowed
boundspublic void swap(int p1, int p2)
p1
- The first index to swapp2
- The second index to swapjava.lang.ArrayIndexOutOfBoundsException
- if either index is outside the
allowed boundsprotected void resize(int size)
size
- the number of elements in the new internal arrayprotected int length()
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public static DoubleArrayList zeros(int size)
size
- The number of zeros to put in the returned DoubleVectorpublic void reserve(int size)
size
- The new size for the arraypublic void shrinkToFit()
public void increaseTo(int size)
size
- The new sizepublic void decreaseTo(int size)
size
- The new length of the arraypublic void clear()
public int size()
protected void ensureNotFull()
protected void checkBounds(int idx)
idx
- the index into the vectorjava.lang.ArrayIndexOutOfBoundsException
- if idx is outside the allowed
boundsprotected static void checkNewSizePositive(int size)
size
- The new sizejava.lang.IllegalArgumentException
- if size is negative