Interface NavigableMultiset<E>

Type Parameters:
E - element type | 元素类型
All Superinterfaces:
Collection<E>, Iterable<E>, Multiset<E>
All Known Implementing Classes:
TreeMultiset

public interface NavigableMultiset<E> extends Multiset<E>
NavigableMultiset - Navigable Multiset Interface NavigableMultiset - 可导航多重集合接口

A sorted multiset that provides navigation methods for accessing elements in sorted order.

提供按排序顺序访问元素的导航方法的排序多重集合。

Features | 主要功能:

  • Sorted element access - 排序元素访问
  • Navigation operations (lower, higher, floor, ceiling) - 导航操作
  • Polling operations - 轮询操作
  • Comparator access - 比较器访问

Usage Examples | 使用示例:

NavigableMultiset<String> multiset = TreeMultiset.create();
multiset.add("banana", 2);
multiset.add("apple", 3);
multiset.add("cherry");

String first = multiset.first();   // "apple"
String last = multiset.last();     // "cherry"
String lower = multiset.lower("banana"); // "apple"

Security | 安全性:

  • Thread-safe: No (interface, implementation-dependent) - 否(接口,取决于实现)
  • Null-safe: No - 否
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • first

      E first()
      Return the first (lowest) element. 返回第一个(最小)元素。
      Returns:
      the first element | 第一个元素
      Throws:
      NoSuchElementException - if empty | 如果为空则抛出异常
    • last

      E last()
      Return the last (highest) element. 返回最后一个(最大)元素。
      Returns:
      the last element | 最后一个元素
      Throws:
      NoSuchElementException - if empty | 如果为空则抛出异常
    • lower

      E lower(E e)
      Return the greatest element strictly less than the given element. 返回严格小于给定元素的最大元素。
      Parameters:
      e - the element | 元素
      Returns:
      the lower element, or null | 更小的元素,或 null
    • higher

      E higher(E e)
      Return the least element strictly greater than the given element. 返回严格大于给定元素的最小元素。
      Parameters:
      e - the element | 元素
      Returns:
      the higher element, or null | 更大的元素,或 null
    • floor

      E floor(E e)
      Return the greatest element less than or equal to the given element. 返回小于或等于给定元素的最大元素。
      Parameters:
      e - the element | 元素
      Returns:
      the floor element, or null | floor 元素,或 null
    • ceiling

      E ceiling(E e)
      Return the least element greater than or equal to the given element. 返回大于或等于给定元素的最小元素。
      Parameters:
      e - the element | 元素
      Returns:
      the ceiling element, or null | ceiling 元素,或 null
    • pollFirstEntry

      Multiset.Entry<E> pollFirstEntry()
      Remove and return the first entry, or null if empty. 移除并返回第一个条目,如果为空则返回 null。
      Returns:
      the first entry, or null | 第一个条目,或 null
    • pollLastEntry

      Multiset.Entry<E> pollLastEntry()
      Remove and return the last entry, or null if empty. 移除并返回最后一个条目,如果为空则返回 null。
      Returns:
      the last entry, or null | 最后一个条目,或 null
    • comparator

      Comparator<? super E> comparator()
      Return the comparator used to order elements. 返回用于排序元素的比较器。
      Returns:
      the comparator, or null for natural ordering | 比较器,自然排序则为 null