Java Code Examples for java.util.concurrent.LinkedBlockingQueue.toArray()

The following are Jave code examples for showing how to use toArray() of the java.util.concurrent.LinkedBlockingQueue class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   View Source Code Vote up 5 votes
/**
 * toArray contains all elements in FIFO order
 */
public void testToArray() {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    Object[] o = q.toArray();
    for (int i = 0; i < o.length; i++)
        assertSame(o[i], q.poll());
}
 
Example 2
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   View Source Code Vote up 5 votes
/**
 * toArray(a) contains all elements in FIFO order
 */
public void testToArray2() throws InterruptedException {
    LinkedBlockingQueue<Integer> q = populatedQueue(SIZE);
    Integer[] ints = new Integer[SIZE];
    Integer[] array = q.toArray(ints);
    assertSame(ints, array);
    for (int i = 0; i < ints.length; i++)
        assertSame(ints[i], q.poll());
}
 
Example 3
Project: openjdk-jdk10   File: LinkedBlockingQueueTest.java   View Source Code Vote up 5 votes
/**
 * toArray(incompatible array type) throws ArrayStoreException
 */
public void testToArray1_BadArg() {
    LinkedBlockingQueue q = populatedQueue(SIZE);
    try {
        q.toArray(new String[10]);
        shouldThrow();
    } catch (ArrayStoreException success) {}
}