circular-buffer icon indicating copy to clipboard operation
circular-buffer copied to clipboard

Feature request - ordered read vs drain

Open sfkamath opened this issue 12 years ago • 0 comments

Have a need to examine the contents of the circular buffer and build a list based on insert order.

Initially read your blog and the following snippet is based on your initial revision there.

public List<T> getAllOrdered() {
    List<T> list = new Vector<T>(size);
    for (int i = index.get() + 1; i < size; i++) {
        if(buffer.get(i) != null)
            list.add(buffer.get(i));
    }
    for (int i = 0; i < index.get() + 1; i++) 
        list.add(buffer.get(i));
    return list;
}  

The code might not be thread safe in that the buffer might get updated while I am building the list. Hoping I can download the code from github and use as a library with the above method included.

Regards Suneet

sfkamath avatar Sep 11 '12 13:09 sfkamath