Mr Dk.'s BlogMr Dk.'s Blog
  • 🦆 About Me
  • ⛏️ Technology Stack
  • 🔗 Links
  • 🗒️ About Blog
  • Algorithm
  • C++
  • Compiler
  • Cryptography
  • DevOps
  • Docker
  • Git
  • Java
  • Linux
  • MS Office
  • MySQL
  • Network
  • Operating System
  • Performance
  • PostgreSQL
  • Productivity
  • Solidity
  • Vue.js
  • Web
  • Wireless
  • 🐧 How Linux Works (notes)
  • 🐧 Linux Kernel Comments (notes)
  • 🐧 Linux Kernel Development (notes)
  • 🐤 μc/OS-II Source Code (notes)
  • ☕ Understanding the JVM (notes)
  • ⛸️ Redis Implementation (notes)
  • 🗜️ Understanding Nginx (notes)
  • ⚙️ Netty in Action (notes)
  • ☁️ Spring Microservices (notes)
  • ⚒️ The Annotated STL Sources (notes)
  • ☕ Java Development Kit 8
GitHub
  • 🦆 About Me
  • ⛏️ Technology Stack
  • 🔗 Links
  • 🗒️ About Blog
  • Algorithm
  • C++
  • Compiler
  • Cryptography
  • DevOps
  • Docker
  • Git
  • Java
  • Linux
  • MS Office
  • MySQL
  • Network
  • Operating System
  • Performance
  • PostgreSQL
  • Productivity
  • Solidity
  • Vue.js
  • Web
  • Wireless
  • 🐧 How Linux Works (notes)
  • 🐧 Linux Kernel Comments (notes)
  • 🐧 Linux Kernel Development (notes)
  • 🐤 μc/OS-II Source Code (notes)
  • ☕ Understanding the JVM (notes)
  • ⛸️ Redis Implementation (notes)
  • 🗜️ Understanding Nginx (notes)
  • ⚙️ Netty in Action (notes)
  • ☁️ Spring Microservices (notes)
  • ⚒️ The Annotated STL Sources (notes)
  • ☕ Java Development Kit 8
GitHub
  • ☕ Java Development Kit 8
    • java.io

      • Abstract Class - java.io.InputStream
      • Abstract Class - java.io.OutputStream
      • Abstract Class - java.io.Reader
      • Class - java.io.BufferedInputStream
      • Class - java.io.BufferedOutputStream
      • Class - java.io.BufferedReader
      • Class - java.io.ByteArrayInputStream
      • Class - java.io.ByteArrayOutputStream
      • Class - java.io.DataInputStream
      • Class - java.io.DataOutputStream
      • Class - java.io.FileInputStream
      • Class - java.io.FileOutputStream
      • Class - java.io.FileReader
      • Class - java.io.FilterInputStream
      • Class - java.io.FilterOutputStream
      • Class - java.io.InputStreamReader
      • Class - java.io.PipedInputStream
      • Class - java.io.PipedOutputStream
      • Class - java.io.PushbackInputStream
      • Class - java.io.SequenceInputStream
      • Interface - java.io.Closeable
    • java.lang

      • Abstract Class - java.lang.AbstractStringBuilder
      • Class - java.lang.Integer
      • Class - java.lang.String
      • Class - java.lang.ThreadLocal
    • java.nio

      • Abstract Class - java.nio.Buffer
    • java.util

      • Abstract Class - java.util.AbstractCollection
      • Abstract Class - java.util.AbstractList
      • Abstract Class - java.util.AbstractMap
      • Abstract Class - java.util.AbstractQueue
      • Abstract Class - java.util.AbstractSet
      • Class - java.util.ArrayList
      • Class - java.util.HashMap
      • Class - java.util.HashSet
      • Class - java.util.IdentityHashMap
      • Class - java.util.LinkedHashMap
      • Class - java.util.LinkedHashSet
      • Class - java.util.LinkedList
      • Class - java.util.PriorityQueue
      • Class - java.util.TreeMap
      • Class - java.util.TreeSet
      • Interface - java.util.Collection
      • Interface - java.util.Deque
      • Interface - java.util.Iterator
      • Interface - java.util.Iterator
      • Interface - java.util.Map
      • Interface - java.util.NavigableMap
      • Interface - java.util.NavigableSet
      • Interface - java.util.Queue
      • Interface - java.util.Set
      • Interface - java.util.SortedMap
      • Interface - java.util.SortedSet
    • java.util.concurrent

      • Abstract Class - java.util.concurrent.atomic.AtomicIntegerFieldUpdater
      • Abstract Class - java.util.concurrent.locks.AbstractExecutorService
      • Abstract Class - java.util.concurrent.locks.AbstractOwnableSynchronizer
      • Abstract Class - java.util.concurrent.locks.AbstractQueuedSynchronizer
      • Class - java.util.concurrent.ArrayBlockingQueue
      • Class - java.util.concurrent.ConcurrentHashMap
      • Class - java.util.concurrent.ConcurrentLinkedQueue
      • Class - java.util.concurrent.DelayQueue
      • Class - java.util.concurrent.ExecutorCompletionService
      • Class - java.util.concurrent.FutureTask
      • Class - java.util.concurrent.LinkedBlockingQueue
      • Class - java.util.concurrent.LinkedTransferQueue
      • Class - java.util.concurrent.SynchronousQueue
      • Class - java.util.concurrent.ThreadPoolExecutor
      • Class - java.util.concurrent.atomic.AtomicInteger
      • Class - java.util.concurrent.atomic.AtomicIntegerArray
      • Class - java.util.concurrent.atomic.AtomicReference
      • Class - java.util.concurrent.atomic.AtomicStampedReference
      • Class - java.util.concurrent.locks.ReentrantLock
      • Class - java.util.concurrent.locks.ReentrantReadWriteLock
      • Interface - java.util.concurrent.BlockingQueue
      • Interface - java.util.concurrent.CompletionService
      • Interface - java.util.concurrent.Executor
      • Interface - java.util.concurrent.ExecutorService
      • Interface - java.util.concurrent.Future
      • Interface - java.util.concurrent.ScheduledExecutorService
      • Interface - java.util.concurrent.TransferQueue
      • Interface - java.util.concurrent.locks.Lock
      • Interface - java.util.concurrent.locks.ReadWriteLock

Interface - java.util.SortedSet

Created by : Mr Dk.

2019 / 11 / 20 17:26

Nanjing, Jiangsu, China


Definition

public interface SortedSet<E> extends Set<E> {

}

有顺序保证的 Set,由自然顺序或指定 Comparator 保证。利用集合的有序性,提供了几种附加操作,任何被插入集合的元素必须是可比较的,而且顺序对于 equals() 来说必须一直一致。取子集的函数全是左闭右开的区间 - [)。

/**
 * A {@link Set} that further provides a <i>total ordering</i> on its elements.
 * The elements are ordered using their {@linkplain Comparable natural
 * ordering}, or by a {@link Comparator} typically provided at sorted
 * set creation time.  The set's iterator will traverse the set in
 * ascending element order. Several additional operations are provided
 * to take advantage of the ordering.  (This interface is the set
 * analogue of {@link SortedMap}.)
 *
 * <p>All elements inserted into a sorted set must implement the <tt>Comparable</tt>
 * interface (or be accepted by the specified comparator).  Furthermore, all
 * such elements must be <i>mutually comparable</i>: <tt>e1.compareTo(e2)</tt>
 * (or <tt>comparator.compare(e1, e2)</tt>) must not throw a
 * <tt>ClassCastException</tt> for any elements <tt>e1</tt> and <tt>e2</tt> in
 * the sorted set.  Attempts to violate this restriction will cause the
 * offending method or constructor invocation to throw a
 * <tt>ClassCastException</tt>.
 *
 * <p>Note that the ordering maintained by a sorted set (whether or not an
 * explicit comparator is provided) must be <i>consistent with equals</i> if
 * the sorted set is to correctly implement the <tt>Set</tt> interface.  (See
 * the <tt>Comparable</tt> interface or <tt>Comparator</tt> interface for a
 * precise definition of <i>consistent with equals</i>.)  This is so because
 * the <tt>Set</tt> interface is defined in terms of the <tt>equals</tt>
 * operation, but a sorted set performs all element comparisons using its
 * <tt>compareTo</tt> (or <tt>compare</tt>) method, so two elements that are
 * deemed equal by this method are, from the standpoint of the sorted set,
 * equal.  The behavior of a sorted set <i>is</i> well-defined even if its
 * ordering is inconsistent with equals; it just fails to obey the general
 * contract of the <tt>Set</tt> interface.
 *
 * <p>All general-purpose sorted set implementation classes should
 * provide four "standard" constructors: 1) A void (no arguments)
 * constructor, which creates an empty sorted set sorted according to
 * the natural ordering of its elements.  2) A constructor with a
 * single argument of type <tt>Comparator</tt>, which creates an empty
 * sorted set sorted according to the specified comparator.  3) A
 * constructor with a single argument of type <tt>Collection</tt>,
 * which creates a new sorted set with the same elements as its
 * argument, sorted according to the natural ordering of the elements.
 * 4) A constructor with a single argument of type <tt>SortedSet</tt>,
 * which creates a new sorted set with the same elements and the same
 * ordering as the input sorted set.  There is no way to enforce this
 * recommendation, as interfaces cannot contain constructors.
 *
 * <p>Note: several methods return subsets with restricted ranges.
 * Such ranges are <i>half-open</i>, that is, they include their low
 * endpoint but not their high endpoint (where applicable).
 * If you need a <i>closed range</i> (which includes both endpoints), and
 * the element type allows for calculation of the successor of a given
 * value, merely request the subrange from <tt>lowEndpoint</tt> to
 * <tt>successor(highEndpoint)</tt>.  For example, suppose that <tt>s</tt>
 * is a sorted set of strings.  The following idiom obtains a view
 * containing all of the strings in <tt>s</tt> from <tt>low</tt> to
 * <tt>high</tt>, inclusive:<pre>
 *   SortedSet&lt;String&gt; sub = s.subSet(low, high+"\0");</pre>
 *
 * A similar technique can be used to generate an <i>open range</i> (which
 * contains neither endpoint).  The following idiom obtains a view
 * containing all of the Strings in <tt>s</tt> from <tt>low</tt> to
 * <tt>high</tt>, exclusive:<pre>
 *   SortedSet&lt;String&gt; sub = s.subSet(low+"\0", high);</pre>
 *
 * <p>This interface is a member of the
 * <a href="{@docRoot}/../technotes/guides/collections/index.html">
 * Java Collections Framework</a>.
 *
 * @param <E> the type of elements maintained by this set
 *
 * @author  Josh Bloch
 * @see Set
 * @see TreeSet
 * @see SortedMap
 * @see Collection
 * @see Comparable
 * @see Comparator
 * @see ClassCastException
 * @since 1.2
 */

/**
 * Returns the comparator used to order the elements in this set,
 * or <tt>null</tt> if this set uses the {@linkplain Comparable
 * natural ordering} of its elements.
 *
 * @return the comparator used to order the elements in this set,
 *         or <tt>null</tt> if this set uses the natural ordering
 *         of its elements
 */
Comparator<? super E> comparator();

返回比较器。


/**
 * Returns a view of the portion of this set whose elements range
 * from <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>,
 * exclusive.  (If <tt>fromElement</tt> and <tt>toElement</tt> are
 * equal, the returned set is empty.)  The returned set is backed
 * by this set, so changes in the returned set are reflected in
 * this set, and vice-versa.  The returned set supports all
 * optional set operations that this set supports.
 *
 * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
 * on an attempt to insert an element outside its range.
 *
 * @param fromElement low endpoint (inclusive) of the returned set
 * @param toElement high endpoint (exclusive) of the returned set
 * @return a view of the portion of this set whose elements range from
 *         <tt>fromElement</tt>, inclusive, to <tt>toElement</tt>, exclusive
 * @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);

取子集合,包含 fromElement,但不包含 toElement。


/**
 * Returns a view of the portion of this set whose elements are
 * strictly less than <tt>toElement</tt>.  The returned set is
 * backed by this set, so changes in the returned set are
 * reflected in this set, and vice-versa.  The returned set
 * supports all optional set operations that this set supports.
 *
 * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
 * on an attempt to insert an element outside its range.
 *
 * @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);

取严格小于 toElement 的元素子集。


/**
 * Returns a view of the portion of this set whose elements are
 * greater than or equal to <tt>fromElement</tt>.  The returned
 * set is backed by this set, so changes in the returned set are
 * reflected in this set, and vice-versa.  The returned set
 * supports all optional set operations that this set supports.
 *
 * <p>The returned set will throw an <tt>IllegalArgumentException</tt>
 * on an attempt to insert an element outside its range.
 *
 * @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);

返回大于等于 fromElement 的元素子集。


/**
 * Returns the first (lowest) element currently in this set.
 *
 * @return the first (lowest) element currently in this set
 * @throws NoSuchElementException if this set is empty
 */
E first();

/**
 * Returns the last (highest) element currently in this set.
 *
 * @return the last (highest) element currently in this set
 * @throws NoSuchElementException if this set is empty
 */
E last();

返回最大或最小元素。


Edit this page on GitHub
Prev
Interface - java.util.SortedMap