public class FlatArray
extends java.lang.Object
implements java.io.Serializable
Arrays can be partially flattened, so that the highest few dimensions are mapped onto a single dimension but the remaining dimensions are kept as array elements of flattened array.
FlatArray also contains a large number of class methods as utilities for the manipulation of arrays using the flattening technique. These are extensively used in GraphType.
GraphType
,
Serialized FormConstructor and Description |
---|
FlatArray()
Constructs an empty FlatArray.
|
FlatArray(java.lang.Object o)
Constructs a FlatArray from the given array.
|
FlatArray(java.lang.Object o,
int depth)
Constructs a FlatArray from the given array by flattening all the dimensions up to argument depth.
|
FlatArray(java.lang.Object o,
int[] l)
Constructs a FlatArray from the given flattened array and the given array of integers.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.Object |
addArrays(java.lang.Object a1,
java.lang.Object a2)
Class method that adds the elements of the two given arrays.
|
static java.lang.Object |
convertArrayElements(java.lang.Object o,
java.lang.Class outClass)
Class method that converts the given input array to an array whose elements are of the type given by the Class in
the second argument.
|
static double[] |
convertToFullSpectrum(double[] input,
int full,
boolean onesided,
boolean realpart,
boolean narrowband,
int low)
Class method that converts takes the given spectral data array, which can be one-sided and/or narrow-band, and
which is assumed to be stored according to the Triana spectral data model, and returns the associated two-sided
full-bandwidth data array.
|
static double[] |
convertToNarrowBand(double[] fullArray,
boolean oneSide,
int low,
int high)
Class method that converts a full-bandwidth spectrum to a narrow-band spectrum.
|
static double[] |
convertToOneSided(double[] twoSide,
int full,
boolean narrowband,
boolean containsZeroFrequency)
Class method that takes the given array, assumed to be a two-sided spectrum (either the real or imaginary part)
and returns the associated one-sided spectrum.
|
static java.lang.Object |
divideArrays(java.lang.Object a1,
java.lang.Object a2)
Class method that divides the individual elements of two arrays.
|
static java.util.ArrayList |
divideArrays(java.lang.Object a1r,
java.lang.Object a1i,
java.lang.Object a2r,
java.lang.Object a2i)
Class method that divides the individual elements of two complex arrays, whose real and imaginary parts are the
four given arrays.
|
static boolean |
equalArrays(java.lang.Object a1,
java.lang.Object a2)
Class method that tests the elements of the two given arrays.
|
static java.lang.String |
findArrayComponentName(java.lang.Object o,
int depth)
Class method to find the name of the type of the component of an array down to a certain depth.
|
static int[] |
findArrayDimensionLengths(java.lang.Object o)
Class method finds the size of each dimension of a multi-dimensional array.
|
static int[] |
findArrayDimensionLengths(java.lang.Object o,
int depth)
Class method finds the size of each dimension of a multi-dimensional array down to a certain depth.
|
static int |
findNumberOfDimensions(java.lang.Object o)
Class method finds the number of dimensions of a multi-dimensional array.
|
java.lang.String |
getComponentName()
Returns the name of the type of the components of the flattened array.
|
java.lang.Object |
getFlatArray()
Returns the array that holds the flattened data.
|
int |
getFlatLength()
Returns the length of the flattened array, which is the total number of elements in the original array.
|
int[] |
getLengths()
Returns the int[] that contains the lengths of the dimensions of the original array.
|
static boolean |
incrementArray(java.lang.Object o,
double s)
Class method that adds the given real number to the given data array and returns a boolean true value to
indicate success.
|
static boolean |
incrementArray(java.lang.Object or,
java.lang.Object oi,
double sr,
double si)
Class method that adds the given complex number (supplied as two doubles in the last two arguments) to the given
complex data array (supplied in the first two arguments, containing any primitive arithmetic types) and returns a
boolean true value to indicate success.
|
static java.util.ArrayList |
incrementCopyOfArray(java.lang.Object or,
java.lang.Object oi,
double sr,
double si)
Class method that adds the given complex number (supplied as two doubles in the last two arguments) to the given
complex data array (supplied in the first two arguments, containing any primitive arithmetic types) and returns
an ArrayList holding the real and imaginary parts of the results as new arrays of doubles of the same
dimensionality as the given arrays.
|
static void |
initializeArray(java.lang.Object a)
Class method that sets the elements of the given array to zero.
|
static boolean |
isArithmeticArray(java.lang.Object o)
Class method that returns true if the given multi-dimensional array contains these primitive Java data
types at its lowest level: byte, short, int, long, float, or double.
|
static boolean |
isPrimitiveArray(java.lang.Object o)
Class method that returns true if the given multi-dimensional array is an array of primitive Java data
types at its lowest level.
|
static double |
maxArray(java.lang.Object in)
Class method maxArray returns a double containing the maximum value of all the elements of the given array, if
its elements are of an arithmetic data type, as determined by method isArithmeticArray.
|
static double |
minArray(java.lang.Object in)
Class method that returns a double containing the minimum value of all the elements of the given array, if its
elements are of an arithmetic data type, as determined by method isArithmeticArray.
|
static java.lang.Object |
multiArrayCopy(java.lang.Object o)
Class method that copies an arbitrary multi-dimensional array to another array of the same dimensions.
|
static java.lang.Object |
multiArrayImitate(java.lang.Object o)
Class method that creates a new array with the same dimensionality and component types as the given arbitrary
multi-dimensional array.
|
static java.lang.Object |
multiplyArrays(java.lang.Object a1,
java.lang.Object a2)
Class method that multiplies the individual elements of the two given arrays.
|
static java.util.ArrayList |
multiplyArrays(java.lang.Object a1r,
java.lang.Object a1i,
java.lang.Object a2r,
java.lang.Object a2i)
Class method that multiplies the individual elements of two complex arrays, whose real and imaginary parts are
the four given arrays.
|
java.lang.Object |
restoreArray()
Creates an array of the dimensionality given by lengths and containing the data held in flatArray,/i>.
|
java.lang.Object |
restoreArray(boolean copy)
Returns an array of the dimensionality given by lengths and containing the data held in flatArray.
|
static boolean |
scaleArray(java.lang.Object o,
double s)
Class method that multiplies the given real data array by the given real number and returns a boolean
true value to indicate success.
|
static boolean |
scaleArray(java.lang.Object or,
java.lang.Object oi,
double sr,
double si)
Class method that multiplies the given complex data array (supplied in the first two arguments, containing any
primitive arithmetic types) by the given complex number (supplied as two doubles in the last two arguments) and
returns a boolean true value to indicate success.
|
static java.util.ArrayList |
scaleCopyOfArray(java.lang.Object or,
java.lang.Object oi,
double sr,
double si)
Class method that multiplies the given complex data array (supplied in the first two arguments, containing any
primitive arithmetic types) by the given complex number (supplied as two doubles in the last two arguments) and
returns an ArrayList holding the real and imaginary parts of the results as new arrays of doubles of the same
dimensionality as the given arrays.
|
void |
setComponentName(java.lang.String newComponentName)
Sets the name of the type of the component of the flat array.
|
void |
setFlatArray(java.lang.Object newArray)
Sets the Array that holds the flattened data.
|
void |
setLengths(int[] newLengths)
Sets the int[] that holds the lengths of the original dimensions.
|
static boolean |
similarArrays(java.lang.Object a1,
java.lang.Object a2)
Class method that tests to see if the given arrays are of a similar type: both Objects are indeed arrays, they
have the same dimensionality, and their sizes in the different dimensions are the same.
|
static java.lang.Object |
subtractArrays(java.lang.Object a1,
java.lang.Object a2)
Class method that subtracts the elements of the second given array from those of the first.
|
static int |
testConjugateSymmetry(double[] xr,
double[] xi)
Class method to test whether a spectral data set has the symmetry property that will result in its inverse
transform being pure real or pure imaginary.
|
static java.lang.Object |
toByteArray(java.lang.Object o)
Class method that converts a given input array to an array of bytes.
|
static java.lang.Object |
toDoubleArray(java.lang.Object o)
Class method that converts a given input array to an array of doubles.
|
static java.lang.Object |
toFloatArray(java.lang.Object o)
Class method that converts a given input array to an array of floats.
|
static java.lang.Object |
toIntArray(java.lang.Object o)
Class method that converts a given input array to an array of ints.
|
static java.lang.Object |
toLongArray(java.lang.Object o)
Class method that converts a given input array to an array of longs.
|
static java.lang.Object |
toShortArray(java.lang.Object o)
Class method that converts a given input array to an array of shorts.
|
public FlatArray()
public FlatArray(java.lang.Object o)
o
- The array to be fully flattenedpublic FlatArray(java.lang.Object o, int depth)
o
- The array to be flatteneddepth
- The last dimension to be flattened, counting from 0public FlatArray(java.lang.Object o, int[] l)
o
- The flattened arrayl
- The lengths of the dimensions of the corresponding unflattened arraypublic static int findNumberOfDimensions(java.lang.Object o)
o
- The multi-dimensional array to be examinedpublic static int[] findArrayDimensionLengths(java.lang.Object o)
o
- The input (multi-dimensional) arraypublic static int[] findArrayDimensionLengths(java.lang.Object o, int depth)
o
- The input (multi-dimensional) arraydepth
- The number of dimensions whose size is desiredpublic static java.lang.String findArrayComponentName(java.lang.Object o, int depth)
o
- The data array to be examineddepth
- The depth at which one wants the component typepublic static java.lang.Object multiArrayImitate(java.lang.Object o)
o
- The input (multi-dimensional) arraypublic static java.lang.Object multiArrayCopy(java.lang.Object o)
o
- The input (multi-dimensional) arraypublic static boolean isPrimitiveArray(java.lang.Object o)
o
- The array being inspectedpublic static boolean isArithmeticArray(java.lang.Object o)
o
- The array being testedpublic static java.lang.Object toDoubleArray(java.lang.Object o)
o
- The input arraypublic static java.lang.Object toFloatArray(java.lang.Object o)
o
- The input arraypublic static java.lang.Object toIntArray(java.lang.Object o)
o
- The input arraypublic static java.lang.Object toLongArray(java.lang.Object o)
o
- The input arraypublic static java.lang.Object toShortArray(java.lang.Object o)
o
- The input arraypublic static java.lang.Object toByteArray(java.lang.Object o)
o
- The input arraypublic static java.lang.Object convertArrayElements(java.lang.Object o, java.lang.Class outClass)
Note that Java provides Class constants for primitives, denoted by Integer.Type, Double.Type, etc,. These values are also returned by applying the suffix .class to a primitive variable type name, e.g. int.class has the value Integer.Type. For any Object Q, including arrays, the class is given by the method Q.getClass(). Normally, the present method would be used to to convert the elements of o to the type of the elements of object q, by invoking convertArrayType( o, q.getClass() ).
o
- The input arrayoutClass
- The desired type of the output elementspublic static boolean incrementArray(java.lang.Object or, java.lang.Object oi, double sr, double si)
If the data are not arithmetic data then the method returns false. If the input data are real (second argument null) but the imaginary part of the increment variable (fourth argument) is non-zero, then the method returns false.
or
- The real part of the array data, which must contain doublesoi
- The imaginary part of the array data, which must contain doubles; it may be nullsr
- The real part of the increment numbersi
- The imaginary part of the increment number (must be zero if the second argument is null)public static java.util.ArrayList incrementCopyOfArray(java.lang.Object or, java.lang.Object oi, double sr, double si)
If the data are not arithmetic data then the method returns a null ArrayList. If the input data are real (second argument null) and the imaginary part of the increment variable (fourth argument) is zero, then the second component of the returned ArrayList will be null. If the input data are real but the imaginary part of the increment variable is non-zero, then the output data will be complex.
or
- The real part of the array dataoi
- The imaginary part of the array data (null if data are real)sr
- The real part of the increment numbersi
- The imaginary part of the increment number (zero if increment is real)public static boolean incrementArray(java.lang.Object o, double s)
If the data are not arithmetic data then the method returns false.
o
- The array data, which must contain doubless
- The increment numberpublic static boolean scaleArray(java.lang.Object or, java.lang.Object oi, double sr, double si)
If the data are not arithmetic data then the method returns false. If the input data are real (second argument null) but the imaginary part of the scale variable (fourth argument) is non-zero, then the method returns false.
or
- The real part of the array dataoi
- The imaginary part of the array data (null if data are real)sr
- The real part of the scaling numbersi
- The imaginary part of the scaling number (zero if scale is real)public static java.util.ArrayList scaleCopyOfArray(java.lang.Object or, java.lang.Object oi, double sr, double si)
If the data are not arithmetic data then the method returns a null ArrayList. If the input data are real (second argument null) and the imaginary part of the scale variable (fourth argument) is zero, then the second component of the returned ArrayList will be null. If the input data are real but the imaginary part of the scale variable is non-zero, then the output data will be complex.
or
- The real part of the array dataoi
- The imaginary part of the array data (null if data are real)sr
- The real part of the scaling numbersi
- The imaginary part of the scaling number (zero if scale is real)public static boolean scaleArray(java.lang.Object o, double s)
If the data are not arithmetic data then the method returns false.
o
- The array data, which must contain doubless
- The increment numberpublic static double maxArray(java.lang.Object in)
in
- The array to be testedpublic static double minArray(java.lang.Object in)
in
- The array to be testedpublic static boolean similarArrays(java.lang.Object a1, java.lang.Object a2)
a1
- The first array to be compareda2
- The second array to be comparedpublic static boolean equalArrays(java.lang.Object a1, java.lang.Object a2)
a1
- The first array to be compareda2
- The second arraypublic static void initializeArray(java.lang.Object a)
a
- The array to be initializedpublic static java.lang.Object addArrays(java.lang.Object a1, java.lang.Object a2)
If the input arrays are not the same dimensionality and size, or if at least one of them does not contain arithmetic data types, then this method returns null. If the given objects are not arrays, or are arrays of non-primitive objects, then the method also returns null.
a1
- The first array to be addeda2
- The second array to be addedpublic static java.lang.Object subtractArrays(java.lang.Object a1, java.lang.Object a2)
If the input arrays are not the same dimensionality and size, or if at least one of them does not contain arithmetic data types, then this method returns null. If the given objects are not arrays, or are arrays of non-primitive objects, then the method also returns null.
a1
- The array to be subtracted froma2
- The array to be subtractedpublic static java.util.ArrayList multiplyArrays(java.lang.Object a1r, java.lang.Object a1i, java.lang.Object a2r, java.lang.Object a2i)
If the input arrays are not all the same dimensionality and size, or if at least one of them does not contain arithmetic data types, the this method returns null. If the given objects are not arrays, or are arrays of non-primitive objects, then the method also returns null.
a1r
- The real part of the first array to be multiplieda1i
- The imaginary part of the first array to be multiplieda2r
- The real part of the second array to be multiplieda2i
- The imaginary part of the second array to be multipliedpublic static java.lang.Object multiplyArrays(java.lang.Object a1, java.lang.Object a2)
If the input arrays are not all the same dimensionality and size, or if at least one of them does not contain arithmetic data types, the this method returns null. If the given objects are not arrays, or are arrays of non-primitive objects, then the method also returns null.
a1
- The first array to be multiplieda2
- The second array to be multipliedpublic static java.util.ArrayList divideArrays(java.lang.Object a1r, java.lang.Object a1i, java.lang.Object a2r, java.lang.Object a2i)
If the input arrays are not all the same dimensionality and size, or if at least one of them does not contain arithmetic data types, the this method returns null. If the given objects are not arrays, or are arrays of non-primitive objects, then the method also returns null.
a1r
- The real part of the numerator arraya1i
- The imaginary part of the numeratorarraya2r
- The real part of the denominator arraya2i
- The imaginary part of the denominator arraypublic static java.lang.Object divideArrays(java.lang.Object a1, java.lang.Object a2)
If the input arrays are not the same dimensionality and size, or if at least one of them does not contain arithmetic data types, the this method returns null. If the given objects are not arrays, or are arrays of non-primitive objects, then the method also returns null.
a1
- The numerator arraya2
- The denominator arraypublic static double[] convertToNarrowBand(double[] fullArray, boolean oneSide, int low, int high)
fullArray
- The input full-bandwidth spectrumoneSide
- True if the input spectrum in one-sidedlow
- The index of the lower edge of the returned bandhigh
- The index of the higher edge of the returned bandSpectrum
,
ComplexSpectrum
public static double[] convertToOneSided(double[] twoSide, int full, boolean narrowband, boolean containsZeroFrequency)
twoSide
- The input array containing a two-sided spectrumfull
- The number of elements in the full two-sided spectrumnarrowband
- True if the input array is a narrow-band spectrumcontainsZeroFrequency
- True if the zero-frequency element is present in the input arraySpectrum
,
ComplexSpectrum
public static double[] convertToFullSpectrum(double[] input, int full, boolean onesided, boolean realpart, boolean narrowband, int low)
The nature of the input array is given by the flags onesided and narrowband. The int argument full is the number of elements in the returned array.
The method does not check that the input data obeys the Triana spectral data model. The user is responsible for ensuring this.
input
- The input arrayfull
- The number of data points in the returned arrayonesided
- True if the input data are one-sidedrealpart
- True if the input data are the real part of a spectrum, false if imaginary partnarrowband
- True if the input data are narrow-bandlow
- The lower bound on the frequency spectrumpublic static int testConjugateSymmetry(double[] xr, double[] xi)
xr
- The real part of the input data set (can be null)xi
- The imaginary part of the input data set (can be null)public java.lang.Object getFlatArray()
public int[] getLengths()
public int getFlatLength()
public java.lang.String getComponentName()
public void setFlatArray(java.lang.Object newArray)
newArray
- The new flattened arraypublic void setLengths(int[] newLengths)
newLengths
- The new lengths arraypublic void setComponentName(java.lang.String newComponentName)
newComponentName
- The new type namepublic java.lang.Object restoreArray(boolean copy)
copy
- True if the output should be a new object, false if the old object should be restoredpublic java.lang.Object restoreArray()