本文整理汇总了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);
}