本文整理了Java中org.apache.commons.collections.Buffer.add()
方法的一些代码示例,展示了Buffer.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.add()
方法的具体详情如下:
包路径:org.apache.commons.collections.Buffer
类名称:Buffer
方法名:add
暂无
代码示例来源:origin: Graylog2/graylog2-server
@Override
public void append(LogEvent event) {
buffer.add(event);
}
代码示例来源:origin: commons-collections/commons-collections
public void testAddAllToFullBufferNoTimeout() {
final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
bounded.add( "Hello" );
try {
bounded.addAll(Collections.singleton("World"));
fail();
} catch (BufferOverflowException e) {
}
}
代码示例来源:origin: commons-collections/commons-collections
public void run() {
try {
// wait for other thread to block on get() or remove()
Thread.sleep( delay );
}
catch( InterruptedException e ) {
}
buffer.add( obj );
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testAddAllToFullBufferWithTimeout() {
final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500);
bounded.add( "Hello" );
bounded.add( "World" );
new DelayedRemove( bounded, 200, 2 ).start();
bounded.addAll( Arrays.asList( new String[] { "Foo", "Bar" } ) );
assertEquals( 2, bounded.size() );
assertEquals( "Foo", bounded.get() );
try {
bounded.add( "!" );
fail();
}
catch( BufferOverflowException e ) {
}
}
代码示例来源:origin: commons-collections/commons-collections
public boolean add(Object o) {
synchronized (lock) {
timeoutWait(1);
return getBuffer().add(o);
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testAddAllToFullBufferRemoveViaIterator() {
final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500);
bounded.add( "Hello" );
bounded.add( "World" );
new DelayedIteratorRemove( bounded, 200, 2 ).start();
bounded.addAll( Arrays.asList( new String[] { "Foo", "Bar" } ) );
assertEquals( 2, bounded.size() );
assertEquals( "Foo", bounded.remove() );
assertEquals( "Bar", bounded.remove() );
}
代码示例来源:origin: wildfly/wildfly
public boolean add(Object o) {
synchronized (lock) {
timeoutWait(1);
return getBuffer().add(o);
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testAddToFullBufferNoTimeout() {
final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1);
bounded.add( "Hello" );
try {
bounded.add("World");
fail();
} catch (BufferOverflowException e) {
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testGet() {
Buffer buffer = makeTestBuffer();
try {
Object o = buffer.get();
fail("Expecting BufferUnderflowException");
} catch (BufferUnderflowException ex) {
// expected
}
buffer.add("one");
buffer.add("two");
buffer.add("three");
assertEquals("Buffer get", buffer.get(), "three");
}
代码示例来源:origin: commons-collections/commons-collections
public void testAddToFullBufferWithTimeout() {
final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
bounded.add( "Hello" );
new DelayedRemove( bounded, 200 ).start();
bounded.add( "World" );
assertEquals( 1, bounded.size() );
assertEquals( "World", bounded.get() );
try {
bounded.add( "!" );
fail();
}
catch( BufferOverflowException e ) {
}
}
代码示例来源:origin: commons-collections/commons-collections
/**
* Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add(Object)} using multiple read
* threads.
* <p/>
* Two read threads should block on an empty buffer until one object is added then one thread should complete. The
* remaining thread should complete after the addition of a second object.
*/
public void testBlockedRemoveWithAdd() {
Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
Object obj = new Object();
// run methods will remove and compare -- must wait for add
Thread thread1 = new ReadThread( blockingBuffer, obj, null, "remove" );
Thread thread2 = new ReadThread( blockingBuffer, obj, null, "remove" );
thread1.start();
thread2.start();
// give hungry read threads ample time to hang
delay();
blockingBuffer.add( obj );
// allow notified threads to complete
delay();
// There should be one thread waiting.
assertTrue( "There is one thread waiting", thread1.isAlive() ^ thread2.isAlive() );
blockingBuffer.add( obj );
// allow notified thread to complete
delay();
// There should not be any threads waiting.
if( thread1.isAlive() || thread2.isAlive() ) {
fail( "Live thread(s) when both should be dead." );
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testAddToFullBufferRemoveViaIterator() {
final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 1, 500);
bounded.add( "Hello" );
new DelayedIteratorRemove( bounded, 200 ).start();
bounded.add( "World" );
assertEquals( 1, bounded.size() );
assertEquals( "World", bounded.get() );
}
代码示例来源:origin: commons-collections/commons-collections
/**
* Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)} using multiple read
* threads.
* <p/>
* Two read threads should block on an empty buffer until one object is added then both threads should complete.
*/
public void testBlockedGetWithAdd() {
Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
Object obj = new Object();
// run methods will get and compare -- must wait for add
Thread thread1 = new ReadThread( blockingBuffer, obj );
Thread thread2 = new ReadThread( blockingBuffer, obj );
thread1.start();
thread2.start();
// give hungry read threads ample time to hang
delay();
// notifyAll should allow both read threads to complete
blockingBuffer.add( obj );
// allow notified threads to complete
delay();
// There should not be any threads waiting.
if( thread1.isAlive() || thread2.isAlive() ) {
fail( "Live thread(s) when both should be dead." );
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testRemove() {
Buffer buffer = makeTestBuffer();
buffer.add("one");
assertEquals("Buffer get", buffer.remove(), "one");
try {
buffer.remove();
fail("Expecting BufferUnderflowException");
} catch (BufferUnderflowException ex) {
// expected
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testTransformedBuffer() {
Buffer buffer = TransformedBuffer.decorate(new ArrayStack(), TestTransformedCollection.STRING_TO_INTEGER_TRANSFORMER);
assertEquals(0, buffer.size());
Object[] els = new Object[] {"1", "3", "5", "7", "2", "4", "6"};
for (int i = 0; i < els.length; i++) {
buffer.add(els[i]);
assertEquals(i + 1, buffer.size());
assertEquals(true, buffer.contains(new Integer((String) els[i])));
assertEquals(false, buffer.contains(els[i]));
}
assertEquals(false, buffer.remove(els[0]));
assertEquals(true, buffer.remove(new Integer((String) els[0])));
}
}
代码示例来源:origin: commons-collections/commons-collections
public void testIsFull() {
Set set = new HashSet();
set.add("1");
set.add("2");
set.add("3");
try {
CollectionUtils.isFull(null);
fail();
} catch (NullPointerException ex) {}
assertEquals(false, CollectionUtils.isFull(set));
BoundedFifoBuffer buf = new BoundedFifoBuffer(set);
assertEquals(true, CollectionUtils.isFull(buf));
buf.remove("2");
assertEquals(false, CollectionUtils.isFull(buf));
buf.add("2");
assertEquals(true, CollectionUtils.isFull(buf));
Buffer buf2 = BufferUtils.synchronizedBuffer(buf);
assertEquals(true, CollectionUtils.isFull(buf2));
buf2.remove("2");
assertEquals(false, CollectionUtils.isFull(buf2));
buf2.add("2");
assertEquals(true, CollectionUtils.isFull(buf2));
}
代码示例来源:origin: commons-collections/commons-collections
public void testMaxSize() {
Set set = new HashSet();
set.add("1");
set.add("2");
set.add("3");
try {
CollectionUtils.maxSize(null);
fail();
} catch (NullPointerException ex) {}
assertEquals(-1, CollectionUtils.maxSize(set));
BoundedFifoBuffer buf = new BoundedFifoBuffer(set);
assertEquals(3, CollectionUtils.maxSize(buf));
buf.remove("2");
assertEquals(3, CollectionUtils.maxSize(buf));
buf.add("2");
assertEquals(3, CollectionUtils.maxSize(buf));
Buffer buf2 = BufferUtils.synchronizedBuffer(buf);
assertEquals(3, CollectionUtils.maxSize(buf2));
buf2.remove("2");
assertEquals(3, CollectionUtils.maxSize(buf2));
buf2.add("2");
assertEquals(3, CollectionUtils.maxSize(buf2));
}
代码示例来源:origin: commons-collections/commons-collections
/**
* Tests that the removal operation actually removes the first element.
*/
public void testCircularFifoBufferCircular() {
List list = new ArrayList();
list.add("A");
list.add("B");
list.add("C");
Buffer buf = new CircularFifoBuffer(list);
assertEquals(true, buf.contains("A"));
assertEquals(true, buf.contains("B"));
assertEquals(true, buf.contains("C"));
buf.add("D");
assertEquals(false, buf.contains("A"));
assertEquals(true, buf.contains("B"));
assertEquals(true, buf.contains("C"));
assertEquals(true, buf.contains("D"));
assertEquals("B", buf.get());
assertEquals("B", buf.remove());
assertEquals("C", buf.remove());
assertEquals("D", buf.remove());
}
代码示例来源:origin: commons-collections/commons-collections
public void testMaxSize() {
final Buffer bounded = BoundedBuffer.decorate(new UnboundedFifoBuffer(), 2, 500);
BoundedCollection bc = (BoundedCollection) bounded;
assertEquals(2, bc.maxSize());
assertEquals(false, bc.isFull());
bounded.add("A");
assertEquals(false, bc.isFull());
bounded.add("B");
assertEquals(true, bc.isFull());
bounded.remove();
assertEquals(false, bc.isFull());
try {
BoundedBuffer.decorate(new UnboundedFifoBuffer(), 0);
fail();
} catch (IllegalArgumentException ex) {}
try {
BoundedBuffer.decorate(new UnboundedFifoBuffer(), -1);
fail();
} catch (IllegalArgumentException ex) {}
}
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_core
@SuppressWarnings("unchecked")
@Override
public void processLogEvent(final LogEventObject logEventObject) {
if(!LOGGER_PANEL_RECEIVE_WHEN_CLOSED && !GuiPackage.getInstance().getMenuItemLoggerPanel().getModel().isSelected()) {
return;
}
String logMessage = logEventObject.toString();
synchronized (events) {
events.add(logMessage);
}
logChanged = true;
}
内容来源于网络,如有侵权,请联系作者删除!