public interface

RingBuffer<E>

 androidx.camera.video.internal.utils.RingBuffer<E>

Subclasses:

ArrayDequeRingBuffer<E>

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-video', version: '1.2.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-video
  • version: 1.2.0-alpha01

Artifact androidx.camera:camera-video:1.2.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

A limited size FIFO storage, which automatically evicts elements from the head when attempting to add new elements onto the storage and it is full.

Summary

Methods
public intcapacity()

Returns the number of elements that the RingBuffer can hold.

public voidclear()

Removes all of the elements.

public booleanisEmpty()

Returns true if the RingBuffer contains no elements.

public booleanoffer(java.lang.Object element)

Adds the specified element to the tail of the RingBuffer, if the number of elements reaches the capacity, the element at the head of the RingBuffer will be removed.

public java.lang.Objectpeek()

Retrieves, but does not remove, the head of the RingBuffer, or returns null if the RingBuffer is empty.

public java.lang.Objectpoll()

Retrieves and removes the head of the RingBuffer, or returns null if the RingBuffer is empty.

public intsize()

Returns the number of elements in the RingBuffer.

Methods

public boolean offer(java.lang.Object element)

Adds the specified element to the tail of the RingBuffer, if the number of elements reaches the capacity, the element at the head of the RingBuffer will be removed.

Parameters:

element: the element to add

Returns:

true if the element was added to the RingBuffer, else false

public java.lang.Object poll()

Retrieves and removes the head of the RingBuffer, or returns null if the RingBuffer is empty.

Returns:

the head of the RingBuffer, or null if the RingBuffer is empty

public java.lang.Object peek()

Retrieves, but does not remove, the head of the RingBuffer, or returns null if the RingBuffer is empty.

Returns:

the head of the RingBuffer, or null if the @link RingBuffer} is empty

public int capacity()

Returns the number of elements that the RingBuffer can hold.

Returns:

the number of elements that the RingBuffer can hold

public int size()

Returns the number of elements in the RingBuffer.

Returns:

the number of elements in the RingBuffer

public boolean isEmpty()

Returns true if the RingBuffer contains no elements.

Returns:

true if the RingBuffer contains no elements

public void clear()

Removes all of the elements. The RingBuffer will be empty after this method returns.

Source

/*
 * Copyright 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.video.internal.utils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

/**
 * A limited size FIFO storage, which automatically evicts elements from the head when attempting
 * to add new elements onto the storage and it is full.
 *
 * @param <E> the type of elements stored in the RingBuffer
 */
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
public interface RingBuffer<E> {

    /**
     * Adds the specified element to the tail of the {@link RingBuffer}, if the number of elements
     * reaches the capacity, the element at the head of the {@link RingBuffer} will be removed.
     *
     * @param element the element to add
     * @return true if the element was added to the {@link RingBuffer}, else false
     */
    boolean offer(@NonNull E element);

    /**
     * Retrieves and removes the head of the {@link RingBuffer}, or returns null if the
     * {@link RingBuffer} is empty.
     *
     * @return the head of the {@link RingBuffer}, or null if the {@link RingBuffer} is empty
     */
    @Nullable
    E poll();

    /**
     * Retrieves, but does not remove, the head of the {@link RingBuffer}, or returns null if the
     * {@link RingBuffer} is empty.
     *
     * @return the head of the {@link RingBuffer}, or null if the @link RingBuffer} is empty
     */
    @Nullable
    E peek();

    /**
     * Returns the number of elements that the {@link RingBuffer} can hold.
     *
     * @return the number of elements that the {@link RingBuffer} can hold
     */
    int capacity();

    /**
     * Returns the number of elements in the {@link RingBuffer}.
     *
     * @return the number of elements in the {@link RingBuffer}
     */
    int size();

    /**
     * Returns true if the {@link RingBuffer} contains no elements.
     *
     * @return true if the {@link RingBuffer} contains no elements
     */
    boolean isEmpty();

    /**
     * Removes all of the elements. The {@link RingBuffer} will be empty after this method returns.
     */
    void clear();
}