Example usage for org.apache.commons.collections15.buffer PriorityBuffer remove

List of usage examples for org.apache.commons.collections15.buffer PriorityBuffer remove

Introduction

In this page you can find the example usage for org.apache.commons.collections15.buffer PriorityBuffer remove.

Prototype

public E remove() 

Source Link

Document

Gets and removes the next element (pop).

Usage

From source file:edu.cuny.cat.market.matching.FourHeapShoutEngine.java

/**
 * Remove, possibly several, shouts from heap such that quantity(heap) is
 * reduced by the supplied quantity and reinsert the shouts using the standard
 * insertion logic. quantity(heap) is defined as the total quantity of every
 * shout in the heap.//  w  w w  . ja  v a 2s.  c o m
 * 
 * @param heap
 *          The heap to remove shouts from.
 * @param quantity
 *          The total quantity to remove.
 */
protected void reinsert(final PriorityBuffer<Shout> heap, int quantity) {

    while (quantity > 0) {

        final Shout top = heap.remove();

        if (top.getQuantity() > quantity) {
            heap.add(top.split(top.getQuantity() - quantity));
        }

        quantity -= top.getQuantity();

        try {
            if (top.isBid()) {
                newBid(top);
            } else {
                newAsk(top);
            }
        } catch (final DuplicateShoutException e) {
            throw new AuctionError("Invalid auction status");
        }
    }
}

From source file:edu.cuny.cat.market.matching.FourHeapShoutEngine.java

protected int displaceShout(Shout shout, final PriorityBuffer<Shout> from, final PriorityBuffer<Shout> to)
        throws DuplicateShoutException {
    shout = FourHeapShoutEngine.unifyShout(shout, from);
    to.add(from.remove());
    FourHeapShoutEngine.insertShout(from, shout);
    return shout.getQuantity();
}

From source file:edu.cuny.cat.market.matching.FourHeapShoutEngine.java

public int promoteShout(Shout shout, final PriorityBuffer<Shout> from, final PriorityBuffer<Shout> to,
        final PriorityBuffer<Shout> matched) throws DuplicateShoutException {

    shout = FourHeapShoutEngine.unifyShout(shout, from);
    FourHeapShoutEngine.insertShout(matched, shout);
    to.add(from.remove());
    return shout.getQuantity();
}