Java ~ Collection/Executor ~ BlockingDeque【源码】

33 篇文章 0 订阅
17 篇文章 0 订阅

前言


    文中的源码注释/结论是我个人学习过程中的理解/看法,多有漏误,后期的新看法/总结也不会再于本文中修正/添加,因此本文内容只可作为参考/提示使用,最新看法/总结以总结篇为准,链接在本文底部。

一 BlockingDeque(阻塞双端队列)接口源码及机制详解


 接口

    BlockingDeque(阻塞双端队列)接口(下文简称阻塞双端队列)是BlockingQueue(阻塞队列)接口的子接口,在其的基础上进行了功能性的加强,新增了可在队列的两端进行插入/移除/检查操作的方法定义,就如同Deque(双端队列)接口对Queue(队列)接口做的那样。事实上,阻塞双端队列也确实同时是Deque(双端队列)接口的子接口,因此其新增的方法定义中有一部分是从Deque(双端队列)接口直接继承得来的,该知识点的详细内容会在下文详述。

    阻塞双端队列是线程安全的,即实现类无论采用了何种实现方式,都必须保证线程安全,该定义继承自BlockingQueue(阻塞队列)接口。该定义意味着阻塞双端队列实现类的绝大多数方法实现都会是原子性的(否则无法保证线程安全),但对于批量方法就并非如此。例如addAll()、containsAll()及removeAll()等方法完全可以在底层循环调用add()、contains()及remove()方法来达到目的,因此在整体执行中可能伴随着并发。总的来说,即只要求单方法原子性执行,而批量方法除非特别指定,否则没有原子性执行的要求。因此,对于批量方法部分成功部分失败的情况是可以被接受的。例如在addAll()方法执行的过程中有元素抛出异常而导致后续元素添加失败,但前期元素添加成功的场景。

    阻塞双端队列不允许存null值,该定义继承自BlockingQueue(阻塞队列)接口。接口规定一旦尝试在阻塞双端队列中存null值时必须抛出空异常,这是较为少见的,因为一般来说接口都不会对null值做强制的定义,而是交给子类自身去决定。阻塞双端队列之所以强制不允许存null值是因为null已经被用来作为标志位使用,具体原因与“方法的不同形式”有关,该知识点的详细内容会在下文详述。

    阻塞双端队列虽然与BlockingQueue(阻塞队列)接口一样都被纳入Executor(执行器)框架的范畴,但同时也是Collection(集)框架的成员。

/**
 * A {@link Deque} that additionally supports blocking operations that wait for the deque to become non-empty when retrieving an element,
 * and wait for space to become available in the deque when storing an element.
 * 一个更加支持阻塞操作的双端队列,当检索一个元素时等待双端队列变为非空,当保存一个元素时等待双端队列中的空间变得可用。
 *
 * <p>
 * {@code BlockingDeque} methods come in four forms, with different ways of handling operations that cannot be satisfied immediately, but
 * may be satisfied at some point in the future: one throws an exception, the second returns a special value (either {@code null} or {@code false},
 * depending on the operation), the third blocks the current thread indefinitely until the operation can succeed, and the fourth blocks for only
 * a given maximum time limit before giving up. These methods are summarized in the following table:
 * 阻塞双端队列方法有四种形式,以不同的方式处理法直接满足,但在未来的某个时间点可能满足的操作:一是抛出一个异常,二是返回一
 * 个特殊值(要么null要么false,取决于操作),三是无限期地阻塞当前线程直至操作成功,四是在放弃之前只阻塞指定最大限度的时间限制。
 * 这些方法已在下表中总结。
 * <p>
 * <table BORDER CELLPADDING=3 CELLSPACING=1>
 * <caption>Summary of BlockingDeque methods</caption>
 * <caption>阻塞双端队列方法总结</caption>
 * <tr>
 * <td ALIGN=CENTER COLSPAN = 5> <b>First Element (Head)</b></td>
 * </tr>
 * <tr>
 * <td></td>
 * <td ALIGN=CENTER><em>Throws exception</em></td>
 * <td ALIGN=CENTER><em>Special value</em></td>
 * <td ALIGN=CENTER><em>Blocks</em></td>
 * <td ALIGN=CENTER><em>Times out</em></td>
 * </tr>
 * <tr>
 * <td><b>Insert</b></td>
 * <td>{@link #addFirst addFirst(e)}</td>
 * <td>{@link #offerFirst(Object) offerFirst(e)}</td>
 * <td>{@link #putFirst putFirst(e)}</td>
 * <td>{@link #offerFirst(Object, long, TimeUnit) offerFirst(e, time, unit)}</td>
 * </tr>
 * <tr>
 * <td><b>Remove</b></td>
 * <td>{@link #removeFirst removeFirst()}</td>
 * <td>{@link #pollFirst pollFirst()}</td>
 * <td>{@link #takeFirst takeFirst()}</td>
 * <td>{@link #pollFirst(long, TimeUnit) pollFirst(time, unit)}</td>
 * </tr>
 * <tr>
 * <td><b>Examine</b></td>
 * <td>{@link #getFirst getFirst()}</td>
 * <td>{@link #peekFirst peekFirst()}</td>
 * <td><em>not applicable</em></td>
 * <td><em>not applicable</em></td>
 * </tr>
 * <tr>
 * <td ALIGN=CENTER COLSPAN = 5> <b>Last Element (Tail)</b></td>
 * </tr>
 * <tr>
 * <td></td>
 * <td ALIGN=CENTER><em>Throws exception</em></td>
 * <td ALIGN=CENTER><em>Special value</em></td>
 * <td ALIGN=CENTER><em>Blocks</em></td>
 * <td ALIGN=CENTER><em>Times out</em></td>
 * </tr>
 * <tr>
 * <td><b>Insert</b></td>
 * <td>{@link #addLast addLast(e)}</td>
 * <td>{@link #offerLast(Object) offerLast(e)}</td>
 * <td>{@link #putLast putLast(e)}</td>
 * <td>{@link #offerLast(Object, long, TimeUnit) offerLast(e, time, unit)}</td>
 * </tr>
 * <tr>
 * <td><b>Remove</b></td>
 * <td>{@link #removeLast() removeLast()}</td>
 * <td>{@link #pollLast() pollLast()}</td>
 * <td>{@link #takeLast takeLast()}</td>
 * <td>{@link #pollLast(long, TimeUnit) pollLast(time, unit)}</td>
 * </tr>
 * <tr>
 * <td><b>Examine</b></td>
 * <td>{@link #getLast getLast()}</td>
 * <td>{@link #peekLast peekLast()}</td>
 * <td><em>not applicable</em></td>
 * <td><em>not applicable</em></td>
 * </tr>
 * </table>
 * <p>
 * Like any {@link BlockingQueue}, a {@code BlockingDeque} is thread safe, does not permit null elements, and may (or may not) be capacity-
 * constrained.
 * 类似于任意阻塞队列,一个阻塞双端队列是线程安全的,不允许null元素,以及可能(或不会)容量受限。
 * <p>
 * A {@code BlockingDeque} implementation may be used directly as a FIFO {@code BlockingQueue}. The methods inherited from the {@code
 * BlockingQueue} interface are precisely equivalent to {@code BlockingDeque} methods as indicated in the following table:
 * 一个阻塞双端队列实现可能直接作为一个先入先出的阻塞队列使用。从阻塞队列接口继承的方法精确对应阻塞双端队列方法在下表中表示:
 * <p>
 * <table BORDER CELLPADDING=3 CELLSPACING=1>
 * <caption>Comparison of BlockingQueue and BlockingDeque methods</caption>
 * <caption>比较阻塞队列与阻塞双端队列的方法</caption>
 * <tr>
 * <td ALIGN=CENTER> <b>{@code BlockingQueue} Method</b></td>
 * <td ALIGN=CENTER> <b>Equivalent {@code BlockingDeque} Method</b></td>
 * </tr>
 * <tr>
 * <td ALIGN=CENTER COLSPAN = 2> <b>Insert</b></td>
 * </tr>
 * <tr>
 * <td>{@link #add(Object) add(e)}</td>
 * <td>{@link #addLast(Object) addLast(e)}</td>
 * </tr>
 * <tr>
 * <td>{@link #offer(Object) offer(e)}</td>
 * <td>{@link #offerLast(Object) offerLast(e)}</td>
 * </tr>
 * <tr>
 * <td>{@link #put(Object) put(e)}</td>
 * <td>{@link #putLast(Object) putLast(e)}</td>
 * </tr>
 * <tr>
 * <td>{@link #offer(Object, long, TimeUnit) offer(e, time, unit)}</td>
 * <td>{@link #offerLast(Object, long, TimeUnit) offerLast(e, time, unit)}</td>
 * </tr>
 * <tr>
 * <td ALIGN=CENTER COLSPAN = 2> <b>Remove</b></td>
 * </tr>
 * <tr>
 * <td>{@link #remove() remove()}</td>
 * <td>{@link #removeFirst() removeFirst()}</td>
 * </tr>
 * <tr>
 * <td>{@link #poll() poll()}</td>
 * <td>{@link #pollFirst() pollFirst()}</td>
 * </tr>
 * <tr>
 * <td>{@link #take() take()}</td>
 * <td>{@link #takeFirst() takeFirst()}</td>
 * </tr>
 * <tr>
 * <td>{@link #poll(long, TimeUnit) poll(time, unit)}</td>
 * <td>{@link #pollFirst(long, TimeUnit) pollFirst(time, unit)}</td>
 * </tr>
 * <tr>
 * <td ALIGN=CENTER COLSPAN = 2> <b>Examine</b></td>
 * </tr>
 * <tr>
 * <td>{@link #element() element()}</td>
 * <td>{@link #getFirst() getFirst()}</td>
 * </tr>
 * <tr>
 * <td>{@link #peek() peek()}</td>
 * <td>{@link #peekFirst() peekFirst()}</td>
 * </tr>
 * </table>
 *
 * <p>
 * Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a {@code BlockingDeque}
 * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a> actions subsequent to the access or removal of that element
 * from the {@code BlockingDeque} in another thread.
 * 内存一致性印象:与其他并发集一样,在将对象放入阻塞双端队列之前,线程中的操作发生在另一个线程中从阻塞双端队列中访问或删除该元
 * 素之后的操作之前。
 * <p>
 * This interface is a member of the <a href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections Framework</a>.
 * 该接口是Java集框架的成员。
 *
 * @param <E> the type of elements held in this collection 集中持有元素的类型
 * @author Doug Lea
 * @since 1.6
 */
public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {

    // 单继承是针对类的,对于接口是允许多继承的,这本质和实现是一致的。

    /*
     * We have "diamond" multiple interface inheritance here, and that  introduces ambiguities.  Methods might end up with different specs
     * depending on the branch chosen by javadoc.  Thus a lot of methods specs here are copied from superinterfaces.
     * 这里有“菱形”多接口继承,这引入了歧义。方法最终可能具有不同的规格,则取决于Java文档选择的分支。因此许多方法规则从超
     * 接口中复制而来。
     */
     
    ...
}

 方法

    void addFirst(E e) —— 新增首个 —— 向当前阻塞双端队列的头部插入指定元素。该方法是头部插入/放置方法“异常”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功;否则抛出非法状态异常。

/**
 * Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions,
 * throwing an {@code IllegalStateException} if no space is currently available.  When using a capacity-restricted deque, it is generally
 * preferable to use {@link #offerFirst(Object) offerFirst}.
 * 如果可以立即在不违反容量限制的情况下在双端队列的头部插入指定元素,如果当前没有空间可用则抛出非法状态异常。当使用一个
 * 容量首先得双端队列是,通常使用offerFirst(E e)方法更好。
 *
 * @param e the element to add 用于新增的元素
 * @throws IllegalStateException    {@inheritDoc} 非法状态异常
 * @throws ClassCastException       {@inheritDoc} 类转换异常
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException {@inheritDoc} 非法参数异常
 * @Description: 名称:新增首个
 * @Description: 作用:向当前阻塞双端队列的头部插入指定元素。该方法是头部插入/放置方法“异常”形式的实现,当阻塞双端队列存
 * @Description: 在剩余容量时插入/放置成功;否则抛出非法状态异常。
 * @Description: 逻辑:~
 */
void addFirst(E e);

    void addLast(E e) —— 新增最后 —— 向当前阻塞双端队列的尾部插入指定元素。该方法是尾部插入/放置方法“异常”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功;否则抛出非法状态异常。

/**
 * Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions,
 * throwing an {@code IllegalStateException} if no space is currently available.  When using a capacity-restricted deque, it is generally
 * preferable to use {@link #offerLast(Object) offerLast}.
 * 如果可以立即在不违反容量限制的情况下在双端队列的尾部插入指定元素,如果当前没有空间可用则抛出非法状态异常。当使用
 * 一个容量首先得双端队列是,通常使用offerLast(E e)方法更好。
 *
 * @param e the element to add 用于新增的元素
 * @throws IllegalStateException    {@inheritDoc} 非法状态异常
 * @throws ClassCastException       {@inheritDoc} 类转换异常
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException {@inheritDoc} 非法参数异常
 * @Description: 名称:新增最后
 * @Description: 作用:向当前阻塞双端队列的尾部插入指定元素。该方法是尾部插入/放置方法“异常”形式的实现,当阻塞双端队列
 * @Description: 存在剩余容量时插入/放置成功;否则抛出非法状态异常。
 * @Description: 逻辑:~
 */
void addLast(E e);

    boolean offerFirst(E e) —— 提供首个 —— 向当前阻塞双端队列的头部插入指定元素。该方法是头部插入/放置方法“特殊值”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功并返回true;否则返回false。

/**
 * Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions,
 * returning {@code true} upon success and {@code false} if no space is currently available. When using a capacity-restricted deque,
 * this method is generally preferable to the {@link #addFirst(Object) addFirst} method, which can fail to insert an element only by
 * throwing an exception.
 * 如果可以立即在不违反容量限制的情况下在双端队列的头部插入指定元素,在成功之后返回true;以及如果当前没有空间可用则返
 * 回false。当使用一个容量受限的双端队列时,当前方法通常比addFirst(E e)方法更好,其在插入元素失败时只能抛出异常。
 *
 * @param e the element to add 用于新增的元素
 * @throws ClassCastException       {@inheritDoc} 类转换异常
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException {@inheritDoc} 非法参数异常
 * @Description: 名称:提供首个
 * @Description: 作用:向当前阻塞双端队列的头部插入指定元素。该方法是头部插入/放置方法“特殊值”形式的实现,当阻塞双端队
 * @Description: 列存在剩余容量时插入/放置成功并返回true;否则返回false。
 * @Description: 逻辑:~
 */
boolean offerFirst(E e);

    boolean offerLast(E e) —— 提供最后 —— 向当前阻塞双端队列的尾部插入指定元素。该方法是尾部插入/放置方法“特殊值”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功并返回true;否则返回false。

/**
 * Inserts the specified element at the end of this deque if it is possible to do so immediately without violating capacity restrictions,
 * returning {@code true} upon success and {@code false} if no space is currently available. When using a capacity-restricted deque,
 * this method is generally preferable to the {@link #addLast(Object) addLast} method, which can fail to insert an element only by
 * throwing an exception.
 * 如果可以立即在不违反容量限制的情况下在双端队列的尾部插入指定元素,在成功之后返回true;以及如果当前没有空间可用则返
 * 回false。当使用一个容量受限的双端队列时,当前方法通常比addLast(E e)方法更好,其在插入元素失败时只能抛出异常。
 *
 * @param e the element to add 用于新增的元素
 * @throws ClassCastException       {@inheritDoc} 类转换异常
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException {@inheritDoc} 非法参数异常
 * @Description: 名称:提供最后
 * @Description: 作用:向当前阻塞双端队列的尾部插入指定元素。该方法是尾部插入/放置方法“特殊值”形式的实现,当阻塞双端队
 * @Description: 列存在剩余容量时插入/放置成功并返回true;否则返回false。
 * @Description: 逻辑:~
 */
boolean offerLast(E e);

    void putFirst(E e) throws InterruptedException —— 放置首个 —— 向当前阻塞双端队列的头部插入指定元素。该方法是头部插入/放置方法“阻塞”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功;否则等待至存在剩余容量为止。

/**
 * Inserts the specified element at the front of this deque, waiting if necessary for space to become available.
 * 在双端队列的头部插入指定元素,如果必要则等待至空间变的可用。
 *
 * @param e the element to add 新增的元素
 * @throws InterruptedException     if interrupted while waiting
 *                                  中断异常:如果在等待期间中断
 * @throws ClassCastException       if the class of the specified element prevents it from being added to this deque
 *                                  类转换异常:如果指定元素的类妨碍其加入当前双端队列
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException if some property of the specified element prevents it from being added to this deque
 *                                  非法参数异常:如果指定元素的某些属性妨碍其加入双端队列
 * @Description: 名称:放置首个
 * @Description: 作用:向当前阻塞双端队列的头部插入指定元素。该方法是头部插入/放置方法“阻塞”形式的实现,当阻塞双端队列
 * @Description: 存在剩余容量时插入/放置成功;否则等待至存在剩余容量为止。
 * @Description: 逻辑:~
 */
void putFirst(E e) throws InterruptedException;

    void putLast(E e) throws InterruptedException —— 放置最后 —— 向当前阻塞双端队列的尾部插入指定元素。该方法是尾部插入/放置方法“阻塞”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功;否则等待至存在剩余容量为止。

/**
 * Inserts the specified element at the end of this deque, waiting if necessary for space to become available.
 * 在双端队列的尾部插入指定元素,如果必要则等待至空间变的可用。
 *
 * @param e the element to add 新增的元素
 * @throws InterruptedException     if interrupted while waiting
 *                                  中断异常:如果在等待期间中断
 * @throws ClassCastException       if the class of the specified element prevents it from being added to this deque
 *                                  类转换异常:如果指定元素的类妨碍其加入当前双端队列
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException if some property of the specified element prevents it from being added to this deque
 *                                  非法参数异常:如果指定元素的某些属性妨碍其加入双端队列
 * @Description: 名称:放置最后
 * @Description: 作用:向当前阻塞双端队列的尾部插入指定元素。该方法是尾部插入/放置方法“阻塞”形式的实现,当阻塞双端队列
 * @Description: 存在剩余容量时插入/放置成功;否则等待至存在剩余容量为止。
 * @Description: 逻辑:~
 */
void putLast(E e) throws InterruptedException;

    boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException —— 提供首个 —— 向当前阻塞双端队列的头部插入指定元素。该方法是头部插入/放置方法“超时”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功并返回true;否则在指定等待时间内等待至存在剩余容量,超出等待时间则返回false。

/**
 * Inserts the specified element at the front of this deque, waiting up to the specified wait time if necessary for space to become available.
 * 在双端队列的头部插入指定元素,如果必要则等待指定等待时间直至空间变的可用。
 *
 * @param e       the element to add 新增的元素
 * @param timeout how long to wait before giving up, in units of {@code unit} 放弃前等待多少时间
 * @param unit    a {@code TimeUnit} determining how to interpret the {@code timeout} parameter  一个确定如何解释timeout参数的TimeUnit
 * @return {@code true} if successful, or {@code false} if the specified waiting time elapses before space is available
 * 如果成功返回true,或者如果空间可用之前指定等待时间消逝返回false
 * @throws InterruptedException     if interrupted while waiting
 *                                  中断异常:如果在等待期间中断
 * @throws ClassCastException       if the class of the specified element prevents it from being added to this deque
 *                                  类转换异常:如果指定元素的类妨碍其加入当前双端队列
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException if some property of the specified element prevents it from being added to this deque
 *                                  非法参数异常:如果指定元素的某些属性妨碍其加入双端队列
 * @Description: 名称:提供首个
 * @Description: 作用:向当前阻塞双端队列的头部插入指定元素。该方法是头部插入/放置方法“超时”形式的实现,当阻塞双端队列
 * @Description: 存在剩余容量时插入/放置成功并返回true;否则在指定等待时间内等待至存在剩余容量,超出等待时间则返回false。
 * @Description: 逻辑:~
 */
boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException;

    boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException —— 提供最后 —— 向当前阻塞双端队列的尾部插入指定元素。该方法是尾部插入/放置方法“超时”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功并返回true;否则在指定等待时间内等待至存在剩余容量,超出等待时间则返回false。

/**
 * Inserts the specified element at the end of this deque, waiting up to the specified wait time if necessary for space to become available.
 * 在双端队列的尾部插入指定元素,如果必要则等待指定等待时间直至空间变的可用。
 *
 * @param e       the element to add 新增的元素
 * @param timeout how long to wait before giving up, in units of {@code unit} 放弃前等待多少时间
 * @param unit    a {@code TimeUnit} determining how to interpret the {@code timeout} parameter  一个确定如何解释timeout参数的TimeUnit
 * @return {@code true} if successful, or {@code false} if the specified waiting time elapses before space is available
 * 如果成功返回true,或者如果空间可用之前指定等待时间消逝返回false
 * @throws InterruptedException     if interrupted while waiting
 *                                  中断异常:如果在等待期间中断
 * @throws ClassCastException       if the class of the specified element prevents it from being added to this deque
 *                                  类转换异常:如果指定元素的类妨碍其加入当前双端队列
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException if some property of the specified element prevents it from being added to this deque
 *                                  非法参数异常:如果指定元素的某些属性妨碍其加入双端队列
 * @Description: 名称:提供最后
 * @Description: 作用:向当前阻塞双端队列的尾部插入指定元素。该方法是尾部插入/放置方法“超时”形式的实现,当阻塞双端队列
 * @Description: 存在剩余容量时插入/放置成功并返回true;否则在指定等待时间内等待至存在剩余容量,超出等待时间则返回false。
 * @Description: 逻辑:~
 */
boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException;

    E takeFirst() throws InterruptedException —— 拿取首个 —— 从当前阻塞双端队列的头部移除并获取元素。该方法是头部移除/拿取方法中“阻塞”形式的实现,当阻塞双端队列存在元素时移除/拿取并返回头元素;否则等待至存在元素。

/**
 * Retrieves and removes the first element of this deque, waiting if necessary until an element becomes available.
 * 移除并检索当前双端队列的首个元素,如果必要则等待直至一个元素变的可用。
 *
 * @return the head of this deque 双端队列的头
 * @throws InterruptedException if interrupted while waiting
 *                              中断异常:如果在等待期间中断
 * @Description: 名称:拿取首个
 * @Description: 作用:从当前阻塞双端队列的头部移除并获取元素。该方法是头部移除/拿取方法中“阻塞”形式的实现,当阻塞双端队列存
 * @Description: 在元素时移除/拿取并返回头元素;否则等待至存在元素。
 * @Description: 逻辑:~
 */
E takeFirst() throws InterruptedException;

    E takeLast() throws InterruptedException —— 拿取最后 —— 从当前阻塞双端队列的尾部移除并获取元素。该方法是尾部移除/拿取方法中“阻塞”形式的实现,当阻塞双端队列存在元素时移除/拿取并返回尾元素;否则等待至存在元素。

/**
 * Retrieves and removes the last element of this deque, waiting if necessary until an element becomes available.
 * 移除并检索当前双端队列的最后元素,如果必要则等待直至一个元素变的可用。
 *
 * @return the tail of this deque 双端队列的尾
 * @throws InterruptedException if interrupted while waiting
 *                              中断异常:如果在等待期间中断
 * @Description: 名称:拿取最后
 * @Description: 作用:从当前阻塞双端队列的尾部移除并获取元素。该方法是尾部移除/拿取方法中“阻塞”形式的实现,当阻塞双端队列存
 * @Description: 在元素时移除/拿取并返回尾元素;否则等待至存在元素。
 * @Description: 逻辑:~
 */
E takeLast() throws InterruptedException;

    E pollFirst(long timeout, TimeUnit unit) throws InterruptedException —— 轮询首个 —— 从当前阻塞双端队列的头部移除并获取元素。该方法是头部移除/拿取方法中“超时”形式的实现,当阻塞双端队列存在元素时移除/拿取并返回头元素;否则在指定等待时间内等待至存在元素,超出指定等待时间则返回null。

/**
 * Retrieves and removes the first element of this deque, waiting up to the specified wait time if necessary for an element to become available.
 * 移除并检索当前双端队列的首个元素,如果必要则等待指定等待时间直至一个元素变的可用。
 *
 * @param timeout how long to wait before giving up, in units of {@code unit} 放弃前等待多少时间
 * @param unit    a {@code TimeUnit} determining how to interpret the {@code timeout} parameter  一个确定如何解释timeout参数的TimeUnit
 * @return the head of this deque, or {@code null} if the specified waiting time elapses before an element is available
 * 双端队列的头,或者如果在元素可用之前指定等待实现消逝则返回null
 * @throws InterruptedException if interrupted while waiting
 *                              中断异常:如果在等待期间中断
 * @Description: 名称:轮询首个
 * @Description: 作用:从当前阻塞双端队列的头部移除并获取元素。该方法是头部移除/拿取方法中“超时”形式的实现,当阻塞双端队列存在元
 * @Description: 素时移除/拿取并返回头元素;否则在指定等待时间内等待至存在元素,超出指定等待时间则返回null。
 * @Description: 逻辑:~
 */
E pollFirst(long timeout, TimeUnit unit) throws InterruptedException;

    E pollLast(long timeout, TimeUnit unit) throws InterruptedException —— 轮询最后 —— 从当前阻塞双端队列的尾部移除并获取元素。该方法是尾部移除/拿取方法中“超时”形式的实现,当阻塞双端队列存在元素时移除/拿取并返回尾元素;否则在指定等待时间内等待至存在元素,超出指定等待时间则返回null。

/**
 * Retrieves and removes the last element of this deque, waiting up to the specified wait time if necessary for an element to become available.
 * 移除并检索当前双端队列的最后元素,如果必要则等待指定等待时间直至一个元素变的可用。
 *
 * @param timeout how long to wait before giving up, in units of {@code unit} 放弃前等待多少时间
 * @param unit    a {@code TimeUnit} determining how to interpret the {@code timeout} parameter  一个确定如何解释timeout参数的TimeUnit
 * @return the tail of this deque, or {@code null} if the specified waiting time elapses before an element is available
 * 双端队列的尾,或者如果在元素可用之前指定等待实现消逝则返回null
 * @throws InterruptedException if interrupted while waiting
 *                              中断异常:如果在等待期间中断
 * @Description: 名称:轮询最后
 * @Description: 作用:从当前阻塞双端队列的尾部移除并获取元素。该方法是尾部移除/拿取方法中“超时”形式的实现,当阻塞双端队列存在元
 * @Description: 素时移除/拿取并返回尾元素;否则在指定等待时间内等待至存在元素,超出指定等待时间则返回null。
 * @Description: 逻辑:~
 */
E pollLast(long timeout, TimeUnit unit) throws InterruptedException;

    boolean removeFirstOccurrence(Object o) —— 移除首次出现 —— 从当前双端队列中移除指定元素的首个单例,移除成功返回true;否则返回false。

/**
 * Removes the first occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More
 * formally, removes the first element {@code e} such that {@code o.equals(e)} (if such an element exists). Returns {@code true} if this deque
 * contained the specified element (or equivalently, if this deque changed as a result of the call).
 * 从双端队列中移除指定元素的首次出现「的对象」。如果双端队列不包含元素,它是未改变的。更正式的,通过o.equals(e)}以移除首个
 * 元素(如果如此元素存在)。如果当前双端队列包含指定元素(或等效地,如果调用的结果是当前双端队列发生改变)则返回true。
 *
 * @param o element to be removed from this deque, if present 元素用于从当前双端队列中移除,如果存在
 * @return {@code true} if an element was removed as a result of this call 如果调用的结果是元素从队列中移除
 * @throws ClassCastException   if the class of the specified element is incompatible with this deque
 *                              (<a href="../Collection.html#optional-restrictions">optional</a>)
 *                              类转换异常:如果指定元素的类与当前双端队列不合适
 * @throws NullPointerException if the specified element is null
 *                              (<a href="../Collection.html#optional-restrictions">optional</a>)
 *                              空指针异常:如果指定元素为null
 * @Description: 名称:移除首次出现
 * @Description: 作用:从当前双端队列中移除指定元素的首个单例,移除成功返回true;否则返回false。
 * @Description: 逻辑:~
 */
boolean removeFirstOccurrence(Object o);

    boolean removeLastOccurrence(Object o) —— 移除最后出现 —— 从当前双端队列中移除指定元素的最后单例,移除成功返回true;否则返回false。

/**
 * Removes the last occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More
 * formally, removes the last element {@code e} such that {@code o.equals(e)} (if such an element exists). Returns {@code true} if this deque
 * contained the specified element (or equivalently, if this deque changed as a result of the call).
 * 从双端队列中移除指定元素的最后出现「的对象」。如果双端队列不包含元素,它是未改变的。更正式的,通过o.equals(e)}以移除最后
 * 元素(如果如此元素存在)。如果当前双端队列包含指定元素(或等效地,如果调用的结果是当前双端队列发生改变)则返回true。
 *
 * @param o element to be removed from this deque, if present 元素用于从当前双端队列中移除,如果存在
 * @return {@code true} if an element was removed as a result of this call 如果调用的结果是元素从队列中移除
 * @throws ClassCastException   if the class of the specified element is incompatible with this deque
 *                              (<a href="../Collection.html#optional-restrictions">optional</a>)
 *                              类转换异常:如果指定元素的类与当前双端队列不合适
 * @throws NullPointerException if the specified element is null
 *                              (<a href="../Collection.html#optional-restrictions">optional</a>)
 *                              空指针异常:如果指定元素为null
 * @Description: 名称:移除最后出现
 * @Description: 作用:从当前双端队列中移除指定元素的最后单例,移除成功返回true;否则返回false。
 * @Description: 逻辑:~
 */
boolean removeLastOccurrence(Object o);

    boolean add(E e) —— 新增 —— 向当前阻塞双端队列的尾部插入指定元素。该方法是插入/放置方法“异常”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功并返回true;否则抛出非法状态异常。该方法等价于addLast(E e)方法。

/**
 * Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so
 * immediately without violating capacity restrictions, returning {@code true} upon success and throwing an {@code IllegalStateException}
 * if no space is currently available. When using a capacity-restricted deque, it is generally preferable to use {@link #offer(Object) offer}.
 * 如果可以立即做到不违反容量限制插入指定元素至当前双端队列代表的队列(换句话说,在当前双端队列的尾部),在成功之后返回true,
 * 以及如果当前空间不可用则抛出非法状态异常。当使用一个容量受限的双端队列时,通常使用offer(E e)方法更好。
 * <p>
 * This method is equivalent to {@link #addLast(Object) addLast}.
 * 当前方法等价于addLast(E e)方法
 *
 * @param e the element to add 用于新增的元素
 * @throws IllegalStateException    {@inheritDoc} 非法状态异常
 * @throws ClassCastException       if the class of the specified element prevents it from being added to this deque
 *                                  类型转换异常:如果指定类型的类方法其加入当前双端队列
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException if some property of the specified element prevents it from being added to this deque
 *                                  非法参数异常:如果指定元素的某些元素妨碍其加入当前双端队列
 * @Description: 名称:新增
 * @Description: 作用:向当前阻塞双端队列的尾部插入指定元素。该方法是插入/放置方法“异常”形式的实现,当阻塞双端队列存在剩余
 * @Description: 容量时插入/放置成功并返回true;否则抛出非法状态异常。该方法等价于addLast(E e)方法。
 * @Description: 逻辑:~
 */
boolean add(E e);

    boolean offer(E e) —— 提供 —— 向当前阻塞双端队列的尾部插入指定元素。该方法是插入/放置方法“特殊值”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功并返回true;否则返回false。该方法等价于offerLast(E e)方法。

/**
 * Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do
 * so immediately without violating capacity restrictions, returning {@code true} upon success and {@code false} if no space is currently
 * available.  When using a capacity-restricted deque, this method is generally preferable to the {@link #add} method, which can fail to
 * insert an element only by throwing an exception.
 * 如果可以立即做到不违反容量限制插入指定元素至当前双端队列代表的队列(换句话说,在当前双端队列的尾部),在成功之后返回
 * true,以及如果当前空间不可用则返回false。当使用一个容量受限的双端队列时,当前方法通常比add(E e)方法更好,其在插入元素
 * 失败时只能抛出异常。
 * <p>
 * This method is equivalent to {@link #offerLast(Object) offerLast}.
 * 当前方法等价于offerLast(E e)方法
 *
 * @param e the element to add 用于新增的元素
 * @throws ClassCastException       if the class of the specified element prevents it from being added to this deque
 *                                  类型转换异常:如果指定类型的类方法其加入当前双端队列
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException if some property of the specified element prevents it from being added to this deque
 *                                  非法参数异常:如果指定元素的某些元素妨碍其加入当前双端队列
 * @Description: 名称:提供
 * @Description: 作用:向当前阻塞双端队列的尾部插入指定元素。该方法是插入/放置方法“特殊值”形式的实现,当阻塞双端队列存在
 * @Description: 剩余容量时插入/放置成功并返回true;否则返回false。该方法等价于offerLast(E e)方法。
 * @Description: 逻辑:~
 */
boolean offer(E e);

    void put(E e) throws InterruptedException —— 放置 —— 向当前阻塞双端队列的尾部插入指定元素。该方法是插入/放置方法“阻塞”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功;否则等待至存在剩余容量为止。该方法等价于putLast(E e)方法。

/**
 * Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque), waiting if necessary
 * for space to become available.
 * 插入指定元素至当前双端队列代表的队列(换句话说,在当前双端队列的尾部),如果必要等待至空间变的可用。
 * <p>
 * This method is equivalent to {@link #putLast(Object) putLast}.
 * 当前方法等价于putLast(E e)方法。
 *
 * @param e the element to add 用于新增的元素
 * @throws InterruptedException     {@inheritDoc} 中断异常
 * @throws ClassCastException       if the class of the specified element prevents it from being added to this deque
 *                                  类型转换异常:如果指定类型的类方法其加入当前双端队列
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException if some property of the specified element prevents it from being added to this deque
 *                                  非法参数异常:如果指定元素的某些元素妨碍其加入当前双端队列
 * @Description: 名称:放置
 * @Description: 作用:向当前阻塞双端队列的尾部插入指定元素。该方法是插入/放置方法“阻塞”形式的实现,当阻塞双端队列存在剩
 * @Description: 余容量时插入/放置成功;否则等待至存在剩余容量为止。该方法等价于putLast(E e)方法。
 * @Description: 逻辑:~
 */
void put(E e) throws InterruptedException;

    boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException —— 提供 —— 向当前阻塞双端队列的尾部插入指定元素。该方法是插入/放置方法“超时”形式的实现,当阻塞双端队列存在剩余容量时插入/放置成功并返回true;否则在指定等待时间内等待至存在剩余容量,超出指定等待时间则返回false。该方法等价于offerLast(E e, long timeout, TimeUnit unit)方法。

/**
 * Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque), waiting up to the
 * specified wait time if necessary for space to become available.
 * 插入指定元素至当前双端队列代表的队列(换句话说,在当前双端队列的尾部),如果必要等待指定等待时间至空间变的可用。
 * <p>
 * This method is equivalent to {@link #offerLast(Object, long, TimeUnit) offerLast}.
 * 当前方法等价于offerLast(E e, long timeout, TimeUnit unit)方法。
 *
 * @param e the element to add 用于新增的元素
 * @return {@code true} if the element was added to this deque, else {@code false}
 * 如果元素新增至当前双端队列则返回true;否则返回false
 * @throws InterruptedException     {@inheritDoc} 中断异常
 * @throws ClassCastException       if the class of the specified element prevents it from being added to this deque
 *                                  类型转换异常:如果指定类型的类方法其加入当前双端队列
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException if some property of the specified element prevents it from being added to this deque
 *                                  非法参数异常:如果指定元素的某些元素妨碍其加入当前双端队列
 * @Description: 名称:提供
 * @Description: 作用:向当前阻塞双端队列的尾部插入指定元素。该方法是插入/放置方法“超时”形式的实现,当阻塞双端队列存在剩
 * @Description: 余容量时插入/放置成功并返回true;否则在指定等待时间内等待至存在剩余容量,超出指定等待时间则返回false。该
 * @Description: 方法等价于offerLast(E e, long timeout, TimeUnit unit)方法。
 * @Description: 逻辑:~
 */
boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException;

    E remove() —— 移除 —— 从当前阻塞双端队列的头部移除并获取元素。该方法是移除/拿取方法中“异常”形式的实现,当阻塞双端队列存在元素时移除/拿取并返回头元素;否则抛出无如此元素异常。该方法等价于removeFirst()方法。

/**
 * Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque). This method
 * differs from {@link #poll poll} only in that it throws an exception if this deque is empty.
 * 检索并移除当前双端队列代表的队列的头元素(话句话说,即当前双端队列的头元素)。当前方法不同于poll()方法,如果当前双端队
 * 列为空只能抛出一个异常。
 * <p>
 * This method is equivalent to {@link #removeFirst() removeFirst}.
 * 当前方法等价于removeFirst()方法。
 *
 * @return the head of the queue represented by this deque 当前双端队列代表的队列的头元素
 * @throws NoSuchElementException if this deque is empty
 *                                无如此元素异常:如果当前双端队列为空
 * @Description: 名称:移除
 * @Description: 作用:从当前阻塞双端队列的头部移除并获取元素。该方法是移除/拿取方法中“异常”形式的实现,当阻塞双端队列存
 * @Description: 在元素时移除/拿取并返回头元素;否则抛出无如此元素异常。该方法等价于removeFirst()方法。
 * @Description: 逻辑:~
 */
E remove();

    E poll() —— 轮询 —— 从当前阻塞双端队列的头部移除并获取元素。该方法是移除/拿取方法中“特殊值”形式的实现,当阻塞双端队列存在元素时移除/拿取并返回头元素;否则返回null。该方法等价于pollFirst()方法。

/**
 * Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), or returns
 * {@code null} if this deque is empty.
 * 检索并移除当前双端队列代表的队列的头元素(话句话说,即当前双端队列的头元素),或者如果当前双端队列为空则返回null。
 * <p>
 * This method is equivalent to {@link #pollFirst()}.
 * 当前方法等价于pollFirst()方法。
 *
 * @return the head of this deque, or {@code null} if this deque is empty 当前双端队列的头元素,或者如果当前双端队列为空则返回null
 * @Description: 名称:轮询
 * @Description: 作用:从当前阻塞双端队列的头部移除并获取元素。该方法是移除/拿取方法中“特殊值”形式的实现,当阻塞双端队列存在
 * @Description: 元素时移除/拿取并返回头元素;否则返回null。该方法等价于pollFirst()方法。
 * @Description: 逻辑:~
 */
E poll();

    E take() throws InterruptedException —— 拿取 —— 从当前阻塞双端队列的头部移除并获取元素。该方法是移除/拿取方法中“阻塞”形式的实现,当阻塞双端队列存在元素时移除/拿取并返回头元素;否则等待至存在元素。该方法等价于pollFirst()方法。

/**
 * Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), waiting if
 * necessary until an element becomes available.
 * 检索并移除当前双端队列代表的队列的头元素(话句话说,即当前双端队列的头元素),如果必要则等待至元素变的可用。
 * <p>
 * This method is equivalent to {@link #takeFirst() takeFirst}.
 * 当前方法等价于takeFirst()方法
 *
 * @return the head of this deque 当前双端队列的头元素
 * @throws InterruptedException if interrupted while waiting
 *                              中断异常:如果在等待期间被中断
 * @Description: 名称:拿取
 * @Description: 作用:从当前阻塞双端队列的头部移除并获取元素。该方法是移除/拿取方法中“阻塞”形式的实现,当阻塞双端队列存
 * @Description: 在元素时移除/拿取并返回头元素;否则等待至存在元素。该方法等价于pollFirst()方法。
 * @Description: 逻辑:~
 */
E take() throws InterruptedException;

    E poll(long timeout, TimeUnit unit) throws InterruptedException —— 轮询 —— 从当前阻塞双端队列的头部移除并获取元素。该方法是移除/拿取方法中“超时”形式的实现,当阻塞双端队列存在元素时移除/拿取并返回头元素;否则在指定等待时间内等待至存在元素,超出指定等待时间则返回null。该方法等价于pollFirst()方法。

/**
 * Retrieves and removes the head of the queue represented by this deque (in other words, the first element of this deque), waiting up
 * to the specified wait time if necessary for an element to become available.
 * 检索并移除当前双端队列代表的队列的头元素(话句话说,即当前双端队列的头元素),如果必要则等待指定等待时间至元素变的可
 * 用。
 * <p>
 * This method is equivalent to {@link #pollFirst(long, TimeUnit) pollFirst}.
 * 当前方法等价于pollFirst(long timeout, TimeUnit unit)方法。
 *
 * @return the head of this deque, or {@code null} if the specified waiting time elapses before an element is available
 * 当前双端队列的头元素,或者如果在元素可用之前指定等待时间消逝则返回null
 * @throws InterruptedException if interrupted while waiting
 *                              中断异常:如果在等待期间被中断
 * @Description: 名称:轮询
 * @Description: 作用:从当前阻塞双端队列的头部移除并获取元素。该方法是移除/拿取方法中“超时”形式的实现,当阻塞双端队列存
 * @Description: 在元素时移除/拿取并返回头元素;否则在指定等待时间内等待至存在元素,超出指定等待时间则返回null。该方法等
 * @Description: 价于pollFirst()方法。
 * @Description: 逻辑:~
 */
E poll(long timeout, TimeUnit unit) throws InterruptedException;

    E element() —— 元素 —— 从当前阻塞双端队列的头部获取元素。该方法是检查方法中“异常”形式的实现,当阻塞双端队列存在元素时返回头元素;否则抛出无如此元素异常。该方法等价于getFirst()方法。

/**
 * Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque). This
 * method differs from {@link #peek peek} only in that it throws an exception if this deque is empty.
 * 检索,但不移除当前双端队列代表的队列的头元素(换句话说,即当前双端队列的头元素)。当前方法不同于peek()方法,如果当前双
 * 端队列为空其只能抛出一个异常。
 * <p>
 * This method is equivalent to {@link #getFirst() getFirst}.
 * 当前方法等价于getFirst()方法。
 *
 * @return the head of this deque 当前队列的头
 * @throws NoSuchElementException if this deque is empty
 *                                无如此元素异常:如果当前双端队列为空
 * @Description: 名称:元素
 * @Description: 作用:从当前阻塞双端队列的头部获取元素。该方法是检查方法中“异常”形式的实现,当阻塞双端队列存在元素时返回头
 * @Description: 元素;否则抛出无如此元素异常。该方法等价于getFirst()方法。
 * @Description: 逻辑:~
 */
E element();

    E peek() —— 窥视 —— 从当前阻塞双端队列的头部获取元素。该方法是检查方法中“特殊值”形式的实现,当阻塞双端队列存在元素时返回头元素;否则返回null。该方法等价于getFirst()方法。

/**
 * Retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque), or
 * returns {@code null} if this deque is empty.
 * 检索,但不移除当前双端队列代表的队列的头元素(换句话说,即当前双端队列的头元素),或者如果当前双端队列为空则返回null。
 * <p>
 * This method is equivalent to {@link #peekFirst() peekFirst}.
 * 当前方法等价于peekFirst()方法。
 *
 * @return the head of this deque, or {@code null} if this deque is empty 当前双端队列的头元素,或者如果当前双端队列为空则返回null
 * @Description: 名称:窥视
 * @Description: 作用:从当前阻塞双端队列的头部获取元素。该方法是检查方法中“特殊值”形式的实现,当阻塞双端队列存在元素时返回头元
 * @Description: 素;否则返回null。该方法等价于getFirst()方法。
 * @Description: 逻辑:~
 */
E peek();

    boolean remove(Object o) —— 移除 —— 从当前阻塞双端队列中移除指定元素的首个单例,移除成功则返回true;否则返回false。该方法等价于removeFirstOccurrence(Object o)方法。

/**
 * Removes the first occurrence of the specified element from this deque. If the deque does not contain the element, it is unchanged. More
 * formally, removes the first element {@code e} such that {@code o.equals(e)} (if such an element exists). Returns {@code true} if this deque
 * contained the specified element (or equivalently, if this deque changed as a result of the call).
 * 从当前双端队列中移除指定元素的首次出现。如果双端队列不包含该元素,它是为未改变的。更正式地,通过o.equals(e)以致移除首个元
 * 素(如果这样的元素存在)。如果当前双端队列包含指定元素则返回true(或等价地,如果调用的结果是当前双端队列发生改变)。
 * <p>
 * This method is equivalent to {@link #removeFirstOccurrence(Object) removeFirstOccurrence}.
 * 当前方法等价于removeFirstOccurrence(Object o)方法。
 *
 * @param o element to be removed from this deque, if present 用于从当前双端队列中移除的元素,如果存在
 * @return {@code true} if this deque changed as a result of the call 如果调用的结果是当前双端队列发生改变则返回true
 * @throws ClassCastException   if the class of the specified element is incompatible with this deque
 *                              (<a href="../Collection.html#optional-restrictions">optional</a>)
 *                              类转换异常:如果指定元素的类与当前双端队列不合适
 * @throws NullPointerException if the specified element is null
 *                              (<a href="../Collection.html#optional-restrictions">optional</a>)
 *                              空指针异常:如果之地昂元素为null
 * @Description: 名称:移除
 * @Description: 作用:从当前阻塞双端队列中移除指定元素的首个单例,移除成功则返回true;否则返回false。该方法等价于
 * @Description: removeFirstOccurrence(Object o)方法。
 * @Description: 逻辑:~
 */
boolean remove(Object o);

    public boolean contains(Object o) —— 包含 —— 判断当前阻塞双端队列中是否包含指定元素,是则返回true;否则返回false。

/**
 * Returns {@code true} if this deque contains the specified element. More formally, returns {@code true} if and only if this deque contains
 * at least one element {@code e} such that {@code o.equals(e)}.
 * 如果当前双端队列包含指定元素则返回true。更正式地,当且仅当当前双端队列通过o.equals(e)判断当前栓导管队列至少包含一个元素
 * 则返回true。
 *
 * @param o object to be checked for containment in this deque 用于在当前双端队列中检查包含的对象
 * @throws ClassCastException   if the class of the specified element is incompatible with this deque
 *                              (<a href="../Collection.html#optional-restrictions">optional</a>)
 *                              类转换异常:如果指定元素的类与当前双端队列不合适
 * @throws NullPointerException if the specified element is null
 *                              (<a href="../Collection.html#optional-restrictions">optional</a>)
 *                              空指针异常:如果之地昂元素为null
 * @Description: 名称:包含
 * @Description: 作用:判断当前阻塞双端队列中是否包含指定元素,是则返回true;否则返回false。
 * @Description: 逻辑:~
 */
public boolean contains(Object o);

    public int size() —— 大小 —— 获取当前双端队列中的元素总数。

/**
 * Returns the number of elements in this deque.
 * 返回当前双端队列中的元素数量。
 *
 * @return the number of elements in this deque 当前双端队列中的元素数量
 * @Description: 名称:大小
 * @Description: 作用:获取当前双端队列中的元素总数。
 * @Description: 逻辑:~
 */
public int size();

    Iterator iterator() —— 迭代器 —— 获取当前双端队列的迭代器。

/**
 * Returns an iterator over the elements in this deque in proper sequence. The elements will be returned in order from first (head) to last (tail).
 * 返回一个按合适顺序遍历当前双端队列中元素的迭代器。元素将按从头到尾的顺序返回。
 *
 * @return an iterator over the elements in this deque in proper sequence 一个按合适顺序遍历当前双端队列中元素的迭代器
 * @Description: 名称:迭代器
 * @Description: 作用:获取当前双端队列的迭代器。
 * @Description: 逻辑:~
 */
Iterator<E> iterator();

    void push(E e) —— 推送 —— 向当前阻塞双端队列的头部插入指定元素,如果没有剩余空间则抛出非法状态异常。该方法在定义上等价于addFirst(E e)方法。

/**
 * Pushes an element onto the stack represented by this deque (in other words, at the head of this deque) if it is possible to do so immediately
 * without violating capacity restrictions, throwing an {@code IllegalStateException} if no space is currently available.
 * 如果可以不违背容量限制立即做到推送一个元素至当前双端队列所表示的堆栈(换句话说,在当前双端队列的头),如果当前没有空间可用
 * 则抛出非法状态异常。
 * <p>
 * This method is equivalent to {@link #addFirst(Object) addFirst}.
 * 当前方法等价于addFirst(E e) 方法
 *
 * @throws IllegalStateException    {@inheritDoc} 非法状态异常
 * @throws ClassCastException       {@inheritDoc} 类转换异常
 * @throws NullPointerException     if the specified element is null
 *                                  空指针异常:如果指定元素为null
 * @throws IllegalArgumentException {@inheritDoc} 非法参数异常
 * @Description: 名称:推送
 * @Description: 作用:向当前阻塞双端队列的头部插入指定元素,如果没有剩余空间则抛出非法状态异常。该方法在定义上等价于addFirst(E e)
 * @Description: 方法。
 * @Description: 逻辑:~
 */
void push(E e);

二 相关系列


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

说淑人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值