/*
 *  Evaluation of (existence of) arithmetic relations 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.jTMassPlatform.jTServices;

import jTMass.core.jALLL.jTObjects.TFail;
import jTMass.core.jALLL.jTObjects.TList;
import jTMass.core.jALLL.jTObjects.TObject;
import jTMass.core.jTMassPlatform.TPlatform;

public class TSArithmeticRelations extends TASSynchronousService{

    /* Relations:
      rel is > ("g") or = ("e") or < ("l") or <= ("ge") or >= ("le")
     * op((WN)Atom,(WN)Atom)  Atom rel Atom : Reg'=Reg
     *                        !(Atom rel Atom) : Reg=Fail
     * op(Atom,Atom) Reg=Fail
     * op(List,Atom) Reg=op(car(List), Atom)
     * op(Atom,List) Reg=op(Atom, car(List))
     * op(List,List) Reg=op(car(List),car(List))
     */

    @Override
    public TObject processService(TList parameters, String clientName, String serviceName){
        super.processService(parameters,clientName,serviceName);
        try{
        TObject relation,param1,param2;
        String relCode;

        relation=getIth(1,parameters);
        param1=getIth(2,parameters);
        Integer n1=this.objectToInteger(param1);
        param2=getIth(3,parameters);
        Integer n2=this.objectToInteger(param2);

        if(relation!=null){
            relCode=relation.getContent();

            if(relCode.contentEquals("g"))
                if(n1>n2)
                    return(null);
                else
                    return(new TFail());

            if(relCode.contentEquals("e"))
                if(n1==n2)
                    return(null);
                else
                    return(new TFail());

            if(relCode.contentEquals("l"))
                if(n1<n2)
                    return(null);
                else
                    return(new TFail());

            if(relCode.contentEquals("ge"))
                if(n1>=n2)
                    return(null);
                else
                    return(new TFail());

            if(relCode.contentEquals("le"))
                if(n1<=n2)
                    return(null);
                else
                    return(new TFail());
        }

        return(new TFail());

    }catch(Exception e){
        return(new TFail());
    }
        
    }

    public TSArithmeticRelations(TPlatform platform){
        super(platform);
    }

}