/** * Copies all request data into {@code copy} such that the oldest request is in slot 0 and the * most recent request is in slot {@code copy.length} * * @param copy * the target, has to have a capacity of at least {@code requestWindow.length} */ private void copyRequestsInOrder(RequestData[] copy) { int destPos = 0; if (hasBufferRolledOver()) { destPos = requestWindow.length - indexInWindow; // first copy the oldest requests stored behind the cursor into the copy arraycopy(requestWindow, indexInWindow, copy, 0, destPos); } arraycopy(requestWindow, 0, copy, destPos, indexInWindow); }
/** * Copies all request data into {@code copy} such that the oldest request is in slot 0 and the * most recent request is in slot {@code copy.length} * * @param copy * the target, has to have a capacity of at least {@code requestWindow.length} */ private void copyRequestsInOrder(RequestData[] copy) { int destPos = 0; if (hasBufferRolledOver()) { destPos = requestWindow.length - indexInWindow; // first copy the oldest requests stored behind the cursor into the copy arraycopy(requestWindow, indexInWindow, copy, 0, destPos); } arraycopy(requestWindow, 0, copy, destPos, indexInWindow); }
@Override public List<RequestData> getRequests() { synchronized (requestWindowLock) { RequestData[] result = new RequestData[hasBufferRolledOver() ? requestWindow.length : indexInWindow]; copyRequestsInOrder(result); return Arrays.asList(result); } }
@Override public List<RequestData> getRequests() { synchronized (requestWindowLock) { RequestData[] result = new RequestData[hasBufferRolledOver() ? requestWindow.length : indexInWindow]; copyRequestsInOrder(result); return Arrays.asList(result); } }
int oldNumberOfElements = hasBufferRolledOver() ? oldCapacity : indexInWindow;
int oldNumberOfElements = hasBufferRolledOver() ? oldCapacity : indexInWindow;