@Test public void findMatches() { Instant entryTime1 = clock.instant(); final WorkingOrder order1 = new WorkingOrder( new TestOrder("C1", symbol, Side.Sell, 3, OrdType.Limit, new BigDecimal("12.95")), userId, "Order" + 1, entryTime1); orderBook.addOrder(order1); Instant entryTime2 = clock.instant(); final WorkingOrder order2 = new WorkingOrder( new TestOrder("C2", symbol, Side.Sell, 2, OrdType.Limit, new BigDecimal("12.95")), userId, "Order" + 2, entryTime2); orderBook.addOrder(order2); Instant entryTime3 = clock.instant(); final WorkingOrder order3 = new WorkingOrder( new TestOrder("C3", symbol, Side.Buy, 7, OrdType.Limit, new BigDecimal("12.95")), userId, "Order" + 3, entryTime3); SortedSet<WorkingOrder> matches = orderBook.findMatches(order3); assertEquals(2, matches.size()); }
public SortedSet<WorkingOrder> findMatches(WorkingOrder order) { MatchingOrderDecorator compare = new MatchingOrderDecorator(order, order.getSource()); SortedSet<WorkingOrder> matches = null; switch (order.getSide()) { case Buy: matches = offers.headSet(compare, true); break; case Sell: matches = bids.headSet(compare, true); break; default: throw new IllegalArgumentException("Invalid side"); } return matches; }
OrderBook { public SortedSet<WorkingOrder> findMatches(WorkingOrder order) { MatchingOrderDecorator compare = new MatchingOrderDecorator(order, order.getSource()); SortedSet<WorkingOrder> matches = null; switch (order.getSide()) { case Buy: matches = offers.headSet(compare, true); break; case Sell: matches = bids.headSet(compare, true); break; default: throw new IllegalArgumentException("Invalid side"); } return matches; } }
OrderBook { public SortedSet<WorkingOrder> findMatches(WorkingOrder order) { MatchingOrderDecorator compare = new MatchingOrderDecorator(order, order.getSource()); SortedSet<WorkingOrder> matches = null; switch (order.getSide()) { case Buy: matches = offers.headSet(compare, true); break; case Sell: matches = bids.headSet(compare, true); break; default: throw new IllegalArgumentException("Invalid side"); } return matches; } OrderBook();  OrderBook(Comparator<WorkingOrder> bidComparator,
      Comparator<WorkingOrder> offerComparator); }
OrderBook { public SortedSet<WorkingOrder> findMatches(WorkingOrder order) { MatchingOrderDecorator compare = new MatchingOrderDecorator(order, order.getSource()); SortedSet<WorkingOrder> matches = null; switch (order.getSide()) { case Buy: matches = offers.headSet(compare, true); break; case Sell: matches = bids.headSet(compare, true); break; default: throw new IllegalArgumentException("Invalid side"); } return matches; } OrderBook();  OrderBook(Comparator<WorkingOrder> bidComparator,
      Comparator<WorkingOrder> offerComparator); void addOrder(WorkingOrder order); void clear(); SortedSet<WorkingOrder> findMatches(WorkingOrder order); WorkingOrder findOrder(Side side, String clOrdId, String userId); WorkingOrder findOrder(WorkingOrder order); WorkingOrder removeOrder(Side side, String clOrdId, String userId); WorkingOrder removeOrder(WorkingOrder order); @Override String toString(); }
OrderBook { public SortedSet<WorkingOrder> findMatches(WorkingOrder order) { MatchingOrderDecorator compare = new MatchingOrderDecorator(order, order.getSource()); SortedSet<WorkingOrder> matches = null; switch (order.getSide()) { case Buy: matches = offers.headSet(compare, true); break; case Sell: matches = bids.headSet(compare, true); break; default: throw new IllegalArgumentException("Invalid side"); } return matches; } OrderBook();  OrderBook(Comparator<WorkingOrder> bidComparator,
      Comparator<WorkingOrder> offerComparator); void addOrder(WorkingOrder order); void clear(); SortedSet<WorkingOrder> findMatches(WorkingOrder order); WorkingOrder findOrder(Side side, String clOrdId, String userId); WorkingOrder findOrder(WorkingOrder order); WorkingOrder removeOrder(Side side, String clOrdId, String userId); WorkingOrder removeOrder(WorkingOrder order); @Override String toString();  }