Interface OrderStatisticSet<E>

  • Type Parameters:
    E - the type of elements maintained by this set
    All Superinterfaces:
    Collection<E>, Iterable<E>, NavigableSet<E>, Set<E>, SortedSet<E>

    public interface OrderStatisticSet<E>
    extends NavigableSet<E>
    A NavigableSet that allows two additional operations: receiving (and deleting) an element by its rank, and getting the rank of an element.

    Implementations should adhere to all contracts of the NavigableSet interface.

    Implementing classes should provide two means for comparing elements:

    1. Using the natural ordering of the elements. In this case, all elements of the set have to implement the Comparable interface.
    2. Using a Comparator to create an order over the elements of the set.

    In both cases, the used compare-method should be consistent with equals, i.e., compare(a, b) == 0 => a.equals(b), so that the contract provided by Set is fulfilled. If the used compare-method is not consistent with equals , the Set contract is not fulfilled.

    • Method Detail

      • getByRank

        E getByRank​(int pIndex)
        Returns the element of this set with the given rank. The lowest element in the set has rank == 0, the largest element in the set has rank == size - 1.

        If this OrderStatisticSet is a view on some backing OrderStatisticSet (as created, e.g., by descendingSet() or headSet(Object)), the returned rank is in relation to the elements in the view, not in relation to the elements in the backing set. Thus, one can always expect that element of rank 0 is the first element in this set, and element of rank Set.size() - 1 is the last.

        Parameters:
        pIndex - the rank of the element to return
        Returns:
        the element of this set with the given rank
        Throws:
        IndexOutOfBoundsException - if the given rank is out of the range of this set (i.e., pRank < 0 || pRank >= size)
      • removeByRank

        @CanIgnoreReturnValue
        E removeByRank​(int pIndex)
        Remove the element of this set with the given rank and return it.

        The lowest element in the set has rank == 0, the largest element in the set has rank == size - 1.

        If this OrderStatisticSet is a view on some backing OrderStatisticSet (as created, e.g., by descendingSet() or headSet(Object)), the returned rank is in relation to the elements in the view, not in relation to the elements in the backing set. Thus, one can always expect that element of rank 0 is the first element in this set, and element of rank Set.size() - 1 is the last.

        Parameters:
        pIndex - the rank of the element to remove
        Returns:
        the removed element
        Throws:
        IndexOutOfBoundsException - if the given rank is out of the range of this set (i.e., pRank < 0 || pRank >= size)
        See Also:
        getByRank(int)
      • rankOf

        int rankOf​(E pObj)
        Return the rank of the given element in this set. Returns -1 if the element does not exist in the set.

        The lowest element in the set has rank == 0, the largest element in the set has rank == size - 1.

        If this OrderStatisticSet is a view on some backing OrderStatisticSet (as created, e.g., by descendingSet() or headSet(Object)), the returned rank is in relation to the elements in the view, not in relation to the elements in the backing set. Thus, one can always expect that element of rank 0 is the first element in this set, and element of rank Set.size() - 1 is the last.

        Parameters:
        pObj - the element to return the rank for
        Returns:
        the rank of the given element in the set, or -1 if the element is not in the set
        Throws:
        NullPointerException - if the given element is null
      • create

        static <E> OrderStatisticSet<E> create()
        Creates a new empty OrderStatisticSet using natural ordering. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticSet interface.
      • create

        static <E> OrderStatisticSet<E> create​(Comparator<? super E> pComparator)
        Creates a new empty OrderStatisticSet using the given comparator. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticSet interface.
      • createWithNaturalOrder

        static <E> OrderStatisticSet<E> createWithNaturalOrder​(Iterable<E> pCollection)
        Creates a new OrderStatisticSet containing the same elements as the given Iterable, using natural ordering. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticSet interface.
      • createWithSameOrder

        static <E> OrderStatisticSet<E> createWithSameOrder​(SortedSet<E> pSortedSet)
        Creates a new OrderStatisticSet containing the same elements and using the same order as the given SortedSet. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticSet interface.
        Type Parameters:
        E - type of the elements of the given and new set
        Parameters:
        pSortedSet - set to use elements and ordering of
        Returns:
        a new OrderStatisticSet containing the same elements and using the same order as the given set