Class StoredMap<K,V>
- All Implemented Interfaces:
Cloneable,ConcurrentMap<K,,V> Map<K,V>
- Direct Known Subclasses:
StoredSortedMap
Database.
In addition to the standard Map methods, this class provides the following methods for stored maps only. Note that the use of these methods is not compatible with the standard Java collections interface.
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionStoredMap(Database database, EntryBinding<K> keyBinding, EntityBinding<V> valueEntityBinding, boolean writeAllowed) Creates a map entity view of aDatabase.StoredMap(Database database, EntryBinding<K> keyBinding, EntityBinding<V> valueEntityBinding, PrimaryKeyAssigner keyAssigner) Creates a map entity view of aDatabasewith aPrimaryKeyAssigner.StoredMap(Database database, EntryBinding<K> keyBinding, EntryBinding<V> valueBinding, boolean writeAllowed) Creates a map view of aDatabase.StoredMap(Database database, EntryBinding<K> keyBinding, EntryBinding<V> valueBinding, PrimaryKeyAssigner keyAssigner) Creates a map view of aDatabasewith aPrimaryKeyAssigner. -
Method Summary
Modifier and TypeMethodDescriptionAppends a given value returning the newly assigned key.booleancontainsKey(Object key) Returns true if this map contains the specified key.booleancontainsValue(Object value) Returns true if this map contains the specified value.duplicates(K key) Returns a new collection containing the values mapped to the given key in this map.duplicatesMap(K secondaryKey, EntryBinding primaryKeyBinding) Returns a new map from primary key to value for the subset of records having a given secondary key (duplicates).entrySet()Returns a set view of the mappings contained in this map.booleanCompares the specified object with this map for equality.Returns the value to which this map maps the specified key.inthashCode()keySet()Returns a set view of the keys contained in this map.Associates the specified value with the specified key in this map (optional operation).voidCopies all of the mappings from the specified map to this map (optional operation).putIfAbsent(K key, V value) If the specified key is not already associated with a value, associate it with the given value.Removes the mapping for this key from this map if present (optional operation).booleanRemove entry for key only if currently mapped to given value.Replace entry for key only if currently mapped to some value.booleanReplace entry for key only if currently mapped to given value.intsize()Returns a non-transactional count of the records in the collection or map.toString()Converts the map to a string representation for debugging.values()Returns a collection view of the values contained in this map.Methods inherited from class com.sleepycat.collections.StoredContainer
areDuplicatesAllowed, areDuplicatesOrdered, areKeyRangesAllowed, areKeysRenumbered, clear, getCursorConfig, isEmpty, isOrdered, isSecondary, isTransactional, isWriteAllowedMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.ConcurrentMap
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, replaceAll
-
Constructor Details
-
StoredMap
public StoredMap(Database database, EntryBinding<K> keyBinding, EntryBinding<V> valueBinding, boolean writeAllowed) Creates a map view of aDatabase.- Parameters:
database- is the Database underlying the new collection.keyBinding- is the binding used to translate between key buffers and key objects.valueBinding- is the binding used to translate between value buffers and value objects.writeAllowed- is true to create a read-write collection or false to create a read-only collection.- Throws:
IllegalArgumentException- if formats are not consistently defined or a parameter is invalid.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
StoredMap
public StoredMap(Database database, EntryBinding<K> keyBinding, EntryBinding<V> valueBinding, PrimaryKeyAssigner keyAssigner) Creates a map view of aDatabasewith aPrimaryKeyAssigner. Writing is allowed for the created map.- Parameters:
database- is the Database underlying the new collection.keyBinding- is the binding used to translate between key buffers and key objects.valueBinding- is the binding used to translate between value buffers and value objects.keyAssigner- is used by theappend(V)method to assign primary keys.- Throws:
IllegalArgumentException- if formats are not consistently defined or a parameter is invalid.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
StoredMap
public StoredMap(Database database, EntryBinding<K> keyBinding, EntityBinding<V> valueEntityBinding, boolean writeAllowed) Creates a map entity view of aDatabase.- Parameters:
database- is the Database underlying the new collection.keyBinding- is the binding used to translate between key buffers and key objects.valueEntityBinding- is the binding used to translate between key/value buffers and entity value objects.writeAllowed- is true to create a read-write collection or false to create a read-only collection.- Throws:
IllegalArgumentException- if formats are not consistently defined or a parameter is invalid.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
StoredMap
public StoredMap(Database database, EntryBinding<K> keyBinding, EntityBinding<V> valueEntityBinding, PrimaryKeyAssigner keyAssigner) Creates a map entity view of aDatabasewith aPrimaryKeyAssigner. Writing is allowed for the created map.- Parameters:
database- is the Database underlying the new collection.keyBinding- is the binding used to translate between key buffers and key objects.valueEntityBinding- is the binding used to translate between key/value buffers and entity value objects.keyAssigner- is used by theappend(V)method to assign primary keys.- Throws:
IllegalArgumentException- if formats are not consistently defined or a parameter is invalid.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
-
Method Details
-
get
Returns the value to which this map maps the specified key. If duplicates are allowed, this method returns the first duplicate, in the order in which duplicates are configured, that maps to the specified key. This method conforms to theMap.get(java.lang.Object)interface.- Specified by:
getin interfaceMap<K,V> - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
put
Associates the specified value with the specified key in this map (optional operation). If duplicates are allowed and the specified key is already mapped to a value, this method appends the new duplicate after the existing duplicates. This method conforms to theMap.put(K, V)interface.The key parameter may be null if an entity binding is used and the key will be derived from the value (entity) parameter. If an entity binding is used and the key parameter is non-null, then the key parameter must be equal to the key derived from the value parameter.
- Specified by:
putin interfaceMap<K,V> - Returns:
- the previous value associated with specified key, or null if there was no mapping for the key or if duplicates are allowed.
- Throws:
UnsupportedOperationException- if the collection is indexed, or if the collection is read-only.IllegalArgumentException- if an entity value binding is used and the primary key of the value given is different than the existing stored primary key.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
append
Appends a given value returning the newly assigned key. If aPrimaryKeyAssigneris associated with Store for this map, it will be used to assigned the returned key. Otherwise the Store must be a QUEUE or RECNO database and the next available record number is assigned as the key. This method does not exist in the standardMapinterface.Note that for the JE product, QUEUE and RECNO databases are not supported, and therefore a PrimaryKeyAssigner must be associated with the map in order to call this method.
- Parameters:
value- the value to be appended.- Returns:
- the assigned key.
- Throws:
UnsupportedOperationException- if the collection is indexed, or if the collection is read-only, or if the Store has noPrimaryKeyAssignerand is not a QUEUE or RECNO database.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
remove
Removes the mapping for this key from this map if present (optional operation). If duplicates are allowed, this method removes all duplicates for the given key. This method conforms to theMap.remove(java.lang.Object)interface.- Specified by:
removein interfaceMap<K,V> - Throws:
UnsupportedOperationException- if the collection is read-only.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
putIfAbsent
If the specified key is not already associated with a value, associate it with the given value. This method conforms to theConcurrentMap.putIfAbsent(K, V)interface.- Specified by:
putIfAbsentin interfaceConcurrentMap<K,V> - Specified by:
putIfAbsentin interfaceMap<K,V> - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
remove
Remove entry for key only if currently mapped to given value. This method conforms to theConcurrentMap.remove(Object,Object)interface.- Specified by:
removein interfaceConcurrentMap<K,V> - Specified by:
removein interfaceMap<K,V> - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
replace
Replace entry for key only if currently mapped to some value. This method conforms to theConcurrentMap.replace(Object,Object)interface.- Specified by:
replacein interfaceConcurrentMap<K,V> - Specified by:
replacein interfaceMap<K,V> - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
replace
Replace entry for key only if currently mapped to given value. This method conforms to theConcurrentMap.replace(Object,Object,Object)interface.- Specified by:
replacein interfaceConcurrentMap<K,V> - Specified by:
replacein interfaceMap<K,V> - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
containsKey
Returns true if this map contains the specified key. This method conforms to theMap.containsKey(java.lang.Object)interface.- Specified by:
containsKeyin interfaceMap<K,V> - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
containsValue
Returns true if this map contains the specified value. When an entity binding is used, this method returns whether the map contains the primary key and value mapping of the entity. This method conforms to theMap.containsValue(java.lang.Object)interface.- Specified by:
containsValuein interfaceMap<K,V> - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
putAll
Copies all of the mappings from the specified map to this map (optional operation). When duplicates are allowed, the mappings in the specified map are effectively appended to the existing mappings in this map, that is no previously existing mappings in this map are replaced. This method conforms to theMap.putAll(java.util.Map<? extends K, ? extends V>)interface.- Specified by:
putAllin interfaceMap<K,V> - Throws:
UnsupportedOperationException- if the collection is read-only, or if the collection is indexed.RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
keySet
Returns a set view of the keys contained in this map. ASortedSetis returned if the map supports key ranges. The returned collection will be read-only if the map is read-only. This method conforms to theMap.keySet()interface.Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.
- Specified by:
keySetin interfaceMap<K,V> - Returns:
- a
StoredKeySetor aStoredSortedKeySetfor this map. - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).- See Also:
-
entrySet
Returns a set view of the mappings contained in this map. ASortedSetis returned if the map supports key ranges. The returned collection will be read-only if the map is read-only. This method conforms to theMap.entrySet()interface.Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.
- Specified by:
entrySetin interfaceMap<K,V> - Returns:
- a
StoredEntrySetor aStoredSortedEntrySetfor this map. - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).- See Also:
-
values
Returns a collection view of the values contained in this map. ASortedSetis returned if the map supports key ranges and the value/entity binding can be used to derive the map's key from its value/entity object. The returned collection will be read-only if the map is read-only. This method conforms to theMap.values()interface.Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.
- Specified by:
valuesin interfaceMap<K,V> - Returns:
- a
StoredValueSetor aStoredSortedValueSetfor this map. - Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).- See Also:
-
duplicates
Returns a new collection containing the values mapped to the given key in this map. This collection's iterator() method is particularly useful for iterating over the duplicates for a given key, since this is not supported by the standard Map interface. This method does not exist in the standardMapinterface.If no mapping for the given key is present, an empty collection is returned. If duplicates are not allowed, at most a single value will be in the collection returned. If duplicates are allowed, the returned collection's add() method may be used to add values for the given key.
- Parameters:
key- is the key for which values are to be returned.- Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
duplicatesMap
Returns a new map from primary key to value for the subset of records having a given secondary key (duplicates). This method does not exist in the standardMapinterface.If no mapping for the given key is present, an empty collection is returned. If duplicates are not allowed, at most a single value will be in the collection returned. If duplicates are allowed, the returned collection's add() method may be used to add values for the given key.
- Parameters:
secondaryKey- is the secondary key for which duplicates values will be represented by the returned map.primaryKeyBinding- is the binding used for keys in the returned map.- Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-
equals
Compares the specified object with this map for equality. A value comparison is performed by this method and the stored values are compared rather than calling the equals() method of each element. This method conforms to theMap.equals(java.lang.Object)interface. -
hashCode
public int hashCode() -
size
public int size()Description copied from class:StoredContainerReturns a non-transactional count of the records in the collection or map. This method conforms to theCollection.size()andMap.size()interfaces. -
toString
Converts the map to a string representation for debugging. WARNING: All mappings will be converted to strings and returned and therefore the returned string may be very large.- Overrides:
toStringin classObject- Returns:
- the string representation.
- Throws:
RuntimeExceptionWrapper- if a checked exception is thrown, including aDatabaseExceptionon BDB (C edition).
-