package lab01;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;


/**
 * Test out the streaming stock implementation
 * @author CS-140 Teaching Staff
 *
 */
public class Tester {

	/**
	 * main function
	 *
	 * @param args - Unused
	 */
	public static void main(String[] args) {
		Quotes board=new Quotes();
		Portfolio pf = new Portfolio(10000.00); // Start a new portfolio with $10,000 cash
		long numQuotes=0;
		try (Stream<String> lineStream = Files.lines(Paths.get("quotes.txt"))) {
			numQuotes = lineStream
				.filter(s -> s.trim().length() > 0)
	            .map(s -> new Quote(s))
				.peek(q -> board.addQuote(q))
				.parallel()
				.peek(q -> pf.buyTrigger("IBM", 161.00, 10, q))
				.peek(q -> pf.buyTrigger("AAPL",100,50,q))
				.peek(q -> pf.sellTrigger("IBM", 162.5,20,q))
				.peek(q -> pf.sellTrigger("AAPL", 108.00, 20, q))
				.count();
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println("After processing " + numQuotes + " quotes, your portfolio:");
		pf.report(board);
	}

}
