org.apache.commons.collections.Buffer类的使用及代码示例

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

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

Buffer介绍

[英]Defines a collection that allows objects to be removed in some well-defined order.

The removal order can be based on insertion order (eg, a FIFO queue or a LIFO stack), on access order (eg, an LRU cache), on some arbitrary comparator (eg, a priority queue) or on any other well-defined ordering.

Note that the removal order is not necessarily the same as the iteration order. A Buffer implementation may have equivalent removal and iteration orders, but this is not required.

This interface does not specify any behavior for Object#equals(Object) and Object#hashCode methods. It is therefore possible for a Buffer implementation to also also implement java.util.List, java.util.Set or Bag.
[中]定义一个集合,该集合允许按明确定义的顺序删除对象。
移除顺序可以基于插入顺序(例如,FIFO队列或后进先出堆栈)、访问顺序(例如,LRU缓存)、某些任意比较器(例如,优先级队列)或任何其他定义良好的顺序。
请注意,删除顺序不一定与迭代顺序相同。Buffer实现可能具有等效的删除和迭代顺序,但这不是必需的。
此接口不为Object#equals(Object)和Object#hashCode方法指定任何行为。因此Buffer实现也可以实现java。util。列表,java。util。套装或包。

代码示例

代码示例来源: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: 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: Graylog2/graylog2-server

@Override
public void stop() {
  super.stop();
  buffer.clear();
}

代码示例来源: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 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 Object remove() {
  synchronized (lock) {
    Object returnValue = getBuffer().remove();
    lock.notifyAll();
    return returnValue;
  }
}

代码示例来源: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 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: Graylog2/graylog2-server

@Override
public void append(LogEvent event) {
  buffer.add(event);
}

代码示例来源:origin: com.atlassian.core/atlassian-core

public synchronized T remove() {
  if (!buffer.isEmpty())
    return (T) buffer.remove();
  else
    return null;
}

代码示例来源: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: org.objectstyle.ashwood/ashwood

public void breadthFirstSort() {
 Buffer queue = new UnboundedFifoBuffer();
 Set seen = new HashSet();
 queue.addAll(layers[0]);
 seen.addAll(layers[0]);
 int[] indices = new int[layers.length];
 while (!queue.isEmpty()) {
  LayerVertex origin = (LayerVertex)queue.remove();
  origin.setIndexInLayer(indices[origin.getRank()]++);
  for (int i = 0; i < origin.outDegree(); i++) {
   Object dst = origin.getSuccessors().get(i);
   if (seen.add(dst)) queue.add(dst);
  }
 }
 for (int i = 0; i < layers.length; i++) {
  layers[i].sort();
 }
}

代码示例来源:origin: org.exoplatform.jcr/exo.jcr.component.core

mergeTasks.clear();
mergeTasks.add(QUIT);
log.debug("quit sent");
  log.debug("merge queue size: " + mergeTasks.size());

代码示例来源: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: org.apache.excalibur.components/excalibur-pool-impl

protected void internalShrink( final int amount )
    throws Exception
  {
    for( int i = 0; i < amount; i++ )
    {
      if( m_ready.size() > m_min )
      {
        try
        {
          this.removePoolable( (Poolable)m_ready.remove() );
        }
        catch( final Exception e )
        {
          if( null != getLogger() && getLogger().isDebugEnabled() )
          {
            getLogger().debug( m_factory.getCreatedClass().getName() +
                      ": improperly decommissioned.", e );
          }
        }
      }
    }
  }
}

代码示例来源:origin: org.objectstyle.ashwood/ashwood

public void reset(Object newFirstVertex) {
 if (!queue.isEmpty()) queue.clear();
 if (!seen.isEmpty()) seen.clear();
 this.firstVertex = newFirstVertex;
 queue.add(firstVertex);
 seen.add(firstVertex);
}

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

if (getBuffer().size() + nAdditions > maximumSize) {
    throw new BufferOverflowException(
        "Buffer size cannot exceed " + maximumSize);
while (timeLeft > 0 && getBuffer().size() + nAdditions > maximumSize) {
  try {
    lock.wait(timeLeft);
if (getBuffer().size() + nAdditions > maximumSize) {
  throw new BufferOverflowException("Timeout expired");

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

public boolean addAll(final Collection c) {
  synchronized (lock) {
    timeoutWait(c.size());
    return getBuffer().addAll(c);
  }
}

代码示例来源: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" );
    }
  }
}

相关文章