public abstract class XySequence extends Object implements Iterable<XyPoint>
*copyOf() variants should
be used where possible as x-values will never be replicated in memory.
Although this class is not final, it can not be subclassed. Mutable instances of this class are not thread-safe for operations that alter y-values.
| Modifier and Type | Method and Description |
|---|---|
XySequence |
add(double term)
Add a
term to the y-values of this sequence in place. |
XySequence |
add(double[] ys)
Add the supplied y-values to the y-values of this sequence in place.
|
XySequence |
add(XySequence sequence)
Add the y-values of a sequence to the y-values of this sequence in place.
|
<E extends Enum<E>> |
addToMap(E key,
Map<E,XySequence> map)
Adds
this sequence to any exisiting sequence for key in the
supplied map. |
XySequence |
clear()
Sets all y-values to 0.
|
XySequence |
complement()
Sets the y-values of this sequence to their complement in place [
1 - y]. |
static XySequence |
copyOf(XySequence sequence)
Create a mutable copy of the supplied
sequence. |
static XySequence |
create(Collection<? extends Number> xs,
Collection<? extends Number> ys)
Create a new sequence with mutable y-values from the supplied value
collections.
|
static XySequence |
create(double[] xs,
double[] ys)
Create a new sequence with mutable y-values from the supplied value arrays.
|
static XySequence |
createImmutable(Collection<? extends Number> xs,
Collection<? extends Number> ys)
Create a new, immutable sequence from the supplied value collections.
|
static XySequence |
createImmutable(double[] xs,
double[] ys)
Create a new, immutable sequence from the supplied value arrays.
|
static XySequence |
emptyCopyOf(XySequence sequence)
Create a mutable copy of the supplied
sequence with all y-values
reset to zero. |
static XySequence |
immutableCopyOf(XySequence sequence)
Create an immutable copy of the supplied
sequence. |
abstract boolean |
isClear()
Returns
true if all y-values are 0.0; false otherwise. |
Iterator<XyPoint> |
iterator()
Returns an iterator over the
XyPoints in this sequence. |
XyPoint |
max()
The last
XyPoint in this sequence. |
XyPoint |
min()
The first
XyPoint in this sequence. |
XySequence |
multiply(double scale)
Multiply (
scale) the y-values of this sequence in place. |
XySequence |
multiply(XySequence sequence)
Multiply the y-values of this sequence by the y-values of another sequence
in place.
|
static XySequence |
resampleTo(XySequence sequence,
double[] xs)
Deprecated.
|
void |
set(int index,
double value)
Sets the y-
value at index. |
abstract int |
size()
Returns the number or points in this sequence.
|
String |
toString()
Returns a readable string representation of this sequence.
|
XySequence |
transform(Function<Double,Double> function)
Transforms all y-values in place using the supplied
Function. |
abstract XySequence |
trim()
Returns a new, immutable sequence that has had all leading and trailing
zero-valued points (
y = 0) removed. |
abstract double |
x(int index)
Returns the x-value at
index. |
List<Double> |
xValues()
Returns an immutable
List of the sequence x-values. |
abstract double |
y(int index)
Returns the y-value at
index. |
List<Double> |
yValues()
Returns an immutable
List of the sequence y-values. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorpublic static XySequence create(double[] xs, double[] ys)
xs - x-values to initialize sequence withys - y-values to initialize sequence with; may be nulldouble[]-backed sequenceNullPointerException - if xs are nullIllegalArgumentException - if xs and ys are not the
same sizeIllegalArgumentException - if xs does not increase
monotonically or contains repeated valuespublic static XySequence createImmutable(double[] xs, double[] ys)
create(double[], double[]), the supplied y-value array may not be
null.xs - x-values to initialize sequence withys - y-values to initialize sequence withdouble[]-backed sequenceNullPointerException - if xs or ys are nullIllegalArgumentException - if xs and ys are not the
same sizeIllegalArgumentException - if xs does not increase
monotonically or contains repeated valuespublic static XySequence create(Collection<? extends Number> xs, Collection<? extends Number> ys)
xs - x-values to initialize sequence withys - y-values to initialize sequence with; may be nulldouble[]-backed sequenceNullPointerException - if xs are nullIllegalArgumentException - if xs and ys are not the
same sizeIllegalArgumentException - if xs does not increase
monotonically or contains repeated valuespublic static XySequence createImmutable(Collection<? extends Number> xs, Collection<? extends Number> ys)
create(Collection, Collection) , the supplied y-value
collection may not be null.xs - x-values to initialize sequence withys - y-values to initialize sequence withdouble[]-backed sequenceNullPointerException - if xs or ys are nullIllegalArgumentException - if xs and ys are not the
same sizeIllegalArgumentException - if xs does not increase
monotonically or contains repeated valuespublic static XySequence copyOf(XySequence sequence)
sequence.sequence - to copysequenceNullPointerException - if the supplied sequence is nullpublic static XySequence emptyCopyOf(XySequence sequence)
sequence with all y-values
reset to zero.sequence - to copysequenceNullPointerException - if the supplied sequence is nullpublic static XySequence immutableCopyOf(XySequence sequence)
sequence.sequence - to copysequenceNullPointerException - if the supplied sequence is null@Deprecated public static XySequence resampleTo(XySequence sequence, double[] xs)
sequence. Method
resamples via linear interpolation and does not extrapolate beyond the
domain of the source sequence; y-values with x-values outside the
domain of the source sequence are set to 0.sequence - to resamplexs - resample valuespublic abstract double x(int index)
index.index - to retrieveindexIndexOutOfBoundsException - if the index is out of range (
index < 0 || index >= size())public abstract double y(int index)
index.index - to retrieveindexIndexOutOfBoundsException - if the index is out of range (
index < 0 || index >= size())public void set(int index,
double value)
value at index.index - of y-value to set.value - to setIndexOutOfBoundsException - if the index is out of range (
index < 0 || index >= size())public abstract int size()
public List<Double> xValues()
List of the sequence x-values.List of x-valuespublic List<Double> yValues()
List of the sequence y-values.List of y-valuespublic Iterator<XyPoint> iterator()
XyPoints in this sequence. For
immutable implementations, the XyPoint.set(double) method of a
returned point throws an UnsupportedOperationException.public String toString()
public XySequence add(double term)
term to the y-values of this sequence in place.term - to addthis sequence, for use inlinepublic XySequence add(double[] ys)
ys - y-values to addthis sequence, for use inlinepublic XySequence add(XySequence sequence)
sequence - to addthis sequence, for use inlineIllegalArgumentException - if
sequence.xValues() != this.xValues()public XySequence multiply(double scale)
scale) the y-values of this sequence in place.scale - factorthis sequence, for use inlinepublic XySequence multiply(XySequence sequence)
sequence - to multiply this sequence bythis sequence, for use inlineIllegalArgumentException - if
sequence.xValues() != this.xValues()public XySequence complement()
1 - y]. Assumes this is a probability function limited to the
domain [0 1].this sequence, for use inlinepublic XySequence clear()
this sequence, for use inlinepublic abstract boolean isClear()
true if all y-values are 0.0; false otherwise. apublic abstract XySequence trim()
y = 0) removed. Any zero-valued points in the
middle of this sequence are ignored.IllegalStateException - if this.isClear() as empty
sequences are not permittedpublic XySequence transform(Function<Double,Double> function)
Function.function - for transformthis sequence, for use inlinepublic final <E extends Enum<E>> void addToMap(E key, Map<E,XySequence> map)
this sequence to any exisiting sequence for key in the
supplied map. If key does not exist in the map,
method puts a mutable copy of this in the map.key - for sequence to addmap - of sequences to add toIllegalArgumentException - if the x-values of added sequences to not
match those of existing sequences