SortedSet接口源码解析

来源:互联网 发布:域名证书是什么作用 编辑:程序博客网 时间:2024/05/19 06:36

SortedSet接口为TreeSet做准备
可以实现排序集合
源码

package java.util;public interface SortedSet<E> extends Set<E> {    /**     * 比较器     */    Comparator<? super E> comparator();    /**     * 获取子集     * @throws ClassCastException if <tt>fromElement</tt> and     *         <tt>toElement</tt> cannot be compared to one another using this     *         set's comparator (or, if the set has no comparator, using     *         natural ordering).  Implementations may, but are not required     *         to, throw this exception if <tt>fromElement</tt> or     *         <tt>toElement</tt> cannot be compared to elements currently in     *         the set.     * @throws NullPointerException if <tt>fromElement</tt> or     *         <tt>toElement</tt> is null and this set does not permit null     *         elements     * @throws IllegalArgumentException if <tt>fromElement</tt> is     *         greater than <tt>toElement</tt>; or if this set itself     *         has a restricted range, and <tt>fromElement</tt> or     *         <tt>toElement</tt> lies outside the bounds of the range     */    SortedSet<E> subSet(E fromElement, E toElement);    /**     * 获取严格小于toElement的子集     *     * @param toElement high endpoint (exclusive) of the returned set     * @return a view of the portion of this set whose elements are strictly     *         less than <tt>toElement</tt>     * @throws ClassCastException if <tt>toElement</tt> is not compatible     *         with this set's comparator (or, if the set has no comparator,     *         if <tt>toElement</tt> does not implement {@link Comparable}).     *         Implementations may, but are not required to, throw this     *         exception if <tt>toElement</tt> cannot be compared to elements     *         currently in the set.     * @throws NullPointerException if <tt>toElement</tt> is null and     *         this set does not permit null elements     * @throws IllegalArgumentException if this set itself has a     *         restricted range, and <tt>toElement</tt> lies outside the     *         bounds of the range     */    SortedSet<E> headSet(E toElement);    /**     * 获取大于等于fromElement的子集      *     * @param fromElement low endpoint (inclusive) of the returned set     * @return a view of the portion of this set whose elements are greater     *         than or equal to <tt>fromElement</tt>     * @throws ClassCastException if <tt>fromElement</tt> is not compatible     *         with this set's comparator (or, if the set has no comparator,     *         if <tt>fromElement</tt> does not implement {@link Comparable}).     *         Implementations may, but are not required to, throw this     *         exception if <tt>fromElement</tt> cannot be compared to elements     *         currently in the set.     * @throws NullPointerException if <tt>fromElement</tt> is null     *         and this set does not permit null elements     * @throws IllegalArgumentException if this set itself has a     *         restricted range, and <tt>fromElement</tt> lies outside the     *         bounds of the range     */    SortedSet<E> tailSet(E fromElement);    /**     * 第一个元素      *     * @return the first (lowest) element currently in this set     * @throws NoSuchElementException if this set is empty     */    E first();    /**     * 最后一个元素     *     * @return the last (highest) element currently in this set     * @throws NoSuchElementException if this set is empty     */    E last();}
0 0
原创粉丝点击