Class ProofMapIndexProxy<K,V>
- java.lang.Object
-
- com.exonum.binding.core.proxy.AbstractNativeProxy
-
- com.exonum.binding.core.storage.indices.ProofMapIndexProxy<K,V>
-
- Type Parameters:
K
- the type of keys in this map. Must be 32-byte long in the serialized formV
- the type of values in this map
- All Implemented Interfaces:
MapIndex<K,V>
,StorageIndex
public final class ProofMapIndexProxy<K,V> extends AbstractNativeProxy implements MapIndex<K,V>
A ProofMapIndexProxy is an index that maps keys to values. A map cannot contain duplicate keys; each key corresponds to at most one value. This map is capable of providing cryptographic proofs that a certain key is mapped to a particular value or that there are no mapping for the key in the map.This map is implemented as a Merkle-Patricia tree. It does not permit null keys and values, and requires that keys are 32-byte long.
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 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
-
-
Field Summary
-
Fields inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy
nativeHandle
-
-
Method Summary
All Methods Static Methods Instance 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.Iterator<MapEntry<K,V>>
entries()
Returns an iterator over the map entries.V
get(K key)
Returns the value associated with the specified key, ornull
if there is no mapping for the key.IndexAddress
getAddress()
Returns the index address: its unique identifier in the database.HashCode
getIndexHash()
Returns the index hash which represents the complete state of this map.UncheckedMapProof
getProof(Collection<? extends K> keys)
Returns a proof that there are values mapped to the specified keys or that there are no such mappings.UncheckedMapProof
getProof(K key, K... otherKeys)
Returns a proof that there are values mapped to the specified keys or that there are no such mappings.Iterator<K>
keys()
Returns an iterator over the map keys in lexicographical order.static <K,V>
ProofMapIndexProxy<K,V>newInGroupUnsafe(String groupName, byte[] mapId, View view, Serializer<K> keySerializer, Serializer<V> valueSerializer)
Creates a new proof map in a collection group with the given name.static <K,V>
ProofMapIndexProxy<K,V>newInstance(String name, View view, Serializer<K> keySerializer, Serializer<V> valueSerializer)
Creates a ProofMapIndexProxy.void
put(K key, V value)
Puts a new key-value pair into the map.void
putAll(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.String
toString()
Iterator<V>
values()
Returns an iterator over the map values in lexicographical order of keys.-
Methods inherited from class com.exonum.binding.core.proxy.AbstractNativeProxy
getNativeHandle, isValidHandle
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.exonum.binding.core.storage.indices.StorageIndex
getAddress, getName
-
-
-
-
Method Detail
-
newInstance
public static <K,V> ProofMapIndexProxy<K,V> newInstance(String name, View view, Serializer<K> keySerializer, Serializer<V> valueSerializer)
Creates a ProofMapIndexProxy.- Type Parameters:
K
- the type of keys in the mapV
- 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, must always produce 32-byte long valuesvalueSerializer
- a serializer of values- Throws:
IllegalStateException
- if the view is not validIllegalArgumentException
- if the name is empty- See Also:
StandardSerializers
-
newInGroupUnsafe
public static <K,V> ProofMapIndexProxy<K,V> newInGroupUnsafe(String groupName, byte[] mapId, View view, Serializer<K> keySerializer, Serializer<V> valueSerializer)
Creates a new proof map in a collection group with the given name.See a caveat on index identifiers.
- Type Parameters:
K
- the type of keys in the mapV
- the type of values in the map- Parameters:
groupName
- a name of the collection groupmapId
- an identifier of this collection in the group, see the caveatsview
- a database viewkeySerializer
- a serializer of keys, must always produce 32-byte long valuesvalueSerializer
- a serializer of values- Returns:
- a new map proxy
- Throws:
IllegalStateException
- if the view is not validIllegalArgumentException
- 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 interfaceMapIndex<K,V>
-
put
public 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.- Specified by:
put
in interfaceMapIndex<K,V>
- Parameters:
key
- a proof map key, must be 32-byte long when serializedvalue
- a storage value to associate with the key- Throws:
IllegalStateException
- if this map is not validIllegalArgumentException
- if the size of the key is not 32 bytesUnsupportedOperationException
- if this map is read-only
-
putAll
public void putAll(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 individualMapIndex.put(K, V)
operations.
-
get
public V get(K key)
Description copied from interface:MapIndex
Returns the value associated with the specified key, ornull
if there is no mapping for the key.
-
getProof
public UncheckedMapProof getProof(K key, K... otherKeys)
Returns a proof that there are values mapped to the specified keys or that there are no such mappings.- Parameters:
key
- a proof map key which might be mapped to some value, must be 32-byte longotherKeys
- other proof map keys which might be mapped to some values, each must be 32-byte long- Throws:
IllegalStateException
- if this map is not validIllegalArgumentException
- if the size of any of the keys is not 32 bytes
-
getProof
public UncheckedMapProof getProof(Collection<? extends K> keys)
Returns a proof that there are values mapped to the specified keys or that there are no such mappings.- Parameters:
keys
- proof map keys which might be mapped to some values, each must be 32-byte long- Throws:
IllegalStateException
- if this map is not validIllegalArgumentException
- if the size of any of the keys is not 32 bytes or keys collection is empty
-
getIndexHash
public HashCode getIndexHash()
Returns the index hash which represents the complete state of this map. Any modifications to the stored entries affect the index hash.- Throws:
IllegalStateException
- if this map is not valid
-
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.
-
keys
public Iterator<K> keys()
Description copied from interface:MapIndex
Returns an iterator over the map keys in lexicographical order.
-
values
public Iterator<V> values()
Description copied from interface:MapIndex
Returns an iterator over the map values in lexicographical order of keys.
-
entries
public Iterator<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.
-
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.
-
getAddress
public IndexAddress getAddress()
Description copied from interface:StorageIndex
Returns the index address: its unique identifier in the database. It consists of the name and, in case this index belongs to an index family, a family identifier.- Specified by:
getAddress
in interfaceStorageIndex
-
-