Class MapIndexProxy<K,V>
- Type Parameters:
K
- the type of keys in this mapV
- the type of values in this map
- All Implemented Interfaces:
MapIndex<K,V>
,StorageIndex
public final class MapIndexProxy<K,V> extends AbstractNativeProxy implements MapIndex<K,V>
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 access.
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 access goes out of scope, this map is destroyed. Subsequent use of the closed map
is prohibited and will result in IllegalStateException
.
- See Also:
Access
-
Field Summary
-
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, ornull
if there is no mapping for the key.IndexAddress
getAddress()
Returns the index address: its identifier in the database.java.util.Iterator<K>
keys()
Returns an iterator over the map keys.static <K, V> MapIndexProxy<K,V>
newInstance(IndexAddress address, AbstractAccess access, Serializer<K> keySerializer, Serializer<V> valueSerializer)
Creates a new MapIndexProxy.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.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 Details
-
newInstance
public static <K, V> MapIndexProxy<K,V> newInstance(IndexAddress address, AbstractAccess access, Serializer<K> keySerializer, Serializer<V> valueSerializer)Creates a new MapIndexProxy.Warning: do not invoke this method from service code, use
Access.getMap(IndexAddress, Serializer, Serializer)
.- Type Parameters:
K
- the type of keys in the mapV
- the type of values in the map- Parameters:
address
- an index addressaccess
- a database access. Must be valid. If an access is read-only, "destructive" operations are not permitted.keySerializer
- a serializer of keysvalueSerializer
- a serializer of values- Throws:
java.lang.IllegalStateException
- if the access is not validjava.lang.IllegalArgumentException
- if the name is empty- See Also:
StandardSerializers
-
containsKey
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
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. -
putAll
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
Description copied from interface:MapIndex
Returns the value associated with the specified key, ornull
if there is no mapping for the key. -
remove
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
Description copied from interface:MapIndex
Returns an iterator over the map keys. The keys are ordered in lexicographical order. -
values
Description copied from interface:MapIndex
Returns an iterator over the map values. The values are ordered in lexicographical order of keys. -
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
Description copied from interface:StorageIndex
Returns the index address: its identifier in the database.Please note that the implementations may return either relative or absolute address. The address is not required to be equal to the one passed to the index constructor.
- Specified by:
getAddress
in interfaceStorageIndex
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-