public class StoredMap<K,V> extends StoredContainer implements java.util.concurrent.ConcurrentMap<K,V>
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.
Constructor and Description |
---|
StoredMap(Database database,
EntryBinding<K> keyBinding,
EntityBinding<V> valueEntityBinding,
boolean writeAllowed)
Creates a map entity view of a
Database . |
StoredMap(Database database,
EntryBinding<K> keyBinding,
EntityBinding<V> valueEntityBinding,
PrimaryKeyAssigner keyAssigner)
Creates a map entity view of a
Database with a PrimaryKeyAssigner . |
StoredMap(Database database,
EntryBinding<K> keyBinding,
EntryBinding<V> valueBinding,
boolean writeAllowed)
Creates a map view of a
Database . |
StoredMap(Database database,
EntryBinding<K> keyBinding,
EntryBinding<V> valueBinding,
PrimaryKeyAssigner keyAssigner)
Creates a map view of a
Database with a PrimaryKeyAssigner . |
Modifier and Type | Method and Description |
---|---|
K |
append(V value)
Appends a given value returning the newly assigned key.
|
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains the specified key.
|
boolean |
containsValue(java.lang.Object value)
Returns true if this map contains the specified value.
|
java.util.Collection<V> |
duplicates(K key)
Returns a new collection containing the values mapped to the given key
in this map.
|
<PK> java.util.Map<PK,V> |
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).
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Returns a set view of the mappings contained in this map.
|
boolean |
equals(java.lang.Object other)
Compares the specified object with this map for equality.
|
V |
get(java.lang.Object key)
Returns the value to which this map maps the specified key.
|
int |
hashCode() |
java.util.Set<K> |
keySet()
Returns a set view of the keys contained in this map.
|
V |
put(K key,
V value)
Associates the specified value with the specified key in this map
(optional operation).
|
void |
putAll(java.util.Map<? extends K,? extends V> map)
Copies all of the mappings from the specified map to this map (optional
operation).
|
V |
putIfAbsent(K key,
V value)
If the specified key is not already associated with a value, associate
it with the given value.
|
V |
remove(java.lang.Object key)
Removes the mapping for this key from this map if present (optional
operation).
|
boolean |
remove(java.lang.Object key,
java.lang.Object value)
Remove entry for key only if currently mapped to given value.
|
V |
replace(K key,
V value)
Replace entry for key only if currently mapped to some value.
|
boolean |
replace(K key,
V oldValue,
V newValue)
Replace entry for key only if currently mapped to given value.
|
int |
size()
Returns a non-transactional count of the records in the collection or
map.
|
java.lang.String |
toString()
Converts the map to a string representation for debugging.
|
java.util.Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
areDuplicatesAllowed, areDuplicatesOrdered, areKeyRangesAllowed, areKeysRenumbered, clear, getCursorConfig, isEmpty, isOrdered, isSecondary, isTransactional, isWriteAllowed
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public StoredMap(Database database, EntryBinding<K> keyBinding, EntryBinding<V> valueBinding, boolean writeAllowed)
Database
.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.java.lang.IllegalArgumentException
- if formats are not consistently
defined or a parameter is invalid.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public StoredMap(Database database, EntryBinding<K> keyBinding, EntryBinding<V> valueBinding, PrimaryKeyAssigner keyAssigner)
Database
with a PrimaryKeyAssigner
. Writing is allowed for the created map.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 the append(V)
method to assign
primary keys.java.lang.IllegalArgumentException
- if formats are not consistently
defined or a parameter is invalid.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public StoredMap(Database database, EntryBinding<K> keyBinding, EntityBinding<V> valueEntityBinding, boolean writeAllowed)
Database
.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.java.lang.IllegalArgumentException
- if formats are not consistently
defined or a parameter is invalid.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public StoredMap(Database database, EntryBinding<K> keyBinding, EntityBinding<V> valueEntityBinding, PrimaryKeyAssigner keyAssigner)
Database
with a PrimaryKeyAssigner
. Writing is allowed for the created map.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 the append(V)
method to assign
primary keys.java.lang.IllegalArgumentException
- if formats are not consistently
defined or a parameter is invalid.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public V get(java.lang.Object key)
Map.get(java.lang.Object)
interface.
get
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Read Operation
Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public V put(K key, V value)
Map.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.
put
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Write
Operation Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
java.lang.UnsupportedOperationException
- if the collection is indexed, or
if the collection is read-only.java.lang.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 a DatabaseException
on BDB (C edition).public K append(V value)
PrimaryKeyAssigner
is 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 standard Map
interface.
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.
value
- the value to be appended.OperationFailureException
- if one of the Write
Operation Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
java.lang.UnsupportedOperationException
- if the collection is indexed, or
if the collection is read-only, or if the Store has no PrimaryKeyAssigner
and is not a QUEUE or RECNO database.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public V remove(java.lang.Object key)
Map.remove(java.lang.Object)
interface.
remove
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Write
Operation Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
java.lang.UnsupportedOperationException
- if the collection is read-only.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public V putIfAbsent(K key, V value)
ConcurrentMap.putIfAbsent(K, V)
interface.
putIfAbsent
in interface java.util.concurrent.ConcurrentMap<K,V>
putIfAbsent
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Write
Operation Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public boolean remove(java.lang.Object key, java.lang.Object value)
ConcurrentMap.remove(Object,Object)
interface.
remove
in interface java.util.concurrent.ConcurrentMap<K,V>
remove
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Write
Operation Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public V replace(K key, V value)
ConcurrentMap.replace(Object,Object)
interface.
replace
in interface java.util.concurrent.ConcurrentMap<K,V>
replace
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Write
Operation Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public boolean replace(K key, V oldValue, V newValue)
ConcurrentMap.replace(Object,Object,Object)
interface.
replace
in interface java.util.concurrent.ConcurrentMap<K,V>
replace
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Write
Operation Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public boolean containsKey(java.lang.Object key)
Map.containsKey(java.lang.Object)
interface.
containsKey
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Read Operation
Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public boolean containsValue(java.lang.Object value)
Map.containsValue(java.lang.Object)
interface.
containsValue
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Read Operation
Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public void putAll(java.util.Map<? extends K,? extends V> map)
Map.putAll(java.util.Map<? extends K, ? extends V>)
interface.
putAll
in interface java.util.Map<K,V>
OperationFailureException
- if one of the Write
Operation Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
java.lang.UnsupportedOperationException
- if the collection is read-only, or
if the collection is indexed.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public java.util.Set<K> keySet()
SortedSet
is returned if the map supports key ranges. The
returned collection will be read-only if the map is read-only. This
method conforms to the Map.keySet()
interface.
Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.
keySet
in interface java.util.Map<K,V>
StoredKeySet
or a StoredSortedKeySet
for this
map.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).StoredContainer.areKeyRangesAllowed()
,
StoredContainer.isWriteAllowed()
public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
SortedSet
is returned if the map supports key ranges. The
returned collection will be read-only if the map is read-only. This
method conforms to the Map.entrySet()
interface.
Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.
entrySet
in interface java.util.Map<K,V>
StoredEntrySet
or a StoredSortedEntrySet
for
this map.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).StoredContainer.areKeyRangesAllowed()
,
StoredContainer.isWriteAllowed()
public java.util.Collection<V> values()
SortedSet
is 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 the Map.values()
interface.
Note that the return value is a StoredCollection and must be treated as such; for example, its iterators must be explicitly closed.
values
in interface java.util.Map<K,V>
StoredValueSet
or a StoredSortedValueSet
for
this map.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).StoredContainer.areKeyRangesAllowed()
,
StoredContainer.isWriteAllowed()
public java.util.Collection<V> duplicates(K key)
Map
interface.
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.
key
- is the key for which values are to be returned.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public <PK> java.util.Map<PK,V> duplicatesMap(K secondaryKey, EntryBinding primaryKeyBinding)
Map
interface.
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.
PK
- the primary key class.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.RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public boolean equals(java.lang.Object other)
Map.equals(java.lang.Object)
interface.
equals
in interface java.util.Map<K,V>
equals
in class java.lang.Object
OperationFailureException
- if one of the Read Operation
Failures occurs.EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).public int hashCode()
public int size()
StoredContainer
Collection.size()
and
Map.size()
interfaces.
This operation is faster than obtaining a count by scanning the collection manually, and will not perturb the current contents of the cache. However, the count is not guaranteed to be accurate if there are concurrent updates.
size
in interface java.util.Map<K,V>
size
in class StoredContainer
public java.lang.String toString()
toString
in class java.lang.Object
RuntimeExceptionWrapper
- if a checked exception is thrown,
including a DatabaseException
on BDB (C edition).Copyright (c) 2002, 2017 Oracle and/or its affiliates. All rights reserved.