Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e780e8d2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add createNewItem() to RingBuffer util class."

parents e6c4fdc6 d20627f5
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -67,16 +67,21 @@ public class RingBuffer<T> {
     */
    public T getNextSlot() {
        final int nextSlotIdx = indexOf(mCursor++);
        T item = mBuffer[nextSlotIdx];
        if (item == null) {
        if (mBuffer[nextSlotIdx] == null) {
            mBuffer[nextSlotIdx] = createNewItem();
        }
        return mBuffer[nextSlotIdx];
    }

    /**
     * @return a new object of type <T> or null if a new object could not be created.
     */
    protected T createNewItem() {
        try {
                item = (T) mBuffer.getClass().getComponentType().newInstance();
            return (T) mBuffer.getClass().getComponentType().newInstance();
        } catch (IllegalAccessException | InstantiationException e) {
            return null;
        }
            mBuffer[nextSlotIdx] = item;
        }
        return item;
    }

    public T[] toArray() {