Class IntegerArray

java.lang.Object
org.opensourcephysics.numerics.IntegerArray

public class IntegerArray extends Object
IntegerArray stores an array of doubles as a string and as an array.
  • Field Details

    • NumberFormatError

      public static int NumberFormatError
    • ArrayIndexOutOfBoundsError

      public static int ArrayIndexOutOfBoundsError
    • array

      protected int[] array
    • defaultString

      protected String defaultString
    • defaultArray

      protected int[] defaultArray
    • errorcode

      protected int errorcode
  • Constructor Details

    • IntegerArray

      public IntegerArray(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 -
    • IntegerArray

      public IntegerArray(int[] array)
      Creates a DoubleArray of the given length with all elements set to zero. The length of the arry cannot be changed.
      Parameters:
      array -
    • IntegerArray

      public IntegerArray(String str) throws 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:
      NumberFormatException
  • Method Details

    • getDefault

      public 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:
    • toString

      public String toString()
      Converts the array to a comma delimited string enclosed in braces.
      Overrides:
      toString in class Object
      Returns:
    • getError

      public int getError()
      Gets the error code
      Returns:
    • getArray

      public int[] getArray(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 int[] getArray()
      Gets the array of doubles.
      Returns:
    • set

      public boolean set(String str)
      Sets the array to the given string.
      Returns:
      true if successful; false otherwise
    • setDefaultArray

      public void setDefaultArray(int[] array)
    • toInteger

      protected int[] toInteger(String str) throws 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:
      int array
      Throws:
      ArrayIndexOutOfBoundsException
    • getLoader

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