public long match(long orderId, Side side, long size, EmitterProcessor<MatchOrder> matchEmmiter) {
    long quantity = size;
    while (quantity > 0 && !orders.isEmpty()) {
      Order order = orders.get(0);
      long orderQuantity = order.size();
      if (orderQuantity > quantity) {
        order.reduce(quantity);
        matchEmmiter.onNext(
            new MatchOrder(order.id(), orderId, side, price, quantity, order.size()));
        quantity = 0;
      } else {
        orders.remove(0);
        matchEmmiter.onNext(new MatchOrder(order.id(), orderId, side, price, orderQuantity, 0));
        quantity -= orderQuantity;
      }
    }
    return quantity;
  }
public long match ( long orderId , Side side , long size , EmitterProcessor < MatchOrder > matchEmmiter ) { long quantity = size ; while ( quantity > 0 && ! orders . isEmpty ( ) ) { Order order = orders . get ( 0 ) ; long orderQuantity = order . size ( ) ; if ( orderQuantity > quantity ) { order . reduce ( quantity ) ; matchEmmiter . onNext ( new MatchOrder ( order . id ( ) , orderId , side , price , quantity , order . size ( ) ) ) ; quantity = 0 ; } else { orders . remove ( 0 ) ; matchEmmiter . onNext ( new MatchOrder ( order . id ( ) , orderId , side , price , orderQuantity , 0 ) ) ; quantity -= orderQuantity ; } } return quantity ; }
Match order if possible.

@param orderId the incoming order id
@param side the incoming order side
@param size incoming order quantity
@param matchEmmiter an emitter to be notified for matches {@link Processor#onNext(Object)}
@return the remaining quantity of the incoming order