Deque接口源码解析

Deque

双向队列

队头:可以插入可以删除

队尾:可以插入可以删除

继承Queue接口

源码如下:



package java.util;

public interface Deque<E> extends Queue<E> {
    /**
     * 队头插入元素
     *
     * @throws 队列满了添加元素,抛出:IllegalStateException
     * @throws 类型不兼容,抛出:ClassCastException
     * @throws null队列不允许null,抛出:NullPointerException
     * @throws 其他操作限制了插入元素,抛出:IllegalArgumentException
     */
    void addFirst(E e);

    /**
     * 队列尾部插入元素
     *
     * @param e the element to add
     * @throws IllegalStateException if the element cannot be added at this
     *         time due to capacity restrictions
     * @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 and this
     *         deque does not permit null elements
     * @throws IllegalArgumentException if some property of the specified
     *         element prevents it from being added to this deque
     */
    void addLast(E e);

    /**
     * 队列头部插入元素
     *
     * @param e the element to add
     * @return <tt>true</tt> if the element was added to this deque, else
     *         <tt>false</tt>
     * @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 and this
     *         deque does not permit null elements
     * @throws IllegalArgumentException if some property of the specified
     *         element prevents it from being added to this deque
     */
    boolean offerFirst(E e);

    /**
     * 队列尾部插入元素
     *
     * @param e the element to add
     * @return <tt>true</tt> if the element was added to this deque, else
     *         <tt>false</tt>
     * @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 and this
     *         deque does not permit null elements
     * @throws IllegalArgumentException if some property of the specified
     *         element prevents it from being added to this deque
     */
    boolean offerLast(E e);

    /**
     * 队列头部删除元素
     *
     * @return the head of this deque
     * @throws NoSuchElementException if this deque is empty
     */
    E removeFirst();

    /**
     * 队列尾部插入元素
     *
     * @return the tail of this deque
     * @throws null时候,抛出:NoSuchElementException
     */
    E removeLast();

    /**
     * 获取队头元素,并删除该元素
     *
     * @return the head of this deque, or <tt>null</tt> if this deque is empty
     */
    E pollFirst();

    /**
     * 获取队尾元素,并删除该元素
     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
     */
    E pollLast();

    /**
     * 查看队头元素
     *
     * @return the head of this deque
     * @throws NoSuchElementException if this deque is empty
     */
    E getFirst();

    /**
     * 查看队尾元素
     *
     * @return the tail of this deque
     * @throws NoSuchElementException if this deque is empty
     */
    E getLast();

    /**
     * 查看队头元素
     *
     * @return the head of this deque, or <tt>null</tt> if this deque is empty
     */
    E peekFirst();

    /**
     *查看队尾元素
     *
     * @return the tail of this deque, or <tt>null</tt> if this deque is empty
     */
    E peekLast();

    /**
     * 删除第一个当前元素
     * @param o element to be removed from this deque, if present
     * @return <tt>true</tt> 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
     * @throws NullPointerException if the specified element is null and this
     *         deque does not permit null elements
     */
    boolean removeFirstOccurrence(Object o);

    /**
     * 删除最后一个当前元素
     * @param o element to be removed from this deque, if present
     * @return <tt>true</tt> 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
     * @throws NullPointerException if the specified element is null and this
     *         deque does not permit null elements
     */
    boolean removeLastOccurrence(Object o);

    // *** Queue methods 队列的方法***

    /**
     * 队尾加入元素
     *
     * @param e the element to add
     * @return <tt>true</tt> (as specified by {@link Collection#add})
     * @throws IllegalStateException if the element cannot be added at this
     *         time due to capacity restrictions
     * @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 and this
     *         deque does not permit null elements
     * @throws IllegalArgumentException if some property of the specified
     *         element prevents it from being added to this deque
     */
    boolean add(E e);

    /**
     * 队尾加入元素
     *
     * <p>This method is equivalent to {@link #offerLast}.
     *
     * @param e the element to add
     * @return <tt>true</tt> if the element was added to this deque, else
     *         <tt>false</tt>
     * @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 and this
     *         deque does not permit null elements
     * @throws IllegalArgumentException if some property of the specified
     *         element prevents it from being added to this deque
     */
    boolean offer(E e);

    /**
     * 获取队头元素,并删除该元素
     *
     * @return the head of the queue represented by this deque
     * @throws NoSuchElementException if this deque is empty
     */
    E remove();

    /**
     * 获取队头元素,并删除该元素
     *
     * @return the first element of this deque, or <tt>null</tt> if
     *         this deque is empty
     */
    E poll();

    /**
     * 查看队头元素
     *
     * @return the head of the queue represented by this deque
     * @throws NoSuchElementException if this deque is empty
     */
    E element();

    /**
     * 查看队头元素
     *
     * @return the head of the queue represented by this deque, or
     *         <tt>null</tt> if this deque is empty
     */
    E peek();

    // *** Stack methods 栈方法 ***

    /**
     * 入栈
     *
     * @param e the element to push
     * @throws IllegalStateException if the element cannot be added at this
     *         time due to capacity restrictions
     * @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 and this
     *         deque does not permit null elements
     * @throws IllegalArgumentException if some property of the specified
     *         element prevents it from being added to this deque
     */
    void push(E e);

    /**
     * 出栈
     *
     * @return the element at the front of this deque (which is the top
     *         of the stack represented by this deque)
     * @throws NoSuchElementException if this deque is empty
     */
    E pop();

    // *** Collection methods 集合方法 ***

    /**
     * 删除第一个元素
     * @param o element to be removed from this deque, if present
     * @return <tt>true</tt> 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
     * @throws NullPointerException if the specified element is null and this
     *         deque does not permit null elements
     */
    boolean remove(Object o);

    /**
     * 是否包含元素 o
     * @param o element whose presence in this deque is to be tested
     * @return <tt>true</tt> if this deque contains the specified element
     * @throws ClassCastException if the type of the specified element
     *         is incompatible with this deque
     * @throws NullPointerException if the specified element is null and this
     *         deque does not permit null elements
     */
    boolean contains(Object o);

    /**
     * 队列包含元素数量
     * @return the number of elements in this deque
     */
    public int size();

    /**
     * 获取迭代器
     * @return an iterator over the elements in this deque in proper sequence
     */
    Iterator<E> iterator();

    /**
     * 获取逆向的迭代器:尾->头迭代
     *
     * @return an iterator over the elements in this deque in reverse
     * sequence
     */
    Iterator<E> descendingIterator();

}
时间: 2024-10-24 00:56:37

Deque接口源码解析的相关文章

SortedSet接口源码解析

SortedSet接口为TreeSet做准备 可以实现排序集合 源码 package java.util; public interface SortedSet<E> extends Set<E> { /** * 比较器 */ Comparator<? super E> comparator(); /** * 获取子集 * @throws ClassCastException if <tt>fromElement</tt> and * <t

Set接口源码解析

Set 无须集合 元素不可以重复 接口内源码和上面其他接口很类似 package java.util; public interface Set<E> extends Collection<E> { int size(); boolean isEmpty(); boolean contains(Object o); Iterator<E> iterator(); Object[] toArray(); <T> T[] toArray(T[] a); bool

Queue接口源码解析

队列 先进先出 入队列:offer 出队列:poll 队头元素:peek 继承:Collection抽象类 源码如下: package java.util; public interface Queue<E> extends Collection<E> { /** * 队列插入元素 * * @param e the element to add * @return <tt>true</tt> (as specified by {@link Collectio

Map接口源码解析

Map 每个数据项是key-value数据对 key不能重复 接口内代码比较少,都是基本操作 package java.util; public interface Map<K,V> { // Query Operations int size(); boolean isEmpty(); boolean containsKey(Object key); boolean containsValue(Object value); V get(Object key); // Modification

ceph RGW接口源码解析--Rados数据操作

RGW业务处理流程: http reqest --> apache 转 FastCgi module FastCgi module --> radosgw  通过socket请求实现(未确定是否有其它方式) radosgw --> ceph集群  通过socket实现,调用rados接口 1.数据结构 在Rgw_common.h定义了基本的数据结构,并实现了 decode.encode序列化,方便对rados访问 //桶的权限创建资料 struct RGWBucketInfo  {  r

SortedMap接口源码解析

TreeMap的父接口 package java.util; public interface SortedMap<K,V> extends Map<K,V> { Comparator<? super K> comparator(); SortedMap<K,V> subMap(K fromKey, K toKey); SortedMap<K,V> headMap(K toKey); SortedMap<K,V> tailMap(K

Spring-cloud &amp; Netflix 源码解析:Eureka 服务注册发现接口 ****

http://www.idouba.net/spring-cloud-source-eureka-client-api/?utm_source=tuicool&utm_medium=referral *************************** 先关注下netflix eureka server 原生提供的接口.https://github.com/Netflix/eureka/wiki/Eureka-REST-operations 这是对非java的服务使用eureka时可以使用的r

IdentityServer4源码解析_4_令牌发放接口

目录 identityserver4源码解析_1_项目结构 identityserver4源码解析_2_元数据接口 identityserver4源码解析_3_认证接口 identityserver4源码解析_4_令牌发放接口 identityserver4源码解析_5_查询用户信息接口 identityserver4源码解析_6_结束会话接口 identityserver4源码解析_7_查询令牌信息接口 identityserver4源码解析_8_撤销令牌接口 协议 Token接口 oidc服

IdentityServer4源码解析_5_查询用户信息接口

目录 IdentityServer4源码解析_1_项目结构 IdentityServer4源码解析_2_元数据接口 IdentityServer4源码解析_3_认证接口 IdentityServer4源码解析_4_令牌发放接口 IdentityServer4源码解析_5_查询用户信息接口 [IdentityServer4源码解析_6_结束会话接口] [IdentityServer4源码解析_7_查询令牌信息接口] [IdentityServer4源码解析_8_撤销令牌接口] 协议简析 UserI