Class CustomMap<K,​V>


  • public class CustomMap<K,​V>
    extends java.lang.Object
    A map implementation using a custom equality matcher, to avoid having to wrap each entry in a wrapper object to achieve customised equality testing.

    Note: this doesn't implement Map<K, V> to save the effort of implementing methods like size() and iterator() that aren't required for our use cases. These methods could easily be added without changing the basic design.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsKey​(K key)
      Ask if a key exists in the set of keys
      V get​(K key)
      Get the value associated with a given key, or null if absemt
      java.util.List<K> keys()
      List all the keys.
      V put​(K key, V value)
      Add an entry to the map
      java.util.List<V> values()
      List all the values.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • put

        public V put​(K key,
                     V value)
        Add an entry to the map
        Parameters:
        key - the new key
        value - the value to be added.
        Returns:
        the previous value for the key if there was one, or null otherwise
      • get

        public V get​(K key)
        Get the value associated with a given key, or null if absemt
        Parameters:
        key - the new key
        Returns:
        the value for the key if there is one, or null otherwise
      • containsKey

        public boolean containsKey​(K key)
        Ask if a key exists in the set of keys
        Parameters:
        key - the requested key
        Returns:
        true if it exists
      • keys

        public java.util.List<K> keys()
        List all the keys.
        Returns:
        a list of all the keys
      • values

        public java.util.List<V> values()
        List all the values.
        Returns:
        a list of all the values