當前位置: 首頁>>代碼示例>>Java>>正文


Java Queue.toArray方法代碼示例

本文整理匯總了Java中java.util.Queue.toArray方法的典型用法代碼示例。如果您正苦於以下問題:Java Queue.toArray方法的具體用法?Java Queue.toArray怎麽用?Java Queue.toArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.Queue的用法示例。


在下文中一共展示了Queue.toArray方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.util.Queue; //導入方法依賴的package包/類
public static void main ( final String[] args ) throws Exception
{
    if ( args.length == 0 )
    {
        throw new RuntimeException ( "syntax: DaemonStarter <daemon class name>" );
    }

    final Queue<String> argList = new LinkedList<String> ();
    argList.addAll ( Arrays.asList ( args ) );

    new DaemonStarter ( Class.forName ( argList.poll () ), argList.toArray ( new String[0] ) );

    while ( true )
    {
        Thread.sleep ( 1000 );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:18,代碼來源:DaemonStarter.java

示例2: getSupportedActions

import java.util.Queue; //導入方法依賴的package包/類
@Override
public String[] getSupportedActions() {
    final Set<NativeBundleType> nbts = NativeBundleType.getSupported();
    final Queue<String> res = new ArrayDeque<>(nbts.size());
    for (NativeBundleType nbt : nbts) {
        res.add(nbt.getCommand());
    }
    return res.toArray(new String[res.size()]);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:J2SEDeployActionProvider.java

示例3: checkIterationSanity

import java.util.Queue; //導入方法依賴的package包/類
void checkIterationSanity(Queue q) {
    if (rnd.nextBoolean())
        return;
    int size = q.size();
    Object[] a = q.toArray();
    Object[] b = new Object[size+2];
    Arrays.fill(b, Boolean.TRUE);
    Object[] c = q.toArray(b);
    assertEquals(a.length, size);
    assertSame(b, c);
    assertNull(b[size]);
    assertSame(b[size+1], Boolean.TRUE);
    assertEquals(q.toString(), Arrays.toString(a));
    Integer[] xx = null, yy = null;
    if (size > 0) {
        xx = new Integer[size - 1];
        Arrays.fill(xx, 42);
        yy = ((Queue<Integer>)q).toArray(xx);
        for (Integer zz : xx)
            assertEquals(42, (int) zz);
    }
    Iterator it = q.iterator();
    for (int i = 0; i < size; i++) {
        if (rnd.nextBoolean()) assertTrue(it.hasNext());
        Object x = it.next();
        assertSame(x, a[i]);
        assertSame(x, b[i]);
        if (xx != null) assertSame(x, yy[i]);
    }
    if (rnd.nextBoolean()) assertTrue(!it.hasNext());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:WhiteBox.java

示例4: resizeOnce

import java.util.Queue; //導入方法依賴的package包/類
private void resizeOnce(int capacity) {

        int nextNumberToPut = 0;

        Queue<Integer> referenceQueue = new ArrayBlockingQueue<>(capacity);
        CircularBuffer<Integer> buffer = new CircularBuffer<>(capacity);

        // Fill full, so the next add will wrap
        for (int i = 0; i < capacity; i++, nextNumberToPut++) {
            buffer.add(nextNumberToPut);
            referenceQueue.add(nextNumberToPut);
        }
        int gets = r.nextInt(capacity); // [0, capacity)
        for (int i = 0; i < gets; i++) {
            referenceQueue.poll();
            buffer.remove();
        }
        int puts = r.nextInt(gets + 1); // [0, gets]
        for (int i = 0; i < puts; i++, nextNumberToPut++) {
            buffer.add(nextNumberToPut);
            referenceQueue.add(nextNumberToPut);
        }

        Integer[] expected = referenceQueue.toArray(new Integer[0]);
        buffer.resize(expected.length);

        assertEquals(buffer.elements, expected);
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:CircularBufferTest.java

示例5: transformedQueue

import java.util.Queue; //導入方法依賴的package包/類
/**
 * Factory method to create a transforming queue that will transform
 * existing contents of the specified queue.
 * <p>
 * If there are any elements already in the queue being decorated, they
 * will be transformed by this method.
 * Contrast this with {@link #transformingQueue(Queue, Transformer)}.
 *
 * @param <E> the type of the elements in the queue
 * @param queue  the queue to decorate, must not be null
 * @param transformer  the transformer to use for conversion, must not be null
 * @return a new transformed Queue
 * @throws NullPointerException if queue or transformer is null
 * @since 4.0
 */
public static <E> TransformedQueue<E> transformedQueue(final Queue<E> queue,
                                                       final Transformer<? super E, ? extends E> transformer) {
    // throws IAE if queue or transformer is null
    final TransformedQueue<E> decorated = new TransformedQueue<E>(queue, transformer);
    if (queue.size() > 0) {
        @SuppressWarnings("unchecked") // queue is type <E>
        final E[] values = (E[]) queue.toArray(); // NOPMD - false positive for generics
        queue.clear();
        for (final E value : values) {
            decorated.decorated().add(transformer.transform(value));
        }
    }
    return decorated;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:30,代碼來源:TransformedQueue.java


注:本文中的java.util.Queue.toArray方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。