org.apache.commons.collections.Buffer.get()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(193)

本文整理了Java中org.apache.commons.collections.Buffer.get()方法的一些代码示例,展示了Buffer.get()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.get()方法的具体详情如下:
包路径:org.apache.commons.collections.Buffer
类名称:Buffer
方法名:get

Buffer.get介绍

[英]Gets the next object from the buffer without removing it.
[中]从缓冲区中获取下一个对象,而不删除它。

代码示例

代码示例来源:origin: commons-collections/commons-collections

public Object get() {
  synchronized (lock) {
    return getBuffer().get();
  }
}

代码示例来源:origin: commons-collections/commons-collections

public Object get() {
  return getBuffer().get();
}

代码示例来源:origin: commons-collections/commons-collections

public Object get() {
  return getBuffer().get();
}

代码示例来源:origin: commons-collections/commons-collections

public Object get() {
  return getBuffer().get();
}

代码示例来源:origin: wildfly/wildfly

public Object get() {
  synchronized (lock) {
    return getBuffer().get();
  }
}

代码示例来源:origin: wildfly/wildfly

public Object get() {
  return getBuffer().get();
}

代码示例来源:origin: wildfly/wildfly

public Object get() {
  return getBuffer().get();
}

代码示例来源:origin: wildfly/wildfly

public Object get() {
  return getBuffer().get();
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Gets the next value from the buffer, waiting until an object is
 * added if the buffer is empty. This method uses the default timeout
 * set in the constructor.
 *
 * @throws BufferUnderflowException if an interrupt is received
 */
public Object get() {
  synchronized (lock) {
    while (collection.isEmpty()) {
      try {
        if (timeout <= 0) {
          lock.wait();
        } else {
          return get(timeout);
        }
      } catch (InterruptedException e) {
        PrintWriter out = new PrintWriter(new StringWriter());
        e.printStackTrace(out);
        throw new BufferUnderflowException("Caused by InterruptedException: " + out.toString());
      }
    }
    return getBuffer().get();
  }
}

代码示例来源:origin: commons-collections/commons-collections

public void run() {
    try {
      if( action == "get" ) {
        assertSame( obj, buffer.get() );
      }
      else {
        if( null != obj ) {
          assertSame( obj, buffer.remove() );
        }
        else {
          assertTrue( objs.remove( buffer.remove() ) );
        }
      }
    }
    catch( BufferUnderflowException ex ) {
      exceptionList.add( "BufferUnderFlow" );
    }
  }
}

代码示例来源: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

/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add(Object)}.
 */
public void testGetWithAdd() {
  Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
  Object obj = new Object();
  new DelayedAdd( blockingBuffer, obj ).start();
  // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
  assertSame( obj, blockingBuffer.get() );
}

代码示例来源:origin: commons-collections/commons-collections

public void testGetWithAddTimeout() {
  Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 500 );
  Object obj = new Object();
  new DelayedAdd( blockingBuffer, obj, 100 ).start();
  // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
  assertSame( obj, blockingBuffer.get() );
}

代码示例来源:origin: commons-collections/commons-collections

public void testGetWithAddAllTimeout() {
  Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer(), 500 );
  Object obj = new Object();
  new DelayedAddAll( blockingBuffer, obj, 100 ).start();
  // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
  assertSame( obj, blockingBuffer.get() );
}

代码示例来源:origin: commons-collections/commons-collections

/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#addAll(java.util.Collection)}.
 */
public void testGetWithAddAll() {
  Buffer blockingBuffer = BlockingBuffer.decorate( new MyBuffer() );
  Object obj = new Object();
  new DelayedAddAll( blockingBuffer, obj ).start();
  // verify does not throw BufferUnderflowException; should block until other thread has added to the buffer .
  assertSame( obj, blockingBuffer.get() );
}

代码示例来源:origin: commons-collections/commons-collections

public void testBufferEmpty() {
  resetEmpty();
  Buffer buffer = (Buffer) collection;
  assertEquals(0, buffer.size());
  assertEquals(true, buffer.isEmpty());
  try {
    buffer.get();
    fail();
  } catch (BufferUnderflowException ex) {}
  try {
    buffer.remove();
    fail();
  } catch (BufferUnderflowException ex) {}
}

代码示例来源: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

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

/**
 * 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 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 ) {
  }
}

相关文章