Package org.opensourcephysics.numerics
Class DoubleArray
java.lang.Object
org.opensourcephysics.numerics.DoubleArray
DoubleArray stores an array of doubles as a string and as an array.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected double[]
static int
protected double[]
protected String
protected int
protected DecimalFormat
protected DecimalFormat
static int
-
Constructor Summary
ConstructorsConstructorDescriptionDoubleArray
(double[] array) Creates a DoubleArray of the given length with all elements set to zero.DoubleArray
(int n) Creates a DoubleArray of the given length with all elements set to zero.DoubleArray
(String str) Creates an array with the given string being the default string. -
Method Summary
Modifier and TypeMethodDescriptiondouble[]
getArray()
Gets the array of doubles.double[]
Converts the string to an array and returns the array.Gets the default array.int
getError()
Gets the error codestatic XML.ObjectLoader
Returns an XML.ObjectLoader to save and load object data.boolean
Sets the array to the given string.void
setDecimalFormat
(String pattern) Creates a DecimalFormat for printing array elements using the given pattern and the symbols for the default locale.void
setDefaultArray
(double[] array) protected double[]
Converts a comma delimited string enclosed in braces to an array.toString()
Converts the array to a comma delimited string enclosed in braces.
-
Field Details
-
NumberFormatError
public static int NumberFormatError -
ArrayIndexOutOfBoundsError
public static int ArrayIndexOutOfBoundsError -
format
-
formatExp
-
array
protected double[] array -
defaultString
-
defaultArray
protected double[] defaultArray -
errorcode
protected int errorcode
-
-
Constructor Details
-
DoubleArray
public DoubleArray(int n) Creates a DoubleArray of the given length with all elements set to zero. The length of the arry cannot be changed.- Parameters:
n
-
-
DoubleArray
public DoubleArray(double[] array) Creates a DoubleArray of the given length with all elements set to zero. The length of the array cannot be changed.- Parameters:
array
-
-
DoubleArray
Creates an array with the given string being the default string. The given string determines the length of the array. This lenght cannot be changed.- Parameters:
str
-- Throws:
NumberFormatException
-
-
Method Details
-
setDecimalFormat
Creates a DecimalFormat for printing array elements using the given pattern and the symbols for the default locale.- See Also:
-
getDefault
Gets the default array. The default is used if the input string is not valid due to a number format exception or an array length exception.- Returns:
- string
-
toString
Converts the array to a comma delimited string enclosed in braces. -
getError
public int getError()Gets the error code- Returns:
-
getArray
Converts the string to an array and returns the array. If the conversion fails, the error code is set and default array is returned.- Returns:
- double[] the converted array
-
getArray
public double[] getArray()Gets the array of doubles.- Returns:
-
set
Sets the array to the given string.- Returns:
- true if successful; false otherwise
-
setDefaultArray
public void setDefaultArray(double[] array) -
toDouble
Converts a comma delimited string enclosed in braces to an array. v={1.5, 2.0, -3.2} would returns an array with componets (1.5,2.0,-3.2).- Parameters:
str
-- Returns:
- Throws:
ArrayIndexOutOfBoundsException
-
getLoader
Returns an XML.ObjectLoader to save and load object data.- Returns:
- the XML.ObjectLoader
-