org.opensourcephysics.numerics
Class DoubleArray

java.lang.Object
  extended by org.opensourcephysics.numerics.DoubleArray

public class DoubleArray
extends java.lang.Object

DoubleArray stores an array of doubles as a string and as an array.


Field Summary
protected  double[] array
           
static int ArrayIndexOutOfBoundsError
           
protected  double[] defaultArray
           
protected  java.lang.String defaultString
           
protected  int errorcode
           
protected  java.text.DecimalFormat format
           
protected  java.text.DecimalFormat formatExp
           
static int NumberFormatError
           
 
Constructor Summary
DoubleArray(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(java.lang.String str)
          Creates an arry with the given string being the default string.
 
Method Summary
 double[] getArray()
          Gets the array of doubles.
 double[] getArray(java.lang.String str)
          Converts the string to an array and returns the array.
 java.lang.String getDefault()
          Gets the default array.
 int getError()
          Gets the error code
static XML.ObjectLoader getLoader()
          Returns an XML.ObjectLoader to save and load object data.
 boolean set(java.lang.String str)
          Sets the array to the given string.
 void setDecimalFormat(java.lang.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[] toDouble(java.lang.String str)
          Converts a comma delimited string enclosed in braces to an array.
 java.lang.String toString()
          Converts the array to a comma delimited string enclosed in braces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NumberFormatError

public static int NumberFormatError

ArrayIndexOutOfBoundsError

public static int ArrayIndexOutOfBoundsError

format

protected java.text.DecimalFormat format

formatExp

protected java.text.DecimalFormat formatExp

array

protected double[] array

defaultString

protected java.lang.String defaultString

defaultArray

protected double[] defaultArray

errorcode

protected int errorcode
Constructor Detail

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 arry cannot be changed.

Parameters:
array -

DoubleArray

public DoubleArray(java.lang.String str)
            throws java.lang.NumberFormatException
Creates an arry 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:
java.lang.NumberFormatException
Method Detail

setDecimalFormat

public void setDecimalFormat(java.lang.String pattern)
Creates a DecimalFormat for printing array elements using the given pattern and the symbols for the default locale.

See Also:
DecimalFormat

getDefault

public java.lang.String 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

public java.lang.String toString()
Converts the array to a comma delimited string enclosed in braces.

Overrides:
toString in class java.lang.Object
Returns:
string

getError

public int getError()
Gets the error code

Returns:

getArray

public double[] getArray(java.lang.String str)
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

public boolean set(java.lang.String str)
Sets the array to the given string.

Returns:
true if successful; false otherwise

setDefaultArray

public void setDefaultArray(double[] array)

toDouble

protected double[] toDouble(java.lang.String str)
                     throws java.lang.ArrayIndexOutOfBoundsException
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:
java.lang.ArrayIndexOutOfBoundsException

getLoader

public static XML.ObjectLoader getLoader()
Returns an XML.ObjectLoader to save and load object data.

Returns:
the XML.ObjectLoader