Skip to content

Feature request - ordered read vs drain #1

@sfkamath

Description

@sfkamath

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions