package ws.prova.examples;

/*
 * Copyright (C) 2002-2007 <a href="mailto:a.kozlenkov@city.ac.uk">Alex Kozlenkov</a>
 * Copyright (C) 1999-2005 <a href="mailto:mandarax@jbdietrich.com">Jens Dietrich</a>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.io.Serializable;
import java.util.List;

/**
 * An example class for use in Prova tests
 * <p>Title: Prova</p>
 * <p>Description: An example class for use in Prova tests</p>
 * <p>Copyright: Copyright (C) 2002-2007</p>
 * <p>Company: City University, London, United Kingdom</p>
 *
 * @author Alex Kozlenkov
 * @version 2.0 <25 March 2007>
 */
public class Investment implements Serializable {
	private String symbol;
	private double at;

	public Investment(String _symbol, double _at) {
		super();
		symbol = _symbol;
		at = _at;
	}

	public String toString() {
		return "Investment(" + symbol + ',' + at + ")";
	}

	public Boolean stopLoss(Object arg1) {
		// We have a stock quote that is below the original buy price * 0.95
		Double in = (Double) arg1;
		return Boolean.valueOf(in.doubleValue() < at * 0.95);
	}

	public Boolean sell(Object arg1) {
		// Sell the investment
		Double in = (Double) arg1;
		System.out.println(this.toString() + ": sold at " + in.doubleValue());
		return Boolean.TRUE;
	}

	public Boolean check_price(Object arg1) {
		Double in = (Double) arg1;
		return (in.doubleValue() == at) ? Boolean.TRUE : Boolean.FALSE;
	}

	public Boolean send(Object arg1, Object arg2) {
		String agent = (String) arg1;
		String me = (String) arg2;
		System.out.println(this.toString() + ": sent to agent " + agent + " from agent " + me);
		return Boolean.TRUE;
	}

	public Boolean purchased_at(List ret) {
		ret.add(new Double(at));
		return Boolean.TRUE;
	}

	/**
	 * An example of a method with a long duration calculation
	 *
	 * @param arg1 - the number of seconds to sleep as Integer
	 * @param ret  - list of returned objects
	 * @return - always Boolean.TRUE
	 */
	public Boolean longcalc(Object arg1, List ret) {
		// The only parameter: the number of seconds to sleep
		Integer nsec = (Integer) arg1;
		try {
			Thread.sleep(nsec.intValue() * 1000);
		} catch (Exception exc) {
		}
		// Add returned objects to the return list
		ret.add(nsec);
		return Boolean.TRUE;
	}

}
