// Path: src/java/main/br/ufpe/cin/groundhog/parser/ParserException.java
// public class ParserException extends GroundhogException {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 2115582632203381099L;
// 
// 	public ParserException(String msg, Throwable cause) {
// 		super(msg, cause);
// 	}
// 	
// 	public ParserException() {
// 		super();
// 	}
// 
// 	public ParserException(String msg) {
// 		super(msg);
// 	}
// 
// 	public ParserException(Throwable cause) {
// 		super(cause);
// 	}
// }
// 
// Path: src/java/main/br/ufpe/cin/groundhog/parser/java/MutableInt.java
// public class MutableInt {
// 	int value;
// 	
// 	public MutableInt() {
// 		value = 1;
// 	}
// 	
// 	public MutableInt(int value) {
// 		this.value = value;
// 	}
// 
// 	public void increment() {
// 		++value;
// 	}
// 
// 	public int get() {
// 		return value;
// 	}
// 	
// 	@Override
// 	public String toString() {
// 		return String.valueOf(value);
// 	}
// }


import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map.Entry;
import au.com.bytecode.opencsv.CSVWriter;
import br.ufpe.cin.groundhog.parser.ParserException;
import br.ufpe.cin.groundhog.parser.java.MutableInt;
package br.ufpe.cin.groundhog.parser.java.formater;



/**
 * Creates the CSV representation of the extracted metrics The output file
 * groups data associated with each metric. Each metric has a set of entry value
 * that are printed one per line
 * 
 * @author drn2
 * @since 0.0.1
 */
public class CSVFormater extends Formater {

	@Override
	public String format(HashMap<String, HashMap<String, MutableInt>> object) {
		StringWriter result = new StringWriter();
		try {
			CSVWriter writer = new CSVWriter(result, ';');
			writer.writeNext(new String[] { "Metric", "Entry", "Value" });
			for (String metric : object.keySet()) {
				HashMap<String, MutableInt> counter = object.get(metric);
				for (Entry<String, MutableInt> entry : counter.entrySet()) {
					writer.writeNext(new String[] { metric, entry.getKey(), entry.getValue().toString() });
				}
			}
			writer.flush();
			writer.close();
			return result.toString();
		} catch (IOException e) {
			e.printStackTrace();
// Path: src/java/main/br/ufpe/cin/groundhog/parser/ParserException.java
// public class ParserException extends GroundhogException {
// 
// 	/**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 2115582632203381099L;
// 
// 	public ParserException(String msg, Throwable cause) {
// 		super(msg, cause);
// 	}
// 	
// 	public ParserException() {
// 		super();
// 	}
// 
// 	public ParserException(String msg) {
// 		super(msg);
// 	}
// 
// 	public ParserException(Throwable cause) {
// 		super(cause);
// 	}
// }
// 
// Path: src/java/main/br/ufpe/cin/groundhog/parser/java/MutableInt.java
// public class MutableInt {
// 	int value;
// 	
// 	public MutableInt() {
// 		value = 1;
// 	}
// 	
// 	public MutableInt(int value) {
// 		this.value = value;
// 	}
// 
// 	public void increment() {
// 		++value;
// 	}
// 
// 	public int get() {
// 		return value;
// 	}
// 	
// 	@Override
// 	public String toString() {
// 		return String.valueOf(value);
// 	}
// }


// Path: src/java/main/br/ufpe/cin/groundhog/parser/java/formater/CSVFormater.java
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map.Entry;
import au.com.bytecode.opencsv.CSVWriter;
import br.ufpe.cin.groundhog.parser.ParserException;
import br.ufpe.cin.groundhog.parser.java.MutableInt;

package br.ufpe.cin.groundhog.parser.java.formater;



/**
 * Creates the CSV representation of the extracted metrics The output file
 * groups data associated with each metric. Each metric has a set of entry value
 * that are printed one per line
 * 
 * @author drn2
 * @since 0.0.1
 */
public class CSVFormater extends Formater {

	@Override
	public String format(HashMap<String, HashMap<String, MutableInt>> object) {
		StringWriter result = new StringWriter();
		try {
			CSVWriter writer = new CSVWriter(result, ';');
			writer.writeNext(new String[] { "Metric", "Entry", "Value" });
			for (String metric : object.keySet()) {
				HashMap<String, MutableInt> counter = object.get(metric);
				for (Entry<String, MutableInt> entry : counter.entrySet()) {
					writer.writeNext(new String[] { metric, entry.getKey(), entry.getValue().toString() });
				}
			}
			writer.flush();
			writer.close();
			return result.toString();
		} catch (IOException e) {
			e.printStackTrace();
			throw new ParserException();