Class MapIndexProxy<K,​V>

  • Type Parameters:
    K - the type of keys in this map
    V - the type of values in this map
    All Implemented Interfaces:
    MapIndex<K,​V>

    public final class MapIndexProxy<K,​V>
    extends AbstractNativeProxy
    implements MapIndex<K,​V>
    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 map implementation does not permit null keys and values.

    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.

    All method arguments are non-null by default.

    This class is not thread-safe and its instances shall not be shared between threads.

    When the view goes out of scope, this map is destroyed. Subsequent use of the closed map is prohibited and will result in IllegalStateException.

    See Also:
    View
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      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<com.exonum.binding.common.collect.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.
      java.lang.String getName()
      Returns the name of this index.
      java.lang.String getName()
      Returns the name of this index.
      java.util.Iterator<K> keys()
      Returns an iterator over the map keys in lexicographical order.
      static <K,​V>
      MapIndexProxy<K,​V>
      newInGroupUnsafe​(java.lang.String groupName, byte[] mapId, View view, com.exonum.binding.common.serialization.Serializer<K> keySerializer, com.exonum.binding.common.serialization.Serializer<V> valueSerializer)
      Creates a new map in a collection group with the given name.
      static <K,​V>
      MapIndexProxy<K,​V>
      newInstance​(java.lang.String name, View view, com.exonum.binding.common.serialization.Serializer<K> keySerializer, com.exonum.binding.common.serialization.Serializer<V> valueSerializer)
      Creates a new MapIndexProxy.
      static <K extends com.google.protobuf.MessageLite,​V extends com.google.protobuf.MessageLite>
      MapIndexProxy<K,​V>
      newInstance​(java.lang.String name, View view, java.lang.Class<K> keyType, java.lang.Class<V> valueType)
      Creates a new MapIndexProxy using protobuf messages.
      void put​(K key, V value)
      Puts a new key-value pair into the map.
      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.lang.String toString()  
      java.util.Iterator<V> values()
      Returns an iterator over the map values in lexicographical order of keys.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface com.exonum.binding.storage.indices.MapIndex

        isEmpty
    • Method Detail

      • newInstance

        public static <K extends com.google.protobuf.MessageLite,​V extends com.google.protobuf.MessageLite> MapIndexProxy<K,​V> newInstance​(java.lang.String name,
                                                                                                                                                       View view,
                                                                                                                                                       java.lang.Class<K> keyType,
                                                                                                                                                       java.lang.Class<V> valueType)
        Creates a new MapIndexProxy using protobuf messages.

        If only a key or a value is a protobuf message, use newInstance(String, View, Serializer, Serializer) and StandardSerializers.protobuf(Class).

        Type Parameters:
        K - the type of keys in the map; must be a protobuf message
        V - the type of values in the map; must be a protobuf message
        Parameters:
        name - a unique alphanumeric non-empty identifier of this map in the underlying storage: [a-zA-Z0-9_]
        view - a database view. Must be valid If a view is read-only, "destructive" operations are not permitted
        keyType - the class of keys-protobuf messages
        valueType - the class of values-protobuf messages
        Throws:
        java.lang.IllegalStateException - if the view is not valid
        java.lang.IllegalArgumentException - if the name is empty; or a key or value class is not a valid protobuf message that has a public static #parseFrom(byte[]) method
      • newInstance

        public static <K,​V> MapIndexProxy<K,​V> newInstance​(java.lang.String name,
                                                                       View view,
                                                                       com.exonum.binding.common.serialization.Serializer<K> keySerializer,
                                                                       com.exonum.binding.common.serialization.Serializer<V> valueSerializer)
        Creates a new MapIndexProxy.
        Type Parameters:
        K - the type of keys in the map
        V - the type of values in the map
        Parameters:
        name - a unique alphanumeric non-empty identifier of this map in the underlying storage: [a-zA-Z0-9_]
        view - a database view. Must be valid. If a view is read-only, "destructive" operations are not permitted.
        keySerializer - a serializer of keys
        valueSerializer - a serializer of values
        Throws:
        java.lang.IllegalStateException - if the view is not valid
        java.lang.IllegalArgumentException - if the name is empty
        See Also:
        StandardSerializers
      • newInGroupUnsafe

        public static <K,​V> MapIndexProxy<K,​V> newInGroupUnsafe​(java.lang.String groupName,
                                                                            byte[] mapId,
                                                                            View view,
                                                                            com.exonum.binding.common.serialization.Serializer<K> keySerializer,
                                                                            com.exonum.binding.common.serialization.Serializer<V> valueSerializer)
        Creates a new map in a collection group with the given name.

        See a caveat on index identifiers.

        Type Parameters:
        K - the type of keys in the map
        V - the type of values in the map
        Parameters:
        groupName - a name of the collection group
        mapId - an identifier of this collection in the group, see the caveats
        view - a database view
        keySerializer - a serializer of keys
        valueSerializer - a serializer of values
        Returns:
        a new map proxy
        Throws:
        java.lang.IllegalStateException - if the view is not valid
        java.lang.IllegalArgumentException - if the name or index id is empty
        See Also:
        StandardSerializers
      • containsKey

        public boolean containsKey​(K key)
        Description copied from interface: MapIndex
        Returns true if this map contains a mapping for the specified key.
        Specified by:
        containsKey in interface MapIndex<K,​V>
      • put

        public void put​(K key,
                        V value)
        Description copied from interface: MapIndex
        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.
        Specified by:
        put in interface MapIndex<K,​V>
        Parameters:
        key - a storage key
        value - a storage value to associate with the key
      • putAll

        public void putAll​(java.util.Map<? extends K,​? extends V> sourceMap)
        Description copied from interface: MapIndex
        Puts all key-value pairs from the given map into this map. Equivalent to a sequence of individual MapIndex.put(K, V) operations.
        Specified by:
        putAll in interface MapIndex<K,​V>
        Parameters:
        sourceMap - a map to put into this one
      • get

        public V get​(K key)
        Description copied from interface: MapIndex
        Returns the value associated with the specified key, or null if there is no mapping for the key.
        Specified by:
        get in interface MapIndex<K,​V>
        Parameters:
        key - a storage key
        Returns:
        the value mapped to the specified key, or null if this map contains no mapping for the key.
      • remove

        public void remove​(K key)
        Description copied from interface: MapIndex
        Removes the value mapped to the specified key from the map. If there is no such mapping, has no effect.
        Specified by:
        remove in interface MapIndex<K,​V>
        Parameters:
        key - a storage key
      • keys

        public java.util.Iterator<K> keys()
        Description copied from interface: MapIndex
        Returns an iterator over the map keys in lexicographical order.

        Any destructive operation on the same Fork this map uses (but not necessarily on this map) will invalidate the iterator.

        Specified by:
        keys in interface MapIndex<K,​V>
      • values

        public java.util.Iterator<V> values()
        Description copied from interface: MapIndex
        Returns an iterator over the map values in lexicographical order of keys.

        Any destructive operation on the same Fork this map uses (but not necessarily on this map) will invalidate the iterator.

        Specified by:
        values in interface MapIndex<K,​V>
      • entries

        public java.util.Iterator<com.exonum.binding.common.collect.MapEntry<K,​V>> entries()
        Description copied from interface: MapIndex
        Returns an iterator over the map entries. The entries are ordered by keys in lexicographical order.

        Any destructive operation on the same Fork this map uses (but not necessarily on this map) will invalidate the iterator.

        Specified by:
        entries in interface MapIndex<K,​V>
      • clear

        public void clear()
        Description copied from interface: MapIndex
        Removes all of the key-value pairs from the map. The map will be empty after this method returns.
        Specified by:
        clear in interface MapIndex<K,​V>
      • getName

        public abstract java.lang.String getName()
        Returns the name of this index.
      • getName

        public final java.lang.String getName()
        Returns the name of this index.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object