Example usage for org.apache.commons.collections.buffer UnboundedFifoBuffer remove

List of usage examples for org.apache.commons.collections.buffer UnboundedFifoBuffer remove

Introduction

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

Prototype

public Object remove() 

Source Link

Document

Removes the next object from the buffer

Usage

From source file:com.octo.captcha.engine.bufferedengine.buffer.MemoryCaptchaBufferTest.java

public void testRemoveEmptyBuffer() {
    UnboundedFifoBuffer fifoBuffer = new UnboundedFifoBuffer();
    try {/*from w ww  .ja va 2s . co  m*/
        fifoBuffer.remove();
        fail("should throw an Exception");
    } catch (NoSuchElementException e) {
    }
}

From source file:com.octo.captcha.engine.bufferedengine.buffer.MemoryCaptchaBuffer.java

/**
 * @see CaptchaBuffer#removeCaptcha(int, java.util.Locale)
 *//*from  ww  w  . j  a  v a  2  s  . c o m*/
public synchronized Collection removeCaptcha(int number, Locale locale) {
    ArrayList list = new ArrayList(number);

    UnboundedFifoBuffer buffer = (UnboundedFifoBuffer) buffers.get(locale);
    if (buffer == null) {
        logDebug("Locale not found in Memory buffer map : " + locale.toString());
        return list;
    }

    try {
        for (int i = 0; i < number; i++) {
            list.add(buffer.remove());
        }
    } catch (NoSuchElementException e) {
        // Stop retrieving captchas, used in order to use the "remove" without calling the expensive "size" method
        logDebug("Buffer empty for locale : " + locale.toString());
    }

    logDebug("Removed from locale :'" + locale + "' a list of '" + list.size() + "' elements.");
    return list;
}