package jforex;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import com.dukascopy.api.*;
import com.dukascopy.api.Library;

/**
 *
 * @author Dominique
 */

@RequiresFullAccess
@Library("C:\\Users\\dominique.vita\\Documents\\NetBeansProjects\\Depedency\\maximux.jar;"
        + "C:\\Users\\dominique.vita\\Documents\\NetBeansProjects\\Depedency\\risultado.jar;"
        + "C:\\Users\\dominique.vita\\Documents\\NetBeansProjects\\Depedency\\add_inJava.jar;"
        + "C:\\Users\\dominique.vita\\Documents\\NetBeansProjects\\Depedency\\javabuilder.jar")


public class Strategy implements IStrategy {

    /**
     * @param args the command line arguments
     */
    
    private IEngine engine = null ; 
    private IConsole console; 
    private IHistory history; 
    private IContext context;
    
    
    
    /*public static void main(String[] args) {
        // TODO code application logic here
        
        //Making calculation function, simple two argument function
        make_calcule();
        
        //Making calculation function using an array as parameter
        find_maximux();
        
        
        
    }*/
    
    static double make_calcule(){
        
        long startTime = System.currentTimeMillis(); 
        System.out.println("yap, this is the one");
        
        
        addJava cls = null;
        Object[] x = {1,7.8}; //we position the parameters 
        Object[] y = null;
        double res = 0; 

   try
   {
      cls = new addJava();
      y = cls.addition(1, x);
     // y = cls.mysum(1, x);
      res = ((MWNumericArray)y[0]).getDouble(1);
     // return ((MWNumericArray)y[0]).getDouble(1);
      System.out.println("le resultat est "+ res);
      long estimatedTime = System.currentTimeMillis()- startTime; 
      
      System.out.println("the time which took is "+estimatedTime);
      
   } catch (MWException e){
       System.err.println("We get a IOException "+e.toString());
   
   }
   
        finally
        {
            MWArray.disposeArray(y);
            if (cls != null)
                    cls.dispose();
        }
    
        return(res);
    }
    
    static double find_maximux(){
    
        long startTime = System.currentTimeMillis(); 
        maximux maxy = null;
        Object[] x = null;
        Object[] y = null;
        
        int[] vals = {1,1,2,11,47,10,0,23,59,41,4};
        double res = 0; 
        System.out.println(vals[3]);
   try
   {
      x = new Object[vals.length];
      for (int i = 0; i < vals.length; i++)
         x[i] = new MWNumericArray(vals[i], MWClassID.DOUBLE);

      maxy = new maximux();
      y = maxy.maximux(1,x);
     // return ((MWNumericArray)y[0]).getDouble(1);
      
       res = ((MWNumericArray)y[0]).getDouble(1);
     // return ((MWNumericArray)y[0]).getDouble(1);
      System.out.println("le resultat est "+ res);
      
      long estimatedTime = System.currentTimeMillis()- startTime; 
      System.out.println("the time which took is "+estimatedTime);
   }
   
     catch (MWException e){
       System.err.println("We get a IOException "+e.toString());
   
   }
        finally
        {
            MWArray.disposeArray(x);
            MWArray.disposeArray(y);
            if (maxy != null)
                maxy.dispose();
        }
    
        return(res);
    }

    @Override
    public void onStart(IContext context) throws JFException {
        //throw new UnsupportedOperationException("Not supported yet.");
        
        //we initiate the context as in tutorial 
        this.engine = context.getEngine(); 
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context; 
        
        double maximux = 0 ; 
        double calculate = 0 ;
        maximux = find_maximux(); 
        calculate = make_calcule(); 
        
        console.getOut().println("this is vey great "+maximux+"  and "+calculate);
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void onMessage(IMessage message) throws JFException {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void onAccount(IAccount account) throws JFException {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void onStop() throws JFException {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

}
