org.opensourcephysics.display
Class DataFile

java.lang.Object
  extended by org.opensourcephysics.display.DataAdapter
      extended by org.opensourcephysics.display.DataFile
All Implemented Interfaces:
Data

public class DataFile
extends DataAdapter


Field Summary
protected static java.lang.String[] delimiters
           
 
Fields inherited from class org.opensourcephysics.display.DataAdapter
colNames, data, ID, name
 
Constructor Summary
DataFile(java.lang.String fileName)
          Creates a DataFile using data in the given file.
 
Method Summary
 java.util.List<Data> getDataList()
          Some objects (eg, a Group) do not contain data, but a list of Data objects that do.
protected static double[] getRowArray(int rowCount)
          Returns an array of row numbers.
 java.lang.String open(java.lang.String fileName)
          Opens an xml or data file specified by name.
 double[][] parseData(java.lang.String dataString, java.lang.String fileName)
          Parses character-delimited data from a string.
protected static double[] parseDoubles(java.lang.String[] strings)
          Parses a String array into doubles.
protected static double[][] parseDoubles(java.lang.String text, java.lang.String rowDelimiter, java.lang.String colDelimiter)
          Parses a String into doubles separated by specified row and column delimiters.
protected static java.lang.String[] parseStrings(java.lang.String text, java.lang.String delimiter)
          Parses a String into tokens separated by a specified delimiter.
protected static java.lang.String[][] parseStrings(java.lang.String text, java.lang.String rowDelimiter, java.lang.String colDelimiter)
          Parses a String into tokens separated by specified row and column delimiters.
protected  java.lang.String readFirstLine(java.io.Reader in)
           
 
Methods inherited from class org.opensourcephysics.display.DataAdapter
getColumnNames, getData2D, getData3D, getDatasets, getFillColors, getID, getLineColors, getName, setColumnNames, setID, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delimiters

protected static java.lang.String[] delimiters
Constructor Detail

DataFile

public DataFile(java.lang.String fileName)
Creates a DataFile using data in the given file.

Parameters:
fileName -
Method Detail

getDataList

public java.util.List<Data> getDataList()
Some objects (eg, a Group) do not contain data, but a list of Data objects that do. This method is used by Data displaying tools to create as many pages as needed.

Specified by:
getDataList in interface Data
Overrides:
getDataList in class DataAdapter
Returns:
a list of Data objects, or null if this object contains data

open

public java.lang.String open(java.lang.String fileName)
Opens an xml or data file specified by name.

Parameters:
fileName - the file name
Returns:
the file name, if successfully opened

parseData

public double[][] parseData(java.lang.String dataString,
                            java.lang.String fileName)
Parses character-delimited data from a string. This attempts to extract the following information from the string: 1. A title to be used for the tab name 2. One or more columns of double data values 3. Column names for the data columns

Parameters:
dataString - the data string
fileName - name of file containing the data string (may be null)
Returns:
DatasetManager with parsed data, or null if none found

readFirstLine

protected java.lang.String readFirstLine(java.io.Reader in)

parseStrings

protected static java.lang.String[] parseStrings(java.lang.String text,
                                                 java.lang.String delimiter)
Parses a String into tokens separated by a specified delimiter. A token may be "".

Parameters:
text - the text to parse
delimiter - the delimiter
Returns:
an array of String tokens

parseStrings

protected static java.lang.String[][] parseStrings(java.lang.String text,
                                                   java.lang.String rowDelimiter,
                                                   java.lang.String colDelimiter)
Parses a String into tokens separated by specified row and column delimiters.

Parameters:
text - the text to parse
rowDelimiter - the column delimiter
colDelimiter - the column delimiter
Returns:
a 2D array of String tokens

parseDoubles

protected static double[] parseDoubles(java.lang.String[] strings)
Parses a String array into doubles. Unparsable strings are set to Double.NaN.

Parameters:
strings - the String array to parse
Returns:
an array of doubles

parseDoubles

protected static double[][] parseDoubles(java.lang.String text,
                                         java.lang.String rowDelimiter,
                                         java.lang.String colDelimiter)
Parses a String into doubles separated by specified row and column delimiters.

Parameters:
text - the text to parse
rowDelimiter - the column delimiter
colDelimiter - the column delimiter
Returns:
a 2D array of doubles

getRowArray

protected static double[] getRowArray(int rowCount)
Returns an array of row numbers.

Parameters:
rowCount - length of the array
Returns:
the array