package project_2;

public class Equation {

	private	 String postfixLeft=null;
	private String postfixRight=null;
	private String resultLeft=null;
	private String resultRight=null;
	private String equation=null;
	private String rightEquation=null;
	private String leftEquation=null;
	private Boolean isEquals=false;
	private Boolean validLeft=false;
	private Boolean validRight=false;


	public Equation(String equation) {
		this.equation= equation;
		DoEveryThing();
	}

	public boolean isEquals(){

		if(resultLeft==null || resultRight==null)
			return false;

		isEquals=resultLeft.equals(resultRight);
		return isEquals;

	}

	private void DoEveryThing(){
		try {
			
	
			String []array = equation.split("[=]");
			
			leftEquation=array[0];
			rightEquation=array[1];

			validLeft=CheckValid.checkEquation(leftEquation);
			validRight = CheckValid.checkEquation(rightEquation);

			if(validLeft){
				
				postfixLeft = InfixToPos.EvaluateInfix(leftEquation);
				resultLeft = PostfixEval.evaluate(postfixLeft);
				
			}
			if(validRight){
				
				postfixRight = InfixToPos.EvaluateInfix(rightEquation);
				resultRight = PostfixEval.evaluate(postfixRight);
	
			}
			
		} 
		catch (Exception e) {
			return;
		}
	}

	public boolean isValidLeft(){
		return(validLeft && resultLeft!=null);

	}
	public boolean isValidRight(){
		return (validRight && resultRight!=null);
	
	}

	public boolean isEquationValid(){
		return isValidLeft() && isValidRight();
	}

	public String getResultRight() {
		return resultRight;
	}

	public String getRightEquation() {
		return rightEquation;
	}
	public String getResultLeft() {
		return resultLeft;
	}

	public String getLeftEquation() {
		return leftEquation;
	}

	public String getPostfixLeft() {
		return postfixLeft;
	}

	public String getPostfixRight() {
		return postfixRight;
	}

	
	public Boolean getIsEquals() {
		return resultLeft.equals(resultRight);
	}

	public Boolean getValidLeft() {
		return isValidLeft();
	}

	public Boolean getValidRight() {
		return isValidRight();
	}

	@Override
	public String toString() {
		return "Equation [equation=" + equation + "]";
	}



}
