TKey
- The type of the key in the dictionary.TValue
- The type of the value in the dictionary.public abstract class PersistentDictionary<TKey,TValue> extends PersistentDictionaryNode<TKey,TValue> implements Iterable<Map.Entry<TKey,TValue>>
#add(TKey,TValue)
return a new instance
instead of modifying the one on which they are called. The new instance shares much of its
structure with the original, so modifications are still efficient. This class is useful in
multithreaded applications. An instance of this type cannot be created directly. The
PersistentDictionary.Empty
field contains an empty instance with which to start.Modifier and Type | Field and Description |
---|---|
static PersistentDictionary |
Empty
An empty dictionary.
|
Constructor and Description |
---|
PersistentDictionary() |
Modifier and Type | Method and Description |
---|---|
PersistentDictionary<TKey,TValue> |
add(TKey key,
TValue value)
Adds a specified key/value pair to the dictionary.
|
abstract PersistentDictionary<TKey,TValue> |
add(TKey key,
TValue value,
PersistentDictionaryAddResult[] result)
Adds a specified key/value pair to the dictionary, and returns a value indicating
whether the key was newly added to the dictionary or it already existed and the value
was replaced.
|
boolean |
containsKey(TKey key)
Determines if a specified key exists in the dictionary.
|
TValue |
get(TKey key)
Gets the value corresponding to the specified key.
|
abstract int |
getCount()
Gets the number of elements in this dictionary.
|
Collection<TKey> |
getKeys()
Gets a read-only collection of keys in the dictionary.
|
Collection<TValue> |
getValues()
Gets a read-only collection of values in the dictionary.
|
abstract Iterator<Map.Entry<TKey,TValue>> |
iterator()
Gets an enumerator for enumerating over the key/value pairs in the dictionary.
|
abstract PersistentDictionary<TKey,TValue> |
remove(TKey key)
Removes an item with the specified key from the dictionary.
|
abstract boolean |
tryGetValue(TKey key,
TValue[] value)
Gets the value in the dictionary corresponding to the given key.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
@Nonnull public static final PersistentDictionary Empty
public abstract int getCount()
@Nonnull public final PersistentDictionary<TKey,TValue> add(TKey key, TValue value)
key
- The key of the item to add to the dictionary.value
- The value of the item to add to the dictionary.public final TValue get(TKey key)
KeyNotFoundException
if the key does not exist in the dictionary.key
- The key to find in the dictionary.key
.@Nonnull public final Collection<TKey> getKeys()
@Nonnull public final Collection<TValue> getValues()
public final boolean containsKey(TKey key)
key
- The key to find in the dictionary.true
if the key exists in the dictionary; otherwise false
.@Nonnull public abstract PersistentDictionary<TKey,TValue> add(TKey key, TValue value, @Nonnull PersistentDictionaryAddResult[] result)
key
- The key of the item to add to the dictionary.value
- The value of the item to add to the dictionary.result
- On input, an array with one element. On return, the array is populated with
a value indicating whether the key was newly added to the dictionary or it already existed
and the value was replaced.public abstract boolean tryGetValue(TKey key, @Nonnull TValue[] value)
key
- The key of the item to retrieve from the dictionary.value
- On input, an array with one element. On return, the array is populated with
the value corresponding to the key
.true
if the key was found in the dictionary; otherwise false
.@Nonnull public abstract PersistentDictionary<TKey,TValue> remove(TKey key)
key
- The key to remove from the dictionary.key
, or the same instance on
which it is called if the key does not exist in the dictionary.