Package com.graphbuilder.curve
Class ValueVector
java.lang.Object
com.graphbuilder.curve.ValueVector
A value-vector is a sequence of values that some curves use to define themselves,
sometimes called a knot-vector or a weight-vector. The values are stored using an
array.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a ValueVector with initial capacity of 2.ValueVector(double[] value, int size) Creates a ValueVector using the specified array and initial size.ValueVector(int initialCapacity) Creates a ValueVector with the specified initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double d) Adds a value to the value array at index location size.voidensureCapacity(int capacity) Checks that the value array has the specified capacity, otherwise the capacity of the value array is increased to be the maximum between twice the current capacity and the specified capacity.doubleget(int index) Returns the value at the specified index.voidinsert(double d, int index) Inserts the value at the specified index location.voidremove(int index) Removes the value at the specified index.voidset(double d, int index) Sets the value at the specified index.intsize()Returns the number of values in the value array.voidCreates a new value array of exact size, copying the values from the old array into the new one.
-
Field Details
-
size
protected int size -
value
protected double[] value
-
-
Constructor Details
-
ValueVector
public ValueVector()Creates a ValueVector with initial capacity of 2. -
ValueVector
public ValueVector(double[] value, int size) Creates a ValueVector using the specified array and initial size.- Throws:
IllegalArgumentException- If the value array is null or size < 0 or size > data.length.
-
ValueVector
public ValueVector(int initialCapacity) Creates a ValueVector with the specified initial capacity.
-
-
Method Details
-
size
public int size()Returns the number of values in the value array. -
get
public double get(int index) Returns the value at the specified index.- Throws:
IllegalArgumentException- If index < 0 or index >= size.
-
set
public void set(double d, int index) Sets the value at the specified index.- Throws:
IllegalArgumentException- If index < 0 or index >= size.
-
remove
public void remove(int index) Removes the value at the specified index. Values at a higher index are shifted to fill the space.- Throws:
IllegalArgumentException- If index < 0 or index >= size.
-
add
public void add(double d) Adds a value to the value array at index location size. -
insert
public void insert(double d, int index) Inserts the value at the specified index location. Values at an equal or higher index are shifted to make space.- Throws:
IllegalArgumentException- If index < 0 or index > size.
-
ensureCapacity
public void ensureCapacity(int capacity) Checks that the value array has the specified capacity, otherwise the capacity of the value array is increased to be the maximum between twice the current capacity and the specified capacity. -
trimArray
public void trimArray()Creates a new value array of exact size, copying the values from the old array into the new one.
-