Interface MapIndex<K,​V>

Type Parameters:
K - the type of keys in this map
V - the type of values in this map
All Superinterfaces:
StorageIndex
All Known Implementing Classes:
MapIndexProxy, ProofMapIndexProxy

public interface MapIndex<K,​V>
extends StorageIndex
A MapIndex is an index that maps keys to values. A map cannot contain duplicate keys; each key corresponds to at most one value.

The "destructive" methods of the map, i.e., the one that change the map contents, are specified to throw UnsupportedOperationException if the map has been created with a read-only database view.

This interface prohibits null keys and values.

  • Method Summary

    Modifier and Type Method Description
    void clear()
    Removes all of the key-value pairs from the map.
    boolean containsKey​(K key)
    Returns true if this map contains a mapping for the specified key.
    java.util.Iterator<MapEntry<K,​V>> entries()
    Returns an iterator over the map entries.
    V get​(K key)
    Returns the value associated with the specified key, or null if there is no mapping for the key.
    default boolean isEmpty()
    Returns true if this map has no entries.
    java.util.Iterator<K> keys()
    Returns an iterator over the map keys.
    void put​(K key, V value)
    Puts a new key-value pair into the map.
    default void putAll​(java.util.Map<? extends K,​? extends V> sourceMap)
    Puts all key-value pairs from the given map into this map.
    void remove​(K key)
    Removes the value mapped to the specified key from the map.
    java.util.Iterator<V> values()
    Returns an iterator over the map values.

    Methods inherited from interface com.exonum.binding.core.storage.indices.StorageIndex

    getAddress, getName
  • Method Details

    • containsKey

      boolean containsKey​(K key)
      Returns true if this map contains a mapping for the specified key.
      Throws:
      java.lang.IllegalStateException - if this map is not valid
    • put

      void put​(K key, V value)
      Puts a new key-value pair into the map. If this map already contains a mapping for the specified key, overwrites the old value with the specified value.
      Parameters:
      key - a storage key
      value - a storage value to associate with the key
      Throws:
      java.lang.IllegalStateException - if this map is not valid
      java.lang.IllegalArgumentException - if some property of the key or the value prevents it from being stored in this map
      java.lang.UnsupportedOperationException - if this map is read-only
    • putAll

      default void putAll​(java.util.Map<? extends K,​? extends V> sourceMap)
      Puts all key-value pairs from the given map into this map. Equivalent to a sequence of individual put(K, V) operations.
      Parameters:
      sourceMap - a map to put into this one
      Throws:
      java.lang.NullPointerException - if the passed map is null or contains a null key or values
      java.lang.IllegalStateException - if this map is not valid
      java.lang.IllegalArgumentException - if some property of the key or the value prevents it from being stored in this map
      java.lang.UnsupportedOperationException - if this map is read-only
    • get

      V get​(K key)
      Returns the value associated with the specified key, or null if there is no mapping for the key.
      Parameters:
      key - a storage key
      Returns:
      the value mapped to the specified key, or null if this map contains no mapping for the key.
      Throws:
      java.lang.IllegalStateException - if this map is not valid
    • remove

      void remove​(K key)
      Removes the value mapped to the specified key from the map. If there is no such mapping, has no effect.
      Parameters:
      key - a storage key
      Throws:
      java.lang.IllegalStateException - if this map is not valid
      java.lang.UnsupportedOperationException - if this map is read-only
    • keys

      java.util.Iterator<K> keys()
      Returns an iterator over the map keys. The keys are ordered in lexicographical order.
      Throws:
      java.lang.IllegalStateException - if this map is not valid
    • values

      java.util.Iterator<V> values()
      Returns an iterator over the map values. The values are ordered in lexicographical order of keys.
      Throws:
      java.lang.IllegalStateException - if this map is not valid
    • entries

      java.util.Iterator<MapEntry<K,​V>> entries()
      Returns an iterator over the map entries. The entries are ordered by keys in lexicographical order.
      Throws:
      java.lang.IllegalStateException - if this map is not valid
    • clear

      void clear()
      Removes all of the key-value pairs from the map. The map will be empty after this method returns.
      Throws:
      java.lang.IllegalStateException - if this map is not valid
      java.lang.UnsupportedOperationException - if this map is read-only
    • isEmpty

      default boolean isEmpty()
      Returns true if this map has no entries.

      Note: there is no size() method because implementations of MapIndex do not currently track the number of entries.