/** * Obtain all the messages currently present in the list. * * @return array containing all the log messages */ public Object[] toArray() { if (mQ.size() == mFifoSize) { /* * Once the queue is full, it stays full until the user explicitly clears * all the logs. Optimize for this case by not reallocating the array. */ return mQ.toArray(mQArray); } return mQ.toArray(); }
private MPacket searchQueue() { if (eventQueue.size() == 0) return null; MPacket tempQueue[] = Arrays.copyOf(eventQueue.toArray(), eventQueue.toArray().length, MPacket[].class); for (int i = 0; i < eventQueue.size(); i++) { if (tempQueue[i].sequenceNumber == clientSequenceNumber) { eventQueue.remove(tempQueue[i]); return tempQueue[i]; } } return null; }
void checkEmpty(BlockingQueue q) { try { assertTrue(q.isEmpty()); assertEquals(0, q.size()); assertNull(q.peek()); assertNull(q.poll()); assertNull(q.poll(0, MILLISECONDS)); assertEquals("[]", q.toString()); assertTrue(Arrays.equals(q.toArray(), new Object[0])); assertFalse(q.iterator().hasNext()); try { q.element(); shouldThrow(); } catch (NoSuchElementException success) { } try { q.iterator().next(); shouldThrow(); } catch (NoSuchElementException success) { } try { q.remove(); shouldThrow(); } catch (NoSuchElementException success) { } } catch (InterruptedException ie) { threadUnexpectedException(ie); } }
/** * Resize the message list. * * @param n new size for the list */ public synchronized void resize(int n) { mFifoSize = n; if (mFifoSize > mQ.size()) { /* if resizing to a bigger fifo, we can copy over all elements from the current mQ */ mQ = new ArrayBlockingQueue<LogCatMessage>(mFifoSize, true, mQ); } else { /* for a smaller fifo, copy over the last n entries */ LogCatMessage[] curMessages = mQ.toArray(new LogCatMessage[mQ.size()]); mQ = new ArrayBlockingQueue<LogCatMessage>(mFifoSize); for (int i = curMessages.length - mFifoSize; i < curMessages.length; i++) { mQ.offer(curMessages[i]); } } mQArray = new LogCatMessage[mFifoSize]; }
@Override public <T> T[] toArray(T[] a) { return delegate.toArray(a); }
@Override public Object[] toArray() { return delegate.toArray(); }
@Override public Object[] toArray() { return localInternalQueue.toArray(); }
@Override public <T> T[] toArray(T[] a) { return localInternalQueue.toArray(a); }
/** * returns all requests captured so far. Doesn't clear the captured request list. See {@link * #clear()} */ public CapturedRequest[] capturedRequests() { return capturedRequests.toArray(new CapturedRequest[0]); }