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

import java.util.LinkedList;

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

    char unarna;
    String operand = "";
    char negacia = '¬';
    LinkedList<Integer> zalAktual = new LinkedList<Integer>();

    ////////////////////////////////////////////
//////////////////////////////////////////
    public void saveAktual(LinkedList<Integer> A)
    {
        zalAktual.addAll(A);
    }

    public int getAktualPoc() 
    {
        return zalAktual.size();
    }

    public int loadExAktual(int i)
    {
        return zalAktual.get(i);
    }

    public char getUnarna()
    {
        return unarna;
    }

    public void setUnarna(char x)
    {
        this.unarna = x;
    }

    public String getOperand()
    {
        return operand;
    }

    public void setOperand(String s) 
    {
        this.operand = s;
    }

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

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

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

    public UzolUnarny(Uzol o, String c) 
    {

        super(o);

        unarna = c.charAt(0);
        operand = "";
        for (int i = 1; i < c.length(); i++)
        {
            operand += c.charAt(i);
        }

        if (unarna != '¬') 
        {
        //   System.out.println("pocet1 je "+utils.vars.size());
        //   for (int i=0; i<utils.vars.size();i++) System.out.println("-555-"+utils.vars.get(i)+"-");
        //   System.out.println("operand je "+operand);
        //  System.out.println("o"+utils.vars.indexOf(operand));

        /*                 premenoianiae
        if (utils.vars.contains(new String(operand))==true)
        {
        //     System.out.println("6666666666666");
        //    System.out.println("66666666666667777777777");
        //   System.out.println("o"+utils.vars.indexOf(operand));
        // System.out.println("p"+(utils.pocty.get(utils.vars.indexOf(operand))));
        utils.pocty.set(utils.vars.indexOf(operand),new Integer(utils.pocty.get(utils.vars.indexOf(operand))+1));
        operand+=""+utils.pocty.get(utils.vars.indexOf(operand));
        //      System.out.println("o"+operand);
        //     System.out.println("o"+utils.vars.indexOf(operand));
        // System.out.println("p"+(utils.pocty.get(utils.vars.indexOf(operand))));
        //    System.out.println("6666666666666777777777788888888");
        }
        else
        {
        utils.vars.add(new String(operand));
        //                            System.out.println("pocet2 je "+utils.vars.size());
        //                      System.out.println("7777777 pridane "+operand);
        utils.pocty.add(new Integer(1));
        }
         */ //premenovanie
        //   System.out.println("UUUUUUUUUUUUU "+c+"  "+operand+" "+utils.vars.get(utils.vars.indexOf(operand))+" "+utils.pocty.get(utils.vars.indexOf(operand)));
        }

    }

    public Uzol add(Uzol u)
    {
        lavy = u;
        return this.lavy;
    }
    /*
    public int simplify()
    {
    return 0;
    }
     */
    /*	public int solve() 
    {
    switch (c) 
    {
    case 'x' : return x; 
    case 'y' : return y; 
    default : return 0;
    }	
    }
     */

    public void vypis()
    {
    
        if (this.lavy != null) 
        {
            //System.out.print("(");

            if (unarna == negacia) 
            {

                f.vypis2("" + unarna + "(");
                this.lavy.vypis();
                f.vypis2(")");

            }
            else
            {

                f.vypis2("" + unarna + operand);

                //if  (!(this.lavy instanceof UzolUnarny)) f.vypis2("(");

                this.lavy.vypis();
            }
        //if  (!(this.lavy instanceof UzolUnarny)) f.vypis2(")");
        }

    }
 public void _vypis()
    {
    
        if (this.lavy != null) 
        {
            //System.out.print("(");

            if (unarna == negacia) 
            {

                f._vypis2("" + unarna + "(");
                this.lavy._vypis();
                f._vypis2(")");

            }
            else
            {

                f._vypis2("" + unarna + operand);

                //if  (!(this.lavy instanceof UzolUnarny)) f.vypis2("(");

                this.lavy._vypis();
            }
        //if  (!(this.lavy instanceof UzolUnarny)) f.vypis2(")");
        }

    }

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

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

    @Override
    public void setPravySyn(Uzol u)
    {
    //
    }

  
}
