package org.aksw.simba.sparqlbench.cli;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.aksw.simba.benchmark.Similarity;
import org.aksw.simba.sparqlbench.centroid.KmeansPlusPlus;
import org.aksw.simba.sparqlbench.feasible.FEASIBLEClustering;
import org.aksw.simba.sparqlbench.feasible.FeasibleExemplars;
import org.aksw.simba.sparqlbench.featurevectors.FeatureVector;
import org.aksw.simba.sparqlbench.hierarchical.Agglomerative;
import org.aksw.simba.sparqlbench.hybrid.DbscanAndKMeansPluPlus;
import org.aksw.simba.sparqlbench.random.RandomSelection;
import org.aksw.simba.sparqlbench.rdf.PrintBenchmark;
import org.apache.commons.math3.ml.clustering.CentroidCluster;
import org.apache.commons.math3.ml.clustering.DoublePoint;
import org.apache.commons.math3.ml.clustering.KMeansPlusPlusClusterer;
import org.apache.commons.math3.ml.clustering.MultiKMeansPlusPlusClusterer;
import org.openrdf.query.MalformedQueryException;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.repository.RepositoryException;
import org.openrdf.rio.RDFHandlerException;

public class Benchmarks {

	public static void main(String[] args) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFHandlerException, IOException {
		// TODO Auto-generated method stub
// java -jar sqcframwork.jar -m {feasible, km++, db+km++, aglo}
		// km++ 
		//int noQueries = 15;  //same as number of clusters. we need to pick one query from each cluster
		//int maxItrerations = 10; 
		//int noTrialRun = 10;
	//	String endpointURL = "http://localhost:8890/sparql";	 //The endpoint URL containing the containment RDF data
	//	String queryFile = "../SQCFramework/personalized-query.txt";
		String methodParam = "-m";
		String method = getParamVal(args,methodParam);
		System.out.println("Clustering method parameter is: "+method);
		if(method==null){
			        isMedatory(method);
					invalidKmeansPlusPlusFormat();}
		else if (method.equals("km++"))
				    callKMeansPlusPlus(args);
		else if(method.equals("db+km++"))
			callDBPlusKMeansPlusPlus(args);
		else if(method.equals("feasible"))
			callFeasible(args);
		else if(method.equals("feasible-exmp"))
			callFeasibleExemplars(args);
		else if(method.equals("random"))
			callRandomSelection(args);
		else if(method.equals("agglomerative"))
			callAglomerative(args);
		else
			printGeneralFormat();
		
	}

	private static void callAglomerative(String[] args) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFHandlerException, IOException {
		int noQueries = 0; 
		String endpointURL, queryFile,outputFile = null;
	   String	param = "-n";
       String	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidAgglomerativeFormat();}
    	try{
    	noQueries =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the number of queries -n should be an integer");invalidAgglomerativeFormat(); }
   	param = "-e";
    	endpointURL = getParamVal(args,param);
    	if(endpointURL==null){
	        isMedatory(param);
	        invalidAgglomerativeFormat();} 	
    	param = "-q";
    	queryFile = getParamVal(args,param);
    	if(queryFile==null){
	        isMedatory(param);
	        invalidAgglomerativeFormat();}   	
    	param = "-o";
    	outputFile = getParamVal(args,param);
    	if(outputFile==null){
	        isMedatory(param);
	        invalidAgglomerativeFormat();}
    	Agglomerative.runAgglomerative(noQueries, endpointURL, queryFile, outputFile);
		
	}

	private static void printGeneralFormat() {
		System.err.println("\n\n Invalid format. The general formats are: ");
		System.err.println("### DBSCAN+Kmeans++ Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -i <maxNoIterations> -t <noTrialRun> -e <endpointUrl> -q <queryPersonalized> -r <radius> -p <minPts> -o <outputFile>");
		System.err.println("method = db+km++");
		System.err.println("noQueries = Number of queries in the benchmark");
		System.err.println("maxNoIterations = Maximum number of iterations for the clustering algorithm");
		System.err.println("noTrialRun = Number of trial run for the clustering algorithm");
		System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
		System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
		System.err.println("radius = Radius for the queries to be considered as outliers");
		System.err.println("minPts = Minimum points or queries in a cluster");
		System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
		System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m db+km++   -n 15   -i 10   -t 10   -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -r 1   -p 1   -o db+km++-10QA-benchmark.ttl");
	
		System.err.println("\n\n### Kmeans++ Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -i <maxNoIterations> -t <noTrialRun> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
		System.err.println("method = km++");
		System.err.println("noQueries = Number of queries in the benchmark");
		System.err.println("maxNoIterations = Maximum number of iterations for the clustering algorithm");
		System.err.println("noTrialRun = Number of trial run for the clustering algorithm");
		System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
		System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
		System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
		System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m km++   -n 15   -i 10   -t 10   -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o km++-10QA-benchmark.ttl");
	
		//	System.err.println("Invalid format: values for -m, -n, -q, -e are mendatory parameters.");
			System.err.println("\n\n### FEASIBLE Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
			System.err.println("method = feasible");
			System.err.println("noQueries = Number of queries in the benchmark");
			System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
			System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
			System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
			System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m feasible   -n 15  -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o feasible-10QA-benchmark.ttl");

			System.err.println("\n\n### Agglomerative Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
			System.err.println("method = agglomerative");
			System.err.println("noQueries = Number of queries in the benchmark");
			System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
			System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
			System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
			System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m agglomerative   -n 15  -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o agglomerative-10QA-benchmark.ttl");
			
			System.err.println("\n\n### FEASIBLE-Exemplars Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
			System.err.println("method = feasible-exmp");
			System.err.println("noQueries = Number of queries in the benchmark");
			System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
			System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
			System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
			System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m feasible-exmp   -n 15  -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o feasible-exmp-10QA-benchmark.ttl");
	
		//	System.err.println("Invalid format: values for -m, -n, -q, -e are mendatory parameters.");
			System.err.println("\n\n### Random Selection Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
			System.err.println("method = random");
			System.err.println("noQueries = Number of queries in the benchmark");
			System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
			System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
			System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
			System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m random   -n 15  -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o random-10QA-benchmark.ttl");
		
	}
	private static void callFeasibleExemplars(String[] args) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFHandlerException, IOException {
		int noQueries = 0; 
		String endpointURL, queryFile,outputFile = null;
	   String	param = "-n";
       String	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidFeasibleExemplarsFormat();}
    	try{
    	noQueries =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the Number of queries -n should be an integer");invalidFeasibleExemplarsFormat(); }
   	param = "-e";
    	endpointURL = getParamVal(args,param);
    	if(endpointURL==null){
	        isMedatory(param);
	        invalidFeasibleExemplarsFormat();} 	
    	param = "-q";
    	queryFile = getParamVal(args,param);
    	if(queryFile==null){
	        isMedatory(param);
	        invalidFeasibleExemplarsFormat();}   	
    	param = "-o";
    	outputFile = getParamVal(args,param);
    	if(outputFile==null){
	        isMedatory(param);
	        invalidFeasibleExemplarsFormat();}
    	FeasibleExemplars.runFeasibleExemplars(noQueries, endpointURL, queryFile, outputFile);
	}
	private static void callRandomSelection(String[] args) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFHandlerException, IOException {
		int noQueries = 0; 
		String endpointURL, queryFile,outputFile = null;
	   String	param = "-n";
       String	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidRandomSelectionFormat();}
    	try{
    	noQueries =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the Number of queries -n should be an integer");invalidFeasibleExemplarsFormat(); }
   	param = "-e";
    	endpointURL = getParamVal(args,param);
    	if(endpointURL==null){
	        isMedatory(param);
	        invalidFeasibleExemplarsFormat();} 	
    	param = "-q";
    	queryFile = getParamVal(args,param);
    	if(queryFile==null){
	        isMedatory(param);
	        invalidFeasibleExemplarsFormat();}   	
    	param = "-o";
    	outputFile = getParamVal(args,param);
    	if(outputFile==null){
	        isMedatory(param);
	        invalidFeasibleExemplarsFormat();}
    	RandomSelection.getRandomQueries(noQueries, endpointURL, queryFile, outputFile);
	}
	private static void callFeasible(String[] args) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFHandlerException, IOException {
		int noQueries = 0; 
		String endpointURL, queryFile,outputFile = null;
	   String	param = "-n";
       String	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidFeasibleFormat();}
    	try{
    	noQueries =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the Number of queries -n should be an integer");invalidFeasibleFormat(); }
   	param = "-e";
    	endpointURL = getParamVal(args,param);
    	if(endpointURL==null){
	        isMedatory(param);
	        invalidFeasibleFormat();} 	
    	param = "-q";
    	queryFile = getParamVal(args,param);
    	if(queryFile==null){
	        isMedatory(param);
	        invalidFeasibleFormat();}   	
    	param = "-o";
    	outputFile = getParamVal(args,param);
    	if(outputFile==null){
	        isMedatory(param);
	        invalidFeasibleFormat();}
    	FEASIBLEClustering.runFeasible(noQueries, endpointURL, queryFile, outputFile);
	}

	private static void callDBPlusKMeansPlusPlus(String[] args) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFHandlerException, IOException {
		int noQueries = 0,maxItrerations = 0,noTrialRun = 0,radius=0,minPts =0; 
		String endpointURL, queryFile,outputFile = null ;
	   String	param = "-n";
       String	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidDBKmeansPlusPlusFormat();}
    	try{
    	noQueries =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the Number of queries -n should be an integer"); invalidDBKmeansPlusPlusFormat(); }
   ////    
    	param = "-i";
    	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidDBKmeansPlusPlusFormat();}
    	try{
    		 maxItrerations  =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the maximum number of iteration -i should be an integer");invalidDBKmeansPlusPlusFormat(); }
 ////    
    	param = "-t";
    	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidDBKmeansPlusPlusFormat();}
    	try{
    		 noTrialRun  =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the number of trial runs -t should be an integer"); invalidDBKmeansPlusPlusFormat(); }
   
    	 ////    
    	param = "-r";
    	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidDBKmeansPlusPlusFormat();}
    	try{
    		 noTrialRun  =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the radius -r should be an integer"); invalidDBKmeansPlusPlusFormat(); }
  
   	 ////    
    	param = "-p";
    	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidDBKmeansPlusPlusFormat();}
    	try{
    		 noTrialRun  =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the minimum number of points -p should be an integer"); invalidDBKmeansPlusPlusFormat(); }
  
       	param = "-e";
    	endpointURL = getParamVal(args,param);
    	if(endpointURL==null){
	        isMedatory(param);
			invalidDBKmeansPlusPlusFormat();}
    	param = "-q";
    	queryFile = getParamVal(args,param);
    	if(queryFile==null){
	        isMedatory(param);
			invalidDBKmeansPlusPlusFormat();}
     	param = "-o";
    	outputFile = getParamVal(args,param);
    	if(outputFile==null){
	        isMedatory(param);
			invalidDBKmeansPlusPlusFormat();}
		DbscanAndKMeansPluPlus.runDBPlusKmeanPlusPlus(radius,minPts,noQueries, maxItrerations,noTrialRun,endpointURL, queryFile, outputFile);
   
		
	}

	private static void callKMeansPlusPlus(String[] args) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFHandlerException, IOException {
		int noQueries = 0,maxItrerations = 0,noTrialRun = 0; 
		String endpointURL, queryFile,outputFile = null;
	   String	param = "-n";
       String	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidKmeansPlusPlusFormat();}
    	try{
    	noQueries =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the Number of queries -n should be an integer"); invalidKmeansPlusPlusFormat(); }
   ////    
    	param = "-i";
    	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidKmeansPlusPlusFormat();}
    	try{
    		 maxItrerations  =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the maximum number of iteration -i should be an integer");invalidKmeansPlusPlusFormat(); }
 ////    
    	param = "-t";
    	paramVal = getParamVal(args,param);
    	if(paramVal==null){
	        isMedatory(param);
			invalidKmeansPlusPlusFormat();}
    	try{
    		 noTrialRun  =  Integer.parseInt(paramVal); 
    	}
	catch(Exception ex){System.err.println("the number of trial runs -t should be an integer"); invalidKmeansPlusPlusFormat(); }
  	
    	param = "-e";
    	endpointURL = getParamVal(args,param);
    	if(endpointURL==null){
	        isMedatory(param);
			invalidKmeansPlusPlusFormat();} 	
    	param = "-q";
    	queryFile = getParamVal(args,param);
    	if(queryFile==null){
	        isMedatory(param);
			invalidKmeansPlusPlusFormat();}   	
    	param = "-o";
    	outputFile = getParamVal(args,param);
    	if(outputFile==null){
	        isMedatory(param);
			invalidKmeansPlusPlusFormat();}
    	KmeansPlusPlus.runKMeansPlusPlus(noQueries,maxItrerations,noTrialRun,endpointURL,queryFile, outputFile);	
	}

	
	private static void isMedatory(String method) {
		System.err.println("parameter " +method +" with its corresponding value is mendatory for the requried clustering method");
		
	}

	private static void invalidKmeansPlusPlusFormat() {
	//	System.err.println("Invalid format: values for -m, -n, -q, -e are mendatory parameters.");
		
		System.err.println("\n\n### Kmeans++ Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -i <maxNoIterations> -t <noTrialRun> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
		System.err.println("method = km++");
		System.err.println("noQueries = Number of queries in the benchmark");
		System.err.println("maxNoIterations = Maximum number of iterations for the clustering algorithm");
		System.err.println("noTrialRun = Number of trial run for the clustering algorithm");
		System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
		System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
		System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
		System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m km++   -n 15   -i 10   -t 10   -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o km++-10QA-benchmark.ttl");
	
			System.exit(0);
	}
	private static void invalidFeasibleFormat() {
		System.err.println("\n\n### FEASIBLE Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
		System.err.println("method = feasible");
		System.err.println("noQueries = Number of queries in the benchmark");
		System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
		System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
		System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
		System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m feasible   -n 15  -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o feasible-10QA-benchmark.ttl");

					System.exit(0);
		}
	private static void invalidFeasibleExemplarsFormat() {
				
			System.err.println("\n\n### FEASIBLE-Exemplars Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
			System.err.println("method = feasible-exmp");
			System.err.println("noQueries = Number of queries in the benchmark");
			System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
			System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
			System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
			System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m feasible-exmp   -n 15  -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o feasible-exmp-10QA-benchmark.ttl");
	
					System.exit(0);
		}
	private static void invalidAgglomerativeFormat() {
					System.err.println("\n\n### Agglomerative Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
			System.err.println("method = agglomerative");
			System.err.println("noQueries = Number of queries in the benchmark");
			System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
			System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
			System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
			System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m agglomerative   -n 15  -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o agglomerative-10QA-benchmark.ttl");
	
				System.exit(0);
	}
private static void invalidRandomSelectionFormat() {
	//	System.err.println("Invalid format: values for -m, -n, -q, -e are mendatory parameters.");

//	System.err.println("Invalid format: values for -m, -n, -q, -e are mendatory parameters.");
System.err.println("\n\n### Random Selection Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -e <endpointUrl> -q <queryPersonalized> -o <outputFile>");
System.err.println("method = random");
System.err.println("noQueries = Number of queries in the benchmark");
System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m random   -n 15  -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -o random-10QA-benchmark.ttl");
			System.exit(0);
		}
	private static void invalidDBKmeansPlusPlusFormat() {
		System.err.println("Invalid format: values for -m, -n, -q, -e are mendatory parameters.");
		System.err.println("\n\n Invalid format. The general formats are: ");
		System.err.println("### DBSCAN+Kmeans++ Format ### \n java -jar sparqlbench.jar -m <method> -n <noQueries> -i <maxNoIterations> -t <noTrialRun> -e <endpointUrl> -q <queryPersonalized> -r <radius> -p <minPts> -o <outputFile>");
		System.err.println("method = db+km++");
		System.err.println("noQueries = Number of queries in the benchmark");
		System.err.println("maxNoIterations = Maximum number of iterations for the clustering algorithm");
		System.err.println("noTrialRun = Number of trial run for the clustering algorithm");
		System.err.println("endpointURL = The endpoint URL hosting the QALD RDF dataset");
		System.err.println("queryPersonalized = The personalized query for costum benchmark generation");
		System.err.println("radius = Radius for the queries to be considered as outliers");
		System.err.println("minPts = Minimum points or queries in a cluster");
		System.err.println("outputFile = The output TTL file where the resulting benchmark will be printed");
		System.err.println("\nAn example format: \njava -jar sparqlbench.jar   -m db+km++   -n 15   -i 10   -t 10   -e http://localhost:8890/sparql   -q ../SPARQLBench/personalized-query.txt   -r 1   -p 1   -o db+km++-10QA-benchmark.ttl");

				System.exit(0);
		}
	private static String getParamVal(String[] args, String param) {
		for(int index = 0 ; index<args.length;index++){
			 if(args[index].equals(param))
		 			 return args[index+1];
		}
		return null;
	}

}
