/*
 *  Agent's ALLL add list/plan action class
 *
 *  2004 - 2011 Frantisek Zboril jr.
 *  Faculty of Information Technology
 *  zborilf@fit.vutbr.cz
 *  http://www.fit.vutbr.cz/~zborilf
 *
 * (C) Brno University of Technology
 * Freeware licence VUT v Brně
 * https://wis.fit.vutbr.cz/FIT/db/dir.php/dr/VZ2007/externiInformace/softwareNaWebu/Priloha2_rozh23.pdf

 */

package jTMass.core.jAMass.jActions;
import jTMass.core.jAMass.*;
import jTMass.core.jALLL.jTObjects.*;


public class TAdd extends TAction {

    // ===== OBJECT CLONING =====

    @Override
    public TObject cloneObject(){
        TAdd newAdd=new TAdd((TList)PList.cloneObject());
	return(newAdd);
    }

    // ===== STRING CONTENT READERS =====

    @Override
    public String getActionName(){
        return("ADD");
    }

    @Override
    public String getContent(){
        return("+"+PList.getContent());
    }

    // ===== ACTION EXECUTION =====

    @Override
    public TObject execute(TAgent agent){
	
        super.execute(agent);
        TObject result=agent.getRegister(); 
        if(PList instanceof TPlan)
            agent.addPlan((TPlan)PList, true);
	else{
            TObject element;
            TList list;
            for(int i=0;i<PList.size();i++){
                element=PList.get(i);
            	if(element instanceof TList){
                    ((TList)element).setType(TConstants._Add);
                    agent.addBelief((TList)element);
		}
		else{
                    list=new TList(TConstants._Add);
                    list.add(element);
                    agent.addBelief(list);
		}
            }
	}
	return(result);
    }
	
    // ===== CONSTRUCTOR =====

    public TAdd(TList list){
        super(TConstants._Add);
	PList=list;
    }
	
}
