Skip to content

Commit

Permalink
added javadoc to methods and solved the CSVWriter closing twice probl…
Browse files Browse the repository at this point in the history
…em. Related to #10 and #20
  • Loading branch information
dnr2 committed Apr 26, 2013
1 parent ce08c74 commit a0c7cf7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/java/main/br/ufpe/cin/groundhog/parser/JavaParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public HashMap<String, HashMap<String, MutableInt>> parse() throws IOException {
}
}

/**
* Creates an object that represents the JSON result of the metrics.
* @return JSONObject that embodies the result
* @throws IOException throwed from use of the parse method
* @throws JSONException
*/
public JSONObject parseToJSON() throws IOException, JSONException {
JSONObject json = new JSONObject();
HashMap<String, HashMap<String, MutableInt>> counters = parse();
Expand All @@ -113,20 +119,25 @@ public JSONObject parseToJSON() throws IOException, JSONException {
}
}


/**
* Creates the CSV representation of the extracted metrics
* @return StringWriter that represents the CSV document
* @throws IOException
*/
public StringWriter parseToCSV() throws IOException {
StringWriter result = new StringWriter();
CSVWriter writer = new CSVWriter(result, ';');
StringWriter result = null;
HashMap<String, HashMap<String, MutableInt>> counters = parse();
if( counters != null ){
result = new StringWriter();
CSVWriter writer = new CSVWriter(result, ';');
for (Entry<String, HashMap<String, MutableInt>> entry : counters.entrySet()) {
writer.writeNext( new String[] { entry.getKey(), entry.getValue().toString() } );
}
writer.flush();
writer.close();
return result;
writer.close();
}
writer.close();
return null;
return result;
}

/**
Expand Down

1 comment on commit a0c7cf7

@gustavopinto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.