Class ValueSortedMap<E>

  • Type Parameters:
    E - key's type

    public class ValueSortedMap<E>
    extends Object
    A map which ensures key uniqueness and order over values.
    Since:
    30/01/2017.
    Author:
    Charles Prud'homme
    • Constructor Detail

      • ValueSortedMap

        public ValueSortedMap()
        Create a doubly-linked set E <-> value, where value is a int. Keys are unique, so do values. Value can be retrieved through key and key can be retrieved through value. In addition, values are sorted.
    • Method Detail

      • clear

        public void clear()
        Remove all entries from this map.
      • put

        public void put​(E k,
                        int v)
        Insert a key k with the value v in this. If the key already exists, it is replaced.
        Parameters:
        k - the key
        v - the value
      • replace

        public void replace​(E k,
                            int v)
        Replaces the value attached with key k with v.
        Parameters:
        k - the key
        v - the value
      • getValue

        public int getValue​(E k)
        Parameters:
        k - a key
        Returns:
        value attached to the key k, or NO_ENTRY otherwise.
      • getValueOrDefault

        public int getValueOrDefault​(E k,
                                     int defaultValue)
        Parameters:
        k - a key
        defaultValue - value to return if k is not known.
        Returns:
        value attached to the key k, or defaultValue otherwise.
      • getLastValue

        public int getLastValue()
        return the largest value stored in this
        Returns:
        the largest value stored in this
      • getLowerValue

        public int getLowerValue​(int value)
        return the lowest value stored in this
        Returns:
        the lowest value stored in this
      • pollLastValue

        public int pollLastValue()
        return and remove the largest value stored in this
        Returns:
        the largest value stored in this
      • remove

        public void remove​(E k)
        Remove the key k and its value from this
        Parameters:
        k - a key
      • removeIf

        public boolean removeIf​(Predicate<? super E> filter)
        Remove any key and its value that matches the predicate filter
        Parameters:
        filter - predicate that satisfies (key,value) to remove
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if this is empty