package lipstone.joshua.parser.util;
import java.util.ArrayList;
import lipstone.joshua.parser.exceptions.ParserException;
import lipstone.joshua.parser.types.Matrix;
public class Equation {
public ArrayList<Matrix> matrices = new ArrayList<Matrix>();
public String eqn = "";
public String answer = "";
public boolean hasError = false;
public Equation() {
matrices = new ArrayList<Matrix>();
eqn = "";
answer = "";
}
public Equation(String matrices, String eqn, String answer, boolean hasError) throws ParserException {
this.matrices = new ArrayList<Matrix>();
parseMatrices(matrices);
this.eqn = eqn;
this.answer = answer;
this.hasError = hasError;
}
public Equation(Equation equation) {
for (Matrix mat : equation.matrices)
this.matrices.add(mat);
this.eqn = new String(equation.eqn);
this.answer = new String(equation.answer);
this.hasError = new Boolean(equation.hasError);
}
@Override
public String toString() {
return eqn + " -> " + answer;
}
public String getMatrices() {
String output = "";
for (Matrix m : matrices) {
output = output + m.toString() + ",";
}
if (output.length() > 1)
output = output.substring(0, output.length() - 1);
return output;
}
private void parseMatrices(String input) throws ParserException {
if (input.contains("{"))
input = input.substring(input.indexOf("{"));
while (input.contains("}")) {
matrices.add(new Matrix(input.substring(0, input.indexOf("}"))));
if (input.indexOf("{", input.indexOf("}")) >= 0)
input = input.substring(input.indexOf("{", input.indexOf("}")));
else
break;
}
}
}