Deque接口源码解析
2016-07-16 09:15
309 查看
Deque
双向队列
队头:可以插入可以删除
队尾:可以插入可以删除
继承Queue接口
源码如下:
双向队列
队头:可以插入可以删除
队尾:可以插入可以删除
继承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(); }
相关文章推荐
- 解决“Dynamic Web Module 3.0 requires Java 1.6 or newer.”错误
- codeforces 360 E - The Values You Can Make
- Buildroot-2012.08交叉编译器制作
- Queue接口源码解析
- android studio中requestWindowFeature(Window.FEATURE_NO_TITLE)隐藏标题栏失效的解决方案
- iOS开发之UITextField 左侧设置小图标 leftview
- 62. Unique Paths
- MySQL提示:The server quit without updating PID file(…)失败
- Callable与Futrue创建线程
- EasyUI基础知识
- PyQt5 pyuic
- EasyUI基础知识
- EasyUI基础知识
- Longest Consecutive Sequence
- Intuit Quicken Home & Business 2016(Manage your business and personal finances)
- ${pageContext.request.contextPath} 表达式的分析及作用
- [leetcode] 374. Guess Number Higher or Lower 解题报告
- 隐藏uuid1的mac信息
- 实战 Android中的UI过度绘制
- Codeforces Round #327 (Div. 1) B. Chip 'n Dale Rescue Rangers 二分