package test;

import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;

import java.util.Random;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
/**
 * @author Bhushan Lokhande
 */
public class SellOrBuy implements
		com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {

	// Input argument will be of format:   "Number of Holdings: </B>5</TD>"
	//static Pattern HOLDING_PAT = Pattern.compile("<B>Number of Holdings: </B>(.+?)</TD>");	
	static final Random rand = new Random();

	/**
	 * Instances of this will be created using the no-arg constructor.
	 */
	public SellOrBuy() {
	}

	/**
	 * For javadoc of ICustomCode2 and ITestExecutionServices interfaces, select 'Help Contents' in the
	 * Help menu and select 'Extending Rational Performance Tester functionality' -> 'Extending test execution with custom code'
	 */
	public String exec(ITestExecutionServices tes, String[] args) {
		//String strNumberOfHoldings = args[0];
		//Matcher matcher = HOLDING_PAT.matcher(strNumberOfHoldings);
		
	    int intNHoldings = 0;
	    intNHoldings = Integer.parseInt(args[0]);		 		
		int nthFind = rand.nextInt(10) + 1;

        //Extract the holdings number retrieved from previous Portfolio request
		//if (matcher.find() == true) {
		//	intNHoldings= Integer.parseInt(matcher.group(1));
		//}
		
		//Decide if Sell of Buy operation should be performed
		String strHolding = null;
		if (intNHoldings < nthFind ) {
			strHolding = "DO_BUY";
		}
		else {
			strHolding = "DO_SELL";
		}			
		return strHolding;
	}

}
