Java Code Examples for java.util.Queue.toArray()

The following are Jave code examples for showing how to use toArray() of the java.util.Queue class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: neoscada   File: DaemonStarter.java   Source Code and License Vote up 6 votes
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 );
    }
}
 
Example 2
Project: incubator-netbeans   File: J2SEDeployActionProvider.java   Source Code and License Vote up 5 votes
@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()]);
}
 
Example 3
Project: openjdk-jdk10   File: WhiteBox.java   Source Code and License Vote up 5 votes
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());
}
 
Example 4
Project: openjdk-jdk10   File: CircularBufferTest.java   Source Code and License Vote up 5 votes
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);
    }
 
Example 5
Project: HCFCore   File: TransformedQueue.java   Source Code and License Vote up 3 votes
/**
 * 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;
}
 
Example 6
Project: HCFCore   File: TransformedQueue.java   Source Code and License Vote up 3 votes
/**
 * 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;
}