Package com.google.api.client.util.store
Class AbstractMemoryDataStore<V extends Serializable>
java.lang.Object
com.google.api.client.util.store.AbstractDataStore<V>
com.google.api.client.util.store.AbstractMemoryDataStore<V>
- Type Parameters:
V
- serializable type of the mapped value
- All Implemented Interfaces:
DataStore<V>
- Direct Known Subclasses:
FileDataStoreFactory.FileDataStore
,MemoryDataStoreFactory.MemoryDataStore
Abstract, thread-safe, in-memory implementation of a data store factory.
-
Field Summary
FieldsModifier and TypeFieldDescriptionData store map from the key to the value.private final Lock
Lock on access to the store. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractMemoryDataStore
(DataStoreFactory dataStoreFactory, String id) -
Method Summary
Modifier and TypeMethodDescriptionclear()
Deletes all of the stored keys and values.boolean
containsKey
(String key) Returns whether the store contains the given key.boolean
containsValue
(V value) Returns whether the store contains the given value.Deletes the stored key and value based on the given key, or ignored if the key doesn't already exist.final V
Returns the stored value for the given key ornull
if not found.boolean
isEmpty()
Returns whether there are any stored keys.keySet()
Returns the unmodifiable set of all stored keys.(package private) void
save()
Persist the key-value map into storage at the end ofset(java.lang.String, V)
,delete(String)
, andclear()
.Stores the given value for the given key (replacing any existing value).int
size()
Returns the number of stored keys.toString()
final Collection
<V> values()
Returns the unmodifiable collection of all stored values.Methods inherited from class com.google.api.client.util.store.AbstractDataStore
getDataStoreFactory, getId
-
Field Details
-
lock
Lock on access to the store. -
keyValueMap
Data store map from the key to the value.
-
-
Constructor Details
-
AbstractMemoryDataStore
- Parameters:
dataStoreFactory
- data store factoryid
- data store ID
-
-
Method Details
-
keySet
Description copied from interface:DataStore
Returns the unmodifiable set of all stored keys.Order of the keys is not specified.
- Throws:
IOException
-
values
Description copied from interface:DataStore
Returns the unmodifiable collection of all stored values.- Throws:
IOException
-
get
Description copied from interface:DataStore
Returns the stored value for the given key ornull
if not found.- Parameters:
key
- key ornull
fornull
result- Throws:
IOException
-
set
Description copied from interface:DataStore
Stores the given value for the given key (replacing any existing value).- Parameters:
key
- keyvalue
- value object- Throws:
IOException
-
delete
Description copied from interface:DataStore
Deletes the stored key and value based on the given key, or ignored if the key doesn't already exist.- Parameters:
key
- key ornull
to ignore- Throws:
IOException
-
clear
Description copied from interface:DataStore
Deletes all of the stored keys and values.- Throws:
IOException
-
containsKey
Description copied from class:AbstractDataStore
Returns whether the store contains the given key.Default implementation is to call
DataStore.get(String)
and check if it isnull
.- Specified by:
containsKey
in interfaceDataStore<V extends Serializable>
- Overrides:
containsKey
in classAbstractDataStore<V extends Serializable>
- Throws:
IOException
-
containsValue
Description copied from class:AbstractDataStore
Returns whether the store contains the given value.Default implementation is to call
Collection.contains(Object)
onDataStore.values()
.- Specified by:
containsValue
in interfaceDataStore<V extends Serializable>
- Overrides:
containsValue
in classAbstractDataStore<V extends Serializable>
- Throws:
IOException
-
isEmpty
Description copied from class:AbstractDataStore
Returns whether there are any stored keys.Default implementation is to check if
AbstractDataStore.size()
is0
.- Specified by:
isEmpty
in interfaceDataStore<V extends Serializable>
- Overrides:
isEmpty
in classAbstractDataStore<V extends Serializable>
- Throws:
IOException
-
size
Description copied from class:AbstractDataStore
Returns the number of stored keys.Default implementation is to call
Set.size()
onDataStore.keySet()
.- Specified by:
size
in interfaceDataStore<V extends Serializable>
- Overrides:
size
in classAbstractDataStore<V extends Serializable>
- Throws:
IOException
-
save
Persist the key-value map into storage at the end ofset(java.lang.String, V)
,delete(String)
, andclear()
.- Throws:
IOException
-
toString
-