当前位置: 首页>>代码示例>>Java>>正文


Java Buffer.add方法代码示例

本文整理汇总了Java中org.apache.commons.collections15.Buffer.add方法的典型用法代码示例。如果您正苦于以下问题:Java Buffer.add方法的具体用法?Java Buffer.add怎么用?Java Buffer.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.collections15.Buffer的用法示例。


在下文中一共展示了Buffer.add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requeueReservation

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
/**
 * Take an existing Reservation that we know is legit and randomly decide to 
 * either queue it for a later update or delete transaction 
 * @param r
 */
protected void requeueReservation(Reservation r) {
    int idx = rng.nextInt(100);
    if (idx > 20) return;
    
    // Queue this motha trucka up for a deletin' or an updatin'
    CacheType ctype = null;
    if (rng.nextBoolean()) {
        ctype = CacheType.PENDING_DELETES;
    } else {
        ctype = CacheType.PENDING_UPDATES;
    }
    assert(ctype != null);
    
    Buffer<Reservation> cache = CACHE_RESERVATIONS.get(ctype);
    assert(cache != null);
    cache.add(r);
    if (debug.val)
        LOG.debug(String.format("Queued %s for %s [cacheSize=%d]\nFlightId: %d\nCustomerId: %d",
                  r, ctype, cache.size(),
                  r.flight_id, r.customer_id));
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:27,代码来源:SEATSClient.java

示例2: testBlockedGetWithAdd

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
/**
 * Tests {@link BlockingBuffer#get()} in combination with {@link BlockingBuffer#add()} 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.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:31,代码来源:TestBlockingBuffer.java

示例3: testCircularFifoBufferCircular

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
/**
 * 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());
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:27,代码来源:TestCircularFifoBuffer.java

示例4: testTransformedBuffer

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
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])));

}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:16,代码来源:TestTransformedBuffer.java

示例5: testBlockedRemoveWithAdd

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
/**
 * Tests {@link BlockingBuffer#remove()} in combination with {@link BlockingBuffer#add()} 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.");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:39,代码来源:TestBlockingBuffer.java

示例6: testGet

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
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");
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:14,代码来源:TestPredicatedBuffer.java

示例7: testRemove

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
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
    }
}
 
开发者ID:jgaltidor,项目名称:VarJ,代码行数:12,代码来源:TestPredicatedBuffer.java

示例8: transform

import org.apache.commons.collections15.Buffer; //导入方法依赖的package包/类
/**
 * Extracts the weak components from a graph.
 * @param graph the graph whose weak components are to be extracted
 * @return the list of weak components
 */
public Set<Set<V>> transform(Graph<V,E> graph) {

    Set<Set<V>> clusterSet = new HashSet<Set<V>>();

    HashSet<V> unvisitedVertices = new HashSet<V>(graph.getVertices());

    while (!unvisitedVertices.isEmpty()) {
    	Set<V> cluster = new HashSet<V>();
        V root = unvisitedVertices.iterator().next();
        unvisitedVertices.remove(root);
        cluster.add(root);

        Buffer<V> queue = new UnboundedFifoBuffer<V>();
        queue.add(root);

        while (!queue.isEmpty()) {
            V currentVertex = queue.remove();
            Collection<V> neighbors = graph.getNeighbors(currentVertex);

            for(V neighbor : neighbors) {
                if (unvisitedVertices.contains(neighbor)) {
                    queue.add(neighbor);
                    unvisitedVertices.remove(neighbor);
                    cluster.add(neighbor);
                }
            }
        }
        clusterSet.add(cluster);
    }
    return clusterSet;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:37,代码来源:WeakComponentClusterer.java


注:本文中的org.apache.commons.collections15.Buffer.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。