Example usage for org.apache.commons.collections Buffer size

List of usage examples for org.apache.commons.collections Buffer size

Introduction

In this page you can find the example usage for org.apache.commons.collections Buffer size.

Prototype

int size();

Source Link

Document

Returns the number of elements in this collection.

Usage

From source file:edu.polyu.vad.VAD.java

public static boolean detect(Buffer buf, int mode, double threshold) {
    int numFrames = buf.size();
    double energy[] = new double[numFrames];
    Iterator<double[]> it = buf.iterator();
    int n = 0;/*  ww  w.  j av a 2s  . c o m*/
    while (it.hasNext()) {
        energy[n++] = it.next()[0];
    }
    return detect(energy, mode, threshold);
}

From source file:de.innovationgate.wgpublisher.logserver.AppLogTailHandler.java

public synchronized List refresh() throws IOException {

    List lines = new ArrayList();
    Buffer buffer = _listWriter.getBuffer();
    while (buffer.size() > 0) {
        lines.add(buffer.remove());/*from   w  w  w .j  a v  a2s  . c om*/
    }
    return lines;

}

From source file:edu.polyu.vad.VAD.java

private double[] getEnergyProfile(Buffer buf) {
    int numFrames = buf.size();
    double energy[] = new double[numFrames];
    Iterator<double[]> it = buf.iterator();
    int n = 0;/*from  w  ww .ja v a  2 s  .c o  m*/
    while (it.hasNext()) {
        energy[n++] = it.next()[0];
    }
    return energy;
}

From source file:edu.illinois.enforcemop.examples.apache.collections.TestBoundedBuffer.java

@Test
// @Schedule(name = "addToFullBufferWithTimeout", sequence = "[beforeAdd:afterAdd]@main->beforeRemove@removeThread,afterRemove@removeThread->afterAdd@main")
public void testAddToFullBufferWithTimeout() {
    final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
    bounded.add("Hello");
    new NonDelayedRemove(bounded, 100, "removeThread").start();
    /* @Event("beforeAdd")*/
    bounded.add("World");
    /* @Event("afterAdd")*/
    assertEquals(1, bounded.size());
    assertEquals("World", bounded.get());
    try {//from   www .ja  v a2s  .  c o m
        bounded.add("!");
        fail();
    } catch (BufferOverflowException e) {
    }
}

From source file:edu.illinois.enforcemop.examples.apache.collections.TestBoundedBuffer.java

/**@TO-DO How do we handle timed events? */
@Test//from   www  .j  a  v a  2  s  .  c  om
//  @Schedule(name = "addToFullBufferRemoveViaIterator", sequence = "[beforeAdd:afterAdd]@main->beforeRemove@removeThread")
public void testAddToFullBufferRemoveViaIterator() {
    final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
    bounded.add("Hello");
    new NonDelayedIteratorRemove(bounded, 100, "removeThread").start();
    /* @Event("beforeAdd")*/
    bounded.add("World");
    /* @Event("afterAdd")*/
    assertEquals(1, bounded.size());
    assertEquals("World", bounded.get());

}

From source file:edu.illinois.enforcemop.examples.apache.collections.TestBoundedBuffer.java

@Test
//  @Schedule(name = "default", sequence = "[beforeAdd:afterAdd]@main->beforeRemove@removeThread")
public void testAddAllToFullBufferRemoveViaIterator() {
    final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500);
    bounded.add("Hello");
    bounded.add("World");
    new NonDelayedIteratorRemove(bounded, 100, 2, "removeThread").start();
    /* @Event("beforeAdd")*/
    bounded.addAll(Arrays.asList(new String[] { "Foo", "Bar" }));
    /* @Event("afterAdd")*/
    assertEquals(2, bounded.size());
    assertEquals("Foo", bounded.remove());
    assertEquals("Bar", bounded.remove());
}

From source file:org.xwiki.ircbot.internal.BrokenLinkEventListenerTest.java

@Test
public void onEventWhenInvalidURLEvent() throws Exception {
    sendInvalidURLEvent("testurl", null);

    Buffer buffer = ((BrokenLinkEventListener) getMockedComponent()).getLastBrokenLinks();
    Assert.assertEquals(1, buffer.size());
}

From source file:org.xwiki.ircbot.internal.BrokenLinkEventListenerTest.java

@Test
public void onEventWhenInvalidURLEventAndContextData() throws Exception {
    Map<String, Object> contextData = Collections.singletonMap("datakey", (Object) "datavalue");
    sendInvalidURLEvent("testurl", "Invalid link testurl on page testsource (code = 404, datakey = datavalue)",
            contextData);//from w w w .j  a v  a 2  s. com

    Buffer buffer = ((BrokenLinkEventListener) getMockedComponent()).getLastBrokenLinks();
    Assert.assertEquals(1, buffer.size());
}

From source file:org.xwiki.ircbot.internal.BrokenLinkEventListenerTest.java

@Test
public void onEventWhenSeveralInvalidURLEventWithSameURL() throws Exception {
    sendInvalidURLEvent("testurl", null);
    sendInvalidURLEvent("testurl", null);

    Buffer buffer = ((BrokenLinkEventListener) getMockedComponent()).getLastBrokenLinks();
    Assert.assertEquals(1, buffer.size());
}

From source file:org.xwiki.ircbot.internal.BrokenLinkEventListenerTest.java

@Test
public void onEventWhenSeveralInvalidURLEventWithDifferentURL() throws Exception {
    sendInvalidURLEvent("testurl1", null);
    sendInvalidURLEvent("testurl2", null);

    Buffer buffer = ((BrokenLinkEventListener) getMockedComponent()).getLastBrokenLinks();
    Assert.assertEquals(2, buffer.size());
}