當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。