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

import java.util.LinkedList;

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

    public String operand;
    public String predikat = "";
    public int pocetOperandov = 0;
    String pomOperand;
    String o1, o2, o3;
    Boolean aritmeticky = false;
    public LinkedList<String> operandy = new LinkedList<String>();

    public String getOperand() 
    {
        return this.operand;
    }

    public void setOperand(int i, String n)
    {
        operandy.set(i, new String(n));
    }

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

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

    public UzolOperand(Uzol o, String operand) 
    {
        super(o);
        this.operand = operand;
        int p = 0;
        //ak tam vobec nie je ziadna zatvorka a teda ani operand
        //ked je to klasicky predikat 
       
        if ((operand.contains("(")) && (operand.contains(")"))) 
        {

            while (operand.charAt(p) != '(')
            {
                predikat += operand.charAt(p);
                p++;
            }
            p++;

            while (operand.charAt(p) != ')')
            
            {
                pomOperand = "";
                while ((operand.charAt(p) != ',') && (operand.charAt(p) != ')')) 
                {
                    pomOperand += operand.charAt(p);
                    p++;
                }
                //System.out.println("888888888888"+pomOperand);
        /* premenovanie
                if ((utils.vars.contains(pomOperand)) && (utils.pocty.get(utils.vars.indexOf(pomOperand))!=1)) { pomOperand+=utils.pocty.get(utils.vars.indexOf(pomOperand)); System.out.println("999999999"+pomOperand); }
                 */
                operandy.add(pomOperand);
                
                if (operand.charAt(p) != ')')
                {
                    p++;
                }
                pocetOperandov++;
            }

        /*   f.vypis("xxxxxxxxxxxx");
        f.vypis2("predikat je "+predikat);
        for (int i=0; i<pocetOperandov;i++) f.vypis2(""+operandy.get(i)+" ");
        f.vypis("xxxxxxxxxxxx"); */
        } // ak je to nejaky aritmeticky vyraz a spolieham sa na to ze v strede je nejake aritmeticke znamienko
        else 
        {
            o1 = o3 = "";
            aritmeticky = true;
            o2 = "";
            for (int i = 0; i < operand.length(); i++)
            {

                if ((operand.charAt(i) != '<') && (operand.charAt(i) != '>') && (operand.charAt(i) != '=') && (operand.charAt(i) != '!')) 
                {
                   
                    if (o2.equals("")) {
                        o1 += operand.charAt(i);
                    } 
                    else 
                    {
                        o3 += operand.charAt(i);
                    }
                } 
                else
                {
                    o2 += operand.charAt(i);
                }

            }

        /* f.vypis("yyyyyyyyyyyyyyyyyy "+o1+" "+o2+" "+o3); */
        }
    }

    public Uzol add(Uzol u)
    {
        return null;
    }
   

    public void vypis() 
    {
        //System.out.print(""+operand);
        // f.vypis2(""+operand);
        if (aritmeticky) {
            f.vypis2("(" + o1 + o2 + o3 + ")");

        } 
        else 
        {
            f.vypis2("" + predikat + "(");
           
            for (int i = 0; i < pocetOperandov; i++) 
            {
                f.vypis2("" + operandy.get(i));
               
                if (i != pocetOperandov - 1) 
                {
                    f.vypis2(",");
                }
            }
            f.vypis2(")");
        }
    }
 public void _vypis() 
    {
        //System.out.print(""+operand);
        // f.vypis2(""+operand);
        if (aritmeticky) {
            f.vypis2("(" + o1 + o2 + o3 + ")");

        } 
        else 
        {
            f._vypis2("" + predikat + "(");
           
            for (int i = 0; i < pocetOperandov; i++) 
            {
                f._vypis2("" + operandy.get(i));
               
                if (i != pocetOperandov - 1) 
                {
                    f._vypis2(",");
                }
            }
            f._vypis2(")");
        }
    }
    @Override
    public Uzol getLavySyn()
    {
        return lavy;
    }

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

    @Override
    public void setLavySyn(Uzol u) 
    {
        lavy = u;
    }

    @Override
    public void setPravySyn(Uzol u)
    {
        pravy = u;
    }
}
