本文整理汇总了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 );
}
}
示例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()]);
}
示例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());
}
示例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);
}
示例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;
}