当前位置: 首页>>代码示例>>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;未经允许,请勿转载。