本文整理匯總了Java中java.util.Collections.checkedQueue方法的典型用法代碼示例。如果您正苦於以下問題:Java Collections.checkedQueue方法的具體用法?Java Collections.checkedQueue怎麽用?Java Collections.checkedQueue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Collections
的用法示例。
在下文中一共展示了Collections.checkedQueue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAdd
import java.util.Collections; //導入方法依賴的package包/類
/**
* 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) {
}
}
示例2: testOffer
import java.util.Collections; //導入方法依賴的package包/類
/**
* 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");
}
示例3: testAddFail1
import java.util.Collections; //導入方法依賴的package包/類
/**
* 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);
}
示例4: testAddFail2
import java.util.Collections; //導入方法依賴的package包/類
/**
* 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);
}