Java Code Examples for java.util.Collections.checkedQueue()

The following are Jave code examples for showing how to use checkedQueue() of the java.util.Collections 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: jdk8u-jdk   File: CheckedQueue.java   View Source Code Vote up 6 votes
/**
 * This test adds items to a queue.
 */
@Test
public void testAdd() {
    int arrayLength = 10;
    Queue<String> abq = Collections.checkedQueue(new ArrayBlockingQueue<>(arrayLength), String.class);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    try {
        abq.add("full");
    } catch (IllegalStateException full) {

    }
}
 
Example 2
Project: jdk8u-jdk   File: CheckedQueue.java   View Source Code Vote up 6 votes
/**
 * This test tests the CheckedQueue.offer method.
 */
@Test
public void testOffer() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.offer(null);
        fail("should throw NullPointerException.");
    } catch (NullPointerException npe) {
        // Do nothing
    }

    try {
        q.offer(0);
        fail("should throw ClassCastException.");
    } catch (ClassCastException cce) {
        // Do nothing
    }

    assertTrue(q.offer("0"), "queue should have room");

    // no room at the inn!
    assertFalse(q.offer("1"), "queue should be full");
}
 
Example 3
Project: openjdk-jdk10   File: CheckedQueue.java   View Source Code Vote up 6 votes
/**
 * This test adds items to a queue.
 */
@Test
public void testAdd() {
    int arrayLength = 10;
    Queue<String> abq = Collections.checkedQueue(new ArrayBlockingQueue<>(arrayLength), String.class);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    try {
        abq.add("full");
    } catch (IllegalStateException full) {

    }
}
 
Example 4
Project: openjdk-jdk10   File: CheckedQueue.java   View Source Code Vote up 6 votes
/**
 * This test tests the CheckedQueue.offer method.
 */
@Test
public void testOffer() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.offer(null);
        fail("should throw NullPointerException.");
    } catch (NullPointerException npe) {
        // Do nothing
    }

    try {
        q.offer(0);
        fail("should throw ClassCastException.");
    } catch (ClassCastException cce) {
        // Do nothing
    }

    assertTrue(q.offer("0"), "queue should have room");

    // no room at the inn!
    assertFalse(q.offer("1"), "queue should be full");
}
 
Example 5
Project: jdk8u-jdk   File: CheckedQueue.java   View Source Code Vote up 5 votes
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of
 * {@code String}s gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail1() {
    int arrayLength = 10;
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(arrayLength + 1);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    Queue q = Collections.checkedQueue(abq, String.class);
    q.add(0);
}
 
Example 6
Project: jdk8u-jdk   File: CheckedQueue.java   View Source Code Vote up 5 votes
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of one
 * {@code String}, gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail2() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    q.add(0);
}
 
Example 7
Project: openjdk-jdk10   File: CheckedQueue.java   View Source Code Vote up 5 votes
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of
 * {@code String}s gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail1() {
    int arrayLength = 10;
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(arrayLength + 1);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    Queue q = Collections.checkedQueue(abq, String.class);
    q.add(0);
}
 
Example 8
Project: openjdk-jdk10   File: CheckedQueue.java   View Source Code Vote up 5 votes
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of one
 * {@code String}, gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail2() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    q.add(0);
}