/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

/**
 *
 * @author chislim
 */
public class UzolOperacia extends Uzol
{

    Character sign;

    public void setSign(char x)
    {
        this.sign = x;
    }

    public char getSign() 
    {
        return this.sign;
    }

    public void setPravySyn(Uzol u) 
    {
        this.pravy = u;
    }

    public void setLavySyn(Uzol u)
    {
        this.lavy = u;
    }

    public void setOtec(Uzol u) 
    {
        this.otec = u;
    }

    public Uzol getOtec()
    {
        return this.otec;
    }

    public UzolOperacia(Uzol o, Character s)
    {
        super(o);
        this.sign = s;
    }

    public Uzol add(Uzol u) 
    {
        if (lavy == null)
        {
            lavy = u;
            return this.lavy;
        } 
        else
        {
            pravy = u;
            return this.pravy;
        }
    }
    /*	
    public int simplify()
    {
    if ((this.lavy instanceof uzolOperand) && (this.pravy instanceof uzolOperand))
    {
    int a,b,c=0;
    switch (sign)
    {
    case '+' : 
    a=0; 
    b=0; 
    if (this.lavy!=null) a=this.lavy.simplify();
    if (this.pravy!=null) b=this.pravy.simplify();
    c=a+b;
    break;
    case '*' : 
    a=0; 
    b=0; 
    if (this.lavy!=null) a=this.lavy.simplify();
    if (this.pravy!=null) b=this.pravy.simplify();
    c=a*b;
    break;
    case '-' : 
    a=0; 
    b=0; 
    if (this.lavy!=null) a=this.lavy.simplify();
    if (this.pravy!=null) b=this.pravy.simplify();
    c=a-b;
    break;
    default : c=0;
    }
    Uzol novy=new uzolOperand(this.otec,c);
    if (this==this.otec.lavy) this.otec.lavy=novy;
    else  this.otec.pravy=novy;
    }
    if (lavy!=null) this.lavy.simplify();
    if (pravy!=null) this.pravy.simplify();
    return 0;
    }
     */
    /*	
    public int solve() 
    {
    int a,b;
    switch (sign)
    {
    case '+' : 
    a=0; 
    b=0; 
    if (this.lavy!=null) a=this.lavy.solve();
    if (this.pravy!=null) b=this.pravy.solve();
    return a+b;
    case '*' : 
    a=0; 
    b=0; 
    if (this.lavy!=null) a=this.lavy.solve();
    if (this.pravy!=null) b=this.pravy.solve();
    return a*b;
    case '-' : 
    a=0; 
    b=0; 
    if (this.lavy!=null) a=this.lavy.solve();
    if (this.pravy!=null) b=this.pravy.solve();
    return a-b;
    default : return 99999;
    }
    }
     */

    public void vypis() 
    {
        if ((this.lavy != null) && (this.pravy != null)) 
        {
            System.out.print("(");
            f.vypis2("(");
            this.lavy.vypis();
            System.out.print(this.sign);
            f.vypis2("" + this.sign);
            this.pravy.vypis();
            System.out.print(")");
            f.vypis2(")");
        }
    }

    @Override
    public Uzol getLavySyn() 
    {
        return lavy;
    }

    @Override
    public Uzol getPravySyn()
    {
        return pravy;
    }

    @Override
    public void _vypis() {
             if ((this.lavy != null) && (this.pravy != null)) 
        {
            System.out.print("(");
            f._vypis2("(");
            this.lavy._vypis();
            System.out.print(this.sign);
            f._vypis2("" + this.sign);
            this.pravy._vypis();
            System.out.print(")");
            f._vypis2(")");
        }
    }
}
