GraphReaderpublic class GraphReader extends Object GraphReader is a helper class for Grapher, that reads various formats.
(At present, only a list of x,y points from a text file). |
Methods Summary |
---|
public static java.util.List | read(java.lang.String fileName)Read data points from the named file. Each line has an x and a y coordinate.
return read(new FileReader(fileName), fileName);
| public static java.util.List | read(java.io.Reader reader, java.lang.String fileName)Read data points from an opened Reader. Each line has an x and a y coordinate.
LineNumberReader is = new LineNumberReader(reader);
List data = new ArrayList();
String txt;
// Read the file a line at a time, parse it, save the data.
while ((txt = is.readLine()) != null) {
StringTokenizer st = new StringTokenizer(txt);
try {
Point2D p = new Point2D.Double();
p.setLocation(Float.parseFloat(st.nextToken()),
Float.parseFloat(st.nextToken()));
data.add(p);
} catch(NumberFormatException nfe) {
throw new IllegalArgumentException("Invalid number " + nfe +
" on line " + is.getLineNumber());
}
}
if (data.size() < 2) {
throw new IllegalArgumentException(
"GraphReader.read: " + fileName + ": Not enough data points!");
}
return data;
|
|