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


Java Collections.checkedQueue方法代码示例

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

    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:CheckedQueue.java

示例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");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:CheckedQueue.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:CheckedQueue.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:CheckedQueue.java


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