/** * Serialize this deque. * * @serialData The current size (<tt>int</tt>) of the deque, followed by all * of its elements (each an object reference) in first-to-last * order. */ private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); // Write out size s.writeInt(size()); // Write out elements in order. int mask = elements.length - 1; for (int i = head; i != tail; i = (i + 1) & mask) s.writeObject(elements[i]); }
/** * Copies the elements from our element array into the specified array, in * order (from first to last element in the deque). It is assumed that the * array is large enough to hold all elements in the deque. * * @return its argument */ private <T> T[] copyElements(T[] a) { if (head < tail) { System.arraycopy(elements, head, a, 0, size()); } else if (head > tail) { int headPortionLen = elements.length - head; System.arraycopy(elements, head, a, 0, headPortionLen); System.arraycopy(elements, 0, a, headPortionLen, tail); } return a; }
/** * Returns an array containing all of the elements in this deque in proper * sequence (from first to last element). * * <p> * The returned array will be "safe" in that no references to it are * maintained by this deque. (In other words, this method must allocate a * new array). The caller is thus free to modify the returned array. * * <p> * This method acts as bridge between array-based and collection-based APIs. * * @return an array containing all of the elements in this deque */ @Override public Object[] toArray() { return copyElements(new Object[size()]); }
int size = size(); if (a.length < size) a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size);
public ArrayDeque<SilkEvent> call() throws Exception { for (int cursor = 0; cursor < cache.size(); cursor++) { try { SilkEvent e = SilkLinePushParser.parseLine(lexer, tokenStream, cache.get(cursor)); if (e != null) { eventQueue.add(e); } } catch (XerialException e) { if (e.getErrorCode() == XerialErrorCode.PARSE_ERROR) _logger.warn(e); else throw e; } } // finished the parsing cache.clear(); if (_logger.isTraceEnabled()) _logger.trace(String.format("finished workder=%d. event queue size = %d", lsn, eventQueue.size())); return eventQueue; }
public ArrayDeque<SilkEvent> call() throws Exception { for (int cursor = 0; cursor < cache.size(); cursor++) { try { SilkEvent e = SilkLinePushParser.parseLine(lexer, tokenStream, cache.get(cursor)); if (e != null) { eventQueue.add(e); } } catch (XerialException e) { if (e.getErrorCode() == XerialErrorCode.PARSE_ERROR) _logger.warn(e); else throw e; } } // finished the parsing cache.clear(); if (_logger.isTraceEnabled()) _logger.trace(String.format("finished workder=%d. event queue size = %d", lsn, eventQueue.size())); return eventQueue; }