Magentix2  2.1.1
jason.stdlib.ia_add_to_date Class Reference
Inheritance diagram for jason.stdlib.ia_add_to_date:
Collaboration diagram for jason.stdlib.ia_add_to_date:

List of all members.

Public Member Functions

int getMinArgs ()
int getMaxArgs ()
void checkArguments (Term[] args) throws JasonException
Object execute (TransitionSystem ts, Unifier un, Term[] args) throws Exception

Detailed Description

This class represents the internal action for adding a number of years, months and days to a date defined bye the set year, month, day

Author:
Bexy Alfonso Espinosa

Definition at line 17 of file ia_add_to_date.java.


Member Function Documentation

void jason.stdlib.ia_add_to_date.checkArguments ( Term[]  args) throws JasonException

Definition at line 28 of file ia_add_to_date.java.

                                                                     {
                
                super.checkArguments(args);
                boolean result = true;
                int cont=0;
                while (result && (cont<9)) {
                        result = (((Term)args[cont]).isNumeric());
                        cont++;
                }

                if (!result)
                {
                        throw JasonException.createWrongArgument(this,"Parameters must be in correct format.");
                }
        }
Object jason.stdlib.ia_add_to_date.execute ( TransitionSystem  ts,
Unifier  un,
Term[]  args 
) throws Exception

Definition at line 50 of file ia_add_to_date.java.

                                                                                         {
        // execute the internal action
        ts.getAg().getLogger().fine("executing internal action 'jason.stdlib.ia_add_to_date'");
        
        int year = getTermAsInt(args[0]);
        int month = getTermAsInt(args[1]);
        int day = getTermAsInt(args[2]);

        int addy = getTermAsInt(args[3]);
        int addm = getTermAsInt(args[4]);
        int addd = getTermAsInt(args[5]);
        
        //SimpleDateFormat f = new SimpleDateFormat("dd/MM/yyyy"); 
        Calendar c = Calendar.getInstance();
        c.set(year, month-1, day);
        c.add(Calendar.YEAR, addy);
        c.add(Calendar.MONTH, addm);
        c.add(Calendar.DAY_OF_YEAR, addd);
        NumberTermImpl resulty  = new NumberTermImpl(c.get(Calendar.YEAR));
        NumberTermImpl resultm  = new NumberTermImpl(c.get(Calendar.MONTH)+1);
        NumberTermImpl resultd  = new NumberTermImpl(c.get(Calendar.DAY_OF_MONTH));
                
                boolean result = ((un.unifies(resulty, args[6]))&&(un.unifies(resultm, args[7]))&&(un.unifies(resultd, args[8])));
        
        /*if (true) { // just to show how to throw another kind of exception
            throw new JasonException("not implemented!");
        }*/
        
        // everything ok, so returns true
        return result;
    }

Definition at line 25 of file ia_add_to_date.java.

{ return 9; };

Definition at line 24 of file ia_add_to_date.java.

{ return 9; };

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables