<commit_before>package manager;

import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import backend.Board;
import backend.Box;
import backend.Content;
import backend.Floor;
import backend.Ice;
import backend.Interruptor;
import backend.Player;
import backend.Target;
import backend.Tree;
import exceptions.ParsingException;

public class Parser {

	private int columns = 0;
	private int rows = 0;
	private Board board;
	boolean playerExists = false;
	private static final char PLAYER = '@';
	private static final char BOX = 'B';
	private static final char TARGET = 'G';
	private static final char TREE = 'T';
	private static final char WATER = '#';
	private static final char ICE = 'C';
	private static final char INTERRUPTOR = 'K';

	/**
	 * This method parses a file to check if all the data is correct.
	 * 
	 * @param file
	 *            An input file where to obtain the data from.
	 * @return A board created with the data from the file.
	 * @throws IOException
	 *             If the file couldn't be opened.
	 */

	public Board parse(File file) throws IOException {
		String line;
		BufferedReader buffer = null;
		try {
			buffer = new BufferedReader(new FileReader(file));
			while ((line = (buffer.readLine())) != null) {
				line = deleteTabs(line);
				if (line.length() > 1) {
					if (columns == 0) {
						columns = line.length();
					}
					if (line.length() != columns) {
						throw new ParsingException();
					}
					rows++;
				}
			}
			System.out.println(rows);
			System.out.println(columns);
			board = new Board(rows, columns);
			if (buffer != null) {
				buffer.close();
			}

			buffer = new BufferedReader(new FileReader(file));
			rows = 0;
			while ((line = (buffer.readLine())) != null) {
				line = deleteTabs(line);
				checkElementsValues(line, rows);
				rows++;
			}
			return board;
		} finally {
			if (buffer != null) {
				buffer.close();
			}
		}
	}

	/**
	 * This method deletes every tab from a string.
	 * 
	 * @param line
	 *            A string representing a line of the file.
	 * @return A new string without tabs.
	 */
	private String deleteTabs(String line) {
		char aux;
		String resp = new String();
		for (int i = 0; i < line.length(); i++) {
			if ((aux = line.charAt(i)) != '\t')
				resp += aux;
		}
		return resp;
	}

	/**
	 * This method checks each element values to see if they are correct.
	 * 
	 * @param line
	 *            An array of strings representing each of the parameters of a
	 *            line separated by a comma.
	 */
	private void checkElementsValues(String line, int rowActual) {
		int index = 0;
		Content element = null;
		Point p;
		char symbol;

		if (line.length() != columns) {
			throw new ParsingException();
		}
		while (index < columns) {
			p = new Point(rowActual, index);
			System.out.println(rowActual);
			System.out.println(index);
			symbol = line.charAt(index);
			System.out.println(symbol);
			checkSymbolExistance(symbol);
			switch (symbol) {
			case PLAYER: {
				board.putCell(new Floor(), p);
				element = new Player(p, board);
				board.putContent(element, p);
				board.setPlayer((Player) element);
				playerExists = true;
				break;
			}
			case BOX: {
				board.putCell(new Floor(), p);
				element = new Box(p, board);
				board.putContent(element, p);
				break;
			}
			case TARGET: {
				board.putCell(new Target(), p);
				break;
			}
			case TREE: {<commit_msg>saque los prints q taban de mas en el parser<commit_after>package manager;

import java.awt.Point;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import backend.Board;
import backend.Box;
import backend.Content;
import backend.Floor;
import backend.Ice;
import backend.Interruptor;
import backend.Player;
import backend.Target;
import backend.Tree;
import exceptions.ParsingException;

public class Parser {

	private int columns = 0;
	private int rows = 0;
	private Board board;
	boolean playerExists = false;
	private static final char PLAYER = '@';
	private static final char BOX = 'B';
	private static final char TARGET = 'G';
	private static final char TREE = 'T';
	private static final char WATER = '#';
	private static final char ICE = 'C';
	private static final char INTERRUPTOR = 'K';

	/**
	 * This method parses a file to check if all the data is correct.
	 * 
	 * @param file
	 *            An input file where to obtain the data from.
	 * @return A board created with the data from the file.
	 * @throws IOException
	 *             If the file couldn't be opened.
	 */

	public Board parse(File file) throws IOException {
		String line;
		BufferedReader buffer = null;
		try {
			buffer = new BufferedReader(new FileReader(file));
			while ((line = (buffer.readLine())) != null) {
				line = deleteTabs(line);
				if (line.length() > 1) {
					if (columns == 0) {
						columns = line.length();
					}
					if (line.length() != columns) {
						throw new ParsingException();
					}
					rows++;
				}
			}
			System.out.println(rows);
			System.out.println(columns);
			board = new Board(rows, columns);
			if (buffer != null) {
				buffer.close();
			}

			buffer = new BufferedReader(new FileReader(file));
			rows = 0;
			while ((line = (buffer.readLine())) != null) {
				line = deleteTabs(line);
				checkElementsValues(line, rows);
				rows++;
			}
			return board;
		} finally {
			if (buffer != null) {
				buffer.close();
			}
		}
	}

	/**
	 * This method deletes every tab from a string.
	 * 
	 * @param line
	 *            A string representing a line of the file.
	 * @return A new string without tabs.
	 */
	private String deleteTabs(String line) {
		char aux;
		String resp = new String();
		for (int i = 0; i < line.length(); i++) {
			if ((aux = line.charAt(i)) != '\t')
				resp += aux;
		}
		return resp;
	}

	/**
	 * This method checks each element values to see if they are correct.
	 * 
	 * @param line
	 *            An array of strings representing each of the parameters of a
	 *            line separated by a comma.
	 */
	private void checkElementsValues(String line, int rowActual) {
		int index = 0;
		Content element = null;
		Point p;
		char symbol;

		if (line.length() != columns) {
			throw new ParsingException();
		}
		while (index < columns) {
			p = new Point(rowActual, index);
			symbol = line.charAt(index);
			checkSymbolExistance(symbol);
			switch (symbol) {
			case PLAYER: {
				board.putCell(new Floor(), p);
				element = new Player(p, board);
				board.putContent(element, p);
				board.setPlayer((Player) element);
				playerExists = true;
				break;
			}
			case BOX: {
				board.putCell(new Floor(), p);
				element = new Box(p, board);
				board.putContent(element, p);
				break;
			}
			case TARGET: {
				board.putCell(new Target(), p);
				break;
			}
			case TREE: {
{'fraction_non_alphanumeric': 0.12088072324292796, 'fraction_numerical': 0.002041411490230388, 'mean_word_length': 2.853370786516854, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6504345', 'n_tokens_mistral': 2532, 'n_tokens_neox': 2099, 'n_words': 710}