import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class TradeMatcher {
private final Scanner in;
private final BufferedWriter out;
public TradeMatcher(Scanner in, BufferedWriter out) {
this.in = in;
this.out = out;
}
/*
* store state
*/
//********** TO BE COMPLETED *************
/**
* Matching Trade
* @param trade
* @return
*/
public List<Long> match(Trade trade) {
//********** TO BE COMPLETED *************
return new ArrayList<Long>();
}
private void processTrades() throws IOException {
while (in.hasNext()) {
Trade order = readTrade();
List<Long> matchingIds = match(order);
outputMatches(matchingIds);
}
out.close();
}
private Trade readTrade() {
final long tradeId = in.nextLong();
final String securitySymbol = in.next();
final Side customerSide = Side.valueOf(in.next());
final long size = in.nextLong();
return new Trade(tradeId, securitySymbol, customerSide, size);
}
private void outputMatches(List<Long> matchingIds) throws IOException {
int length = matchingIds.size();
out.write(matchingIds.size() + " matches found. Matching ids are: [");
for (int i = 0; i < length; i++) {
out.write(String.valueOf(matchingIds.get(i)));
if (i < length - 1) {
out.write(',');
}
}
out.write("]");
out.newLine();
}
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
TradeMatcher m = new TradeMatcher(in, out);
m.processTrades();
}
//inner class
private static class Trade {
final long tradeId; // Unique id
final String securitySymbol; //if symbol matches & side differs then trade matches
final Side side; //BUY or SELL
long size; //trade QTY
public Trade(long orderId, String securitySymbol, Side customerSide, long size) {
this.tradeId = orderId;
this.securitySymbol = securitySymbol;
this.side = customerSide;
this.size = size;
}
}
private enum Side {
BUY, SELL
}
}