Interface Map<Key,Value>

Type Parameters:
Key - the key type
Value - the value type
All Superinterfaces:
Container<MapItem<Key,Value>>, Iterable<MapItem<Key,Value>>
All Known Subinterfaces:
OrderedMap<Key,Value>
All Known Implementing Classes:
ArrayMap, ArrayMap, AVLTree, AVLTree, BinarySearchTree, BinarySearchTree, ChainingHashMap, ChainingHashMap, ProbingHashMap, ProbingHashMap, SortedArrayMap, SortedArrayMap

public interface Map<Key,Value> extends Container<MapItem<Key,Value>>
A map.

A container where the items have unique keys. An item consists of a key and a value. The key is the uniquely identifying part of the item. The value is everything else.

  • Method Details

    • find

      Find the item with the given key.
      Parameters:
      key - the item's key
      Returns:
      the item
      Throws:
      NoSuchElementException - if no item has key key
    • insert

      void insert(MapItem<Key,Value> item)
      Insert the given item.

      If there's already an item with the same key, that item is replaced with this one.

      This means that if the key was not already contained, the size is incremented, otherwise it isn't.

      Parameters:
      item - the item
    • insert

      default void insert(Key key, Value value)
      Insert an item with the given key and value.

      If there's already an item with the same key, that item is replaced with this one.

      This means that if the key was not already contained, the size is incremented, otherwise it isn't.

      Parameters:
      key - the item's key
      value - the item's value
    • remove

      Remove and return the item with the given key.

      Decrements the size (assuming the item was actually in the map).

      Parameters:
      key - the item's key
      Returns:
      the item
      Throws:
      NoSuchElementException - if key is not contained
    • containsKey

      default boolean containsKey(Key key)
      Check if the given key is equal to any of those contained.
      Parameters:
      key - the key to check for membership
      Returns:
      whether such a key is contained
    • containsValue

      default boolean containsValue(Value value)
      Check if the given value is equal to any of those contained.
      Parameters:
      value - the value to check for membership
      Returns:
      whether such a value is contained
    • get

      default Value get(Key key) throws NoSuchElementException
      Get the value associated with the given key.
      Parameters:
      key - the key
      Returns:
      the corresponding value
      Throws:
      NoSuchElementException - if key is not contained
    • keys

      default Iterable<Key> keys()
      Get an iterable that yields each key once.
      Returns:
      an iterable over the keys
    • values

      default Iterable<Value> values()
      Get an iterable that yields each value once.
      Returns:
      an iterable over the values