在Java Collection Framework中,继承了Collection接口的主要有List,Queue,Set三大类接口。在上篇文章中,已经对List接口下的源码做了分析,本篇文章开始对Queue接口以及主要的实现类进行分析学习:
按照国际惯例,先看类简介,站得高才能看的远,居高临下,用一栏全局的视野来对Queue有一个大致的认识,对该类的学习会有很大的帮助。
来,翠花,上酸菜!
/*
* Written by Doug Lea with assistance from members of JCP JSR-166
* Expert Group and released to the public domain, as explained at
* http://creativecommons.org/publicdomain/zero/1.0/
*/
package java.util;
/**
* queue 涵盖了 Collection 的基本操作,并且额外提供了增加/获取/检查操作。这些方法都存在两种形式:当失败时抛出异常,或者返回特定的值null/false。
* 后一种主要在容量受限时使用,在大多数实现中,插入操作不会出错。
* A collection designed for holding elements prior to processing.
* Besides basic {@link java.util.Collection Collection} operations,
* queues provide additional insertion, extraction, and inspection
* operations. Each of these methods exists in two forms: one throws
* an exception if the operation fails, the other returns a special
* value (either {@code null} or {@code false}, depending on the
* operation). The latter form of the insert operation is designed
* specifically for use with capacity-restricted {@code Queue}
* implementations; in most implementations, insert operations cannot
* fail.
*
* <table BORDER CELLPADDING=3 CELLSPACING=1>
* <caption>Summary of Queue methods</caption>
* <tr>
* <td></td>
* <td ALIGN=CENTER><em>Throws exception</em></td>
* <td ALIGN=CENTER><em>Returns special value</em></td>
* </tr>
* <tr>
* <td><b>Insert</b></td>
* <td>{@link Queue#add add(e)}</td>
* <td>{@link Queue#offer offer(e)}</td>
* </tr>
* <tr>
* <td><b>Remove</b></td>
* <td>{@link Queue#remove remove()}</td>
* <td>{@link Queue#poll poll()}</td>
* </tr>
* <tr>
* <td><b>Examine</b></td>
* <td>{@link Queue#element element()}</td>
* <td>{@link Queue#peek peek()}</td>
* <