Interface OrderStatisticMap<K,​V extends @Nullable Object>

  • Type Parameters:
    K - the type of the keys of this map
    V - the type of the values of this map
    All Superinterfaces:
    Map<K,​V>, NavigableMap<K,​V>, SortedMap<K,​V>

    public interface OrderStatisticMap<K,​V extends @Nullable Object>
    extends NavigableMap<K,​V>
    A NavigableMap that allows two additional operations: receiving (and deleting) an entry by its rank, and getting the rank of an entry.

    Implementations should adhere to all contracts of the NavigableMap interface.

    Implementing classes should provide two means for comparing elements:

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

    In both cases, the used compare-method should be consistent with equals, i.e., compare(k, l) == 0 => k.equals(l), so that the Map interface is correctly implemented. If the used compare-method is not consistent with equals, the Map contract is not fulfilled (See the SortedMap interface for a more detailed description).

    See Also:
    Map, SortedMap
    • Method Detail

      • getKeyByRank

        default K getKeyByRank​(int pIndex)
        Returns the key of this map with the given rank. The lowest key in the map has rank == 0, the largest key in the set has rank == size - 1.

        If this OrderStatisticMap is a view on some backing OrderStatisticMap (as created, e.g., by descendingMap() or headMap(Object)), the returned rank is in relation to the keys in the view, not in relation to the keys in the backing set. Thus, one can always expect that key of rank 0 is the first key in this map, and key of rank Map.size() - 1 is the last.

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

        Map.Entry<K,​V> getEntryByRank​(int pIndex)
        Returns the entry of this map with the given rank. The lowest entry in the set has rank == 0, the largest entry in the set has rank == size - 1.

        If this OrderStatisticMap is a view on some backing OrderStatisticMap (as created, e.g., by descendingMap() or headMap(Object)), the returned rank is in relation to the entries in the view, not in relation to the entries in the backing set. Thus, one can always expect that entry of rank 0 is the first entry in this map, and entry of rank Map.size() - 1 is the last.

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

        @CanIgnoreReturnValue
        K removeByRank​(int pIndex)
        Remove the entry of this map with the given rank and return its key.

        The lowest entry in the map has rank == 0, the largest entry in the map has rank == size - 1.

        If this OrderStatisticMap is a view on some backing OrderStatisticMap (as created, e.g., by descendingMap() or headMap(Object)), the returned rank is in relation to the entries in the view, not in relation to the entries in the backing set. Thus, one can always expect that entry of rank 0 is the first entry in this map, and entry of rank Map.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:
        getKeyByRank(int)
      • rankOf

        int rankOf​(K pObj)
        Return the rank of the entry with the given key in this map. Returns -1 if the key does not exist in the map.

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

        If this OrderStatisticMap is a view on some backing OrderStatisticMap (as created, e.g., by descendingMap() or headMap(Object)), the returned rank is in relation to the entries in the view, not in relation to the entries in the backing set. Thus, one can always expect that key of rank 0 is the first key in this map, and key of rank Map.size() - 1 is the last.

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

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

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

        static <K,​V> OrderStatisticMap<K,​V> createWithNaturalOrder​(Map<? extends K,​? extends V> pMap)
        Creates a new OrderStatisticSet containing the same entries as the given map, using natural ordering over its keys. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticMap interface.
      • createWithSameOrder

        static <K,​V> OrderStatisticMap<K,​V> createWithSameOrder​(SortedMap<K,​? extends V> pSortedMap)
        Creates a new OrderStatisticMap containing the same entries and using the same order over keys as the given SortedMap. The returned map guarantees performance only in O(n) for the operations specific to the OrderStatisticMap interface.
        Type Parameters:
        K - type of the keys of the given and new map
        V - type of the values of the given and new map
        Parameters:
        pSortedMap - map to use entries and ordering of
        Returns:
        a new OrderStatisticMap containing the same entries and using the same order over keys as the given map