Skip to content

Commit

Permalink
split on any whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
fbielejec committed Mar 11, 2016
1 parent 69c0d59 commit d315849
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/parsers/DiscreteLocationsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public DiscreteLocationsParser(String locationsFilename, boolean header) {

}// END: Constructor

public LinkedList<Location> parseLocations() throws IOException,
AnalysisException {
public LinkedList<Location> parseLocations() throws IOException, AnalysisException {

LinkedList<Location> locationsList = new LinkedList<Location>();

Expand All @@ -40,12 +39,13 @@ public LinkedList<Location> parseLocations() throws IOException,
int nrow = lines.length;
for (int i = 0; i < nrow; i++) {

String[] line = lines[i].split("\t");
// String[] line = lines[i].split("\t");
// TODO:test
String[] line = lines[i].split("\\s+");

if (line.length != 3) {
throw new AnalysisException(
"Incorrect number of columns in locations file. Expecting 3, found "
+ line.length);
"Incorrect number of columns in locations file. Expecting 3, found " + line.length);
}

String locationName = line[0];
Expand All @@ -55,8 +55,8 @@ public LinkedList<Location> parseLocations() throws IOException,
String illegalCharacter = "+";
if (locationName.contains(illegalCharacter)) {

throw new AnalysisException("Location " + locationName
+ " contains illegal character " + illegalCharacter);
throw new AnalysisException(
"Location " + locationName + " contains illegal character " + illegalCharacter);

}

Expand Down
17 changes: 8 additions & 9 deletions src/parsers/LogParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public LogParser(String log, Double burnin) {
public Double[][] parseIndicators() throws IOException, AnalysisException {

String[] lines = Utils.readLines(logFilename, Utils.HASH_COMMENT);
columnNames = lines[HEADER_ROW].split("\t");
// columnNames = lines[HEADER_ROW].split("\t");
// TODO: test:
columnNames = lines[HEADER_ROW].split("\\s+");

int nrow = lines.length - 1;

Expand All @@ -49,8 +51,8 @@ public Double[][] parseIndicators() throws IOException, AnalysisException {
int ncol = columns.size();
// this should be enough when sth silly is parsed
if (ncol == 0) {
throw new AnalysisException("No " + Utils.INDICATORS
+ " columns found. I suspect wrong or malformed log file.");
throw new AnalysisException(
"No " + Utils.INDICATORS + " columns found. I suspect wrong or malformed log file.");
}

int skip = (int) ((burnin / 100 * nrow));
Expand All @@ -67,19 +69,16 @@ public Double[][] parseIndicators() throws IOException, AnalysisException {
for (int col = 0; col < ncol; col++) {

if (columns.get(col) > line.length) {
System.out
.println("Empty or malformed input at line "
+ (row + SKIPPED_LINES)
+ " inside log file. Resulting output may not be correct!");
System.out.println("Empty or malformed input at line " + (row + SKIPPED_LINES)
+ " inside log file. Resulting output may not be correct!");

// copy array with one less row
indicators = cloneArray(indicators, i);
break;

} else {

indicators[i][col] = Double.valueOf(line[columns
.get(col)]);
indicators[i][col] = Double.valueOf(line[columns.get(col)]);

}

Expand Down

0 comments on commit d315849

Please sign in to comment.