[Swift-commit] r7587 - usertools/plotter/src/plotter
wozniak at ci.uchicago.edu
wozniak at ci.uchicago.edu
Tue Feb 11 16:02:39 CST 2014
Author: wozniak
Date: 2014-02-11 16:02:39 -0600 (Tue, 11 Feb 2014)
New Revision: 7587
Modified:
usertools/plotter/src/plotter/LineReader.java
Log:
Restore tab indent 2
Modified: usertools/plotter/src/plotter/LineReader.java
===================================================================
--- usertools/plotter/src/plotter/LineReader.java 2014-02-11 21:54:47 UTC (rev 7586)
+++ usertools/plotter/src/plotter/LineReader.java 2014-02-11 22:02:39 UTC (rev 7587)
@@ -13,140 +13,140 @@
* */
public class LineReader
{
- public static List<String> read(File file)
- throws FileNotFoundException
- {
- BufferedReader reader =
- new BufferedReader(new FileReader(file));
- return read(reader);
- }
+ public static List<String> read(File file)
+ throws FileNotFoundException
+ {
+ BufferedReader reader =
+ new BufferedReader(new FileReader(file));
+ return read(reader);
+ }
- public static List<String> read(String s)
- {
- BufferedReader reader =
- new BufferedReader(new StringReader(s));
- return read(reader);
- }
+ public static List<String> read(String s)
+ {
+ BufferedReader reader =
+ new BufferedReader(new StringReader(s));
+ return read(reader);
+ }
- public static List<String> read(BufferedReader reader)
+ public static List<String> read(BufferedReader reader)
+ {
+ List<String> result = new ArrayList<String>();
+ try
{
- List<String> result = new ArrayList<String>();
- try
+ String prevline = "";
+ String line = "";
+ while ((line = reader.readLine()) != null)
+ {
+ int hash = line.indexOf("#");
+ if (hash >= 0)
+ line = line.substring(0,hash);
+ line = spaces(line);
+ line = (prevline + " " + line).trim();
+ if (line.endsWith("\\"))
{
- String prevline = "";
- String line = "";
- while ((line = reader.readLine()) != null)
- {
- int hash = line.indexOf("#");
- if (hash >= 0)
- line = line.substring(0,hash);
- line = spaces(line);
- line = (prevline + " " + line).trim();
- if (line.endsWith("\\"))
- {
- line = line.substring(0, line.length()-2);
- prevline = line;
- continue;
- }
- else
- {
- prevline = "";
- line = line.trim();
- if (line.length() > 0)
- result.add(line);
- }
- }
- reader.close();
+ line = line.substring(0, line.length()-2);
+ prevline = line;
+ continue;
}
- catch (IOException e)
+ else
{
- System.err.println("LineReader: I/O problem.");
- return null;
+ prevline = "";
+ line = line.trim();
+ if (line.length() > 0)
+ result.add(line);
}
- return result;
+ }
+ reader.close();
}
-
- public static List<String[]> tokens(List<String> lines)
+ catch (IOException e)
{
- List<String[]> result = new ArrayList<String[]>(lines.size());
- for (String line : lines)
- {
- String[] tokens = tokenize(line);
- result.add(tokens);
- }
- return result;
+ System.err.println("LineReader: I/O problem.");
+ return null;
}
+ return result;
+ }
- public static int maxTokens(List<String[]> tokens)
+ public static List<String[]> tokens(List<String> lines)
+ {
+ List<String[]> result = new ArrayList<String[]>(lines.size());
+ for (String line : lines)
{
- int result = 0;
- for (String[] t : tokens)
- if (t.length > result)
- result = t.length;
- return result;
+ String[] tokens = tokenize(line);
+ result.add(tokens);
}
+ return result;
+ }
- /**
+ public static int maxTokens(List<String[]> tokens)
+ {
+ int result = 0;
+ for (String[] t : tokens)
+ if (t.length > result)
+ result = t.length;
+ return result;
+ }
+
+ /**
Take line-oriented data and produce an array of doubles.
- */
- public static double[][] array(List<String> lines)
- {
- List<String[]> tokens = tokens(lines);
- int columns = maxTokens(tokens);
- int rows = lines.size();
- double[][] result = new double[rows][columns];
- for (int i = 0; i < rows; i++)
- for (int j = 0; j < columns; j++)
- {
- try
- {
- String v = tokens.get(i)[j];
- v = v.replaceAll(",", "");
- v = v.replaceAll("%", "");
- double d = Double.parseDouble(v);
- result[i][j] = d;
- }
- catch (NumberFormatException e)
- {
- throw new RuntimeException("Problem in row: " + i);
- }
- }
- return result;
- }
-
- public static String spaces(String line)
- {
- String result = "";
- for (int i = 0; i < line.length(); i++)
+ */
+ public static double[][] array(List<String> lines)
+ {
+ List<String[]> tokens = tokens(lines);
+ int columns = maxTokens(tokens);
+ int rows = lines.size();
+ double[][] result = new double[rows][columns];
+ for (int i = 0; i < rows; i++)
+ for (int j = 0; j < columns; j++)
+ {
+ try
{
- if (line.charAt(i) == '=' &&
- line.charAt(i+1) != '=' &&
- line.charAt(i-1) != '=')
- {
- result += " = ";
- }
- else
- result += line.substring(i,i+1);
+ String v = tokens.get(i)[j];
+ v = v.replaceAll(",", "");
+ v = v.replaceAll("%", "");
+ double d = Double.parseDouble(v);
+ result[i][j] = d;
}
- return result;
- }
+ catch (NumberFormatException e)
+ {
+ throw new RuntimeException("Problem in row: " + i);
+ }
+ }
+ return result;
+ }
- public static String[] tokenize(String line)
+ public static String spaces(String line)
+ {
+ String result = "";
+ for (int i = 0; i < line.length(); i++)
{
- if (line == null)
- return null;
- List<String> words = new ArrayList<String>();
- String[] ws = line.split("\\s");
- for (int i = 0; i < ws.length; i++)
- if (ws[i].length() > 0)
- words.add(ws[i]);
- String[] result = new String[words.size()];
- for (int i = 0; i < words.size(); i++)
- result[i] = words.get(i);
- return result;
+ if (line.charAt(i) == '=' &&
+ line.charAt(i+1) != '=' &&
+ line.charAt(i-1) != '=')
+ {
+ result += " = ";
+ }
+ else
+ result += line.substring(i,i+1);
}
+ return result;
+ }
- /*
+ public static String[] tokenize(String line)
+ {
+ if (line == null)
+ return null;
+ List<String> words = new ArrayList<String>();
+ String[] ws = line.split("\\s");
+ for (int i = 0; i < ws.length; i++)
+ if (ws[i].length() > 0)
+ words.add(ws[i]);
+ String[] result = new String[words.size()];
+ for (int i = 0; i < words.size(); i++)
+ result[i] = words.get(i);
+ return result;
+ }
+
+ /*
public static List<String> list(String line)
{
List<String> result = new ArrayList<String>();
@@ -155,5 +155,5 @@
result.add(tokens[i]);
return result;
}
- */
+ */
}
More information about the Swift-commit
mailing list