Package com.google.api.client.util.store
Class AbstractMemoryDataStore<V extends java.io.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
class AbstractMemoryDataStore<V extends java.io.Serializable> extends AbstractDataStore<V>
Abstract, thread-safe, in-memory implementation of a data store factory.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.HashMap<java.lang.String,byte[]>
keyValueMap
Data store map from the key to the value.private java.util.concurrent.locks.Lock
lock
Lock on access to the store.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractMemoryDataStore(DataStoreFactory dataStoreFactory, java.lang.String id)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DataStore<V>
clear()
Deletes all of the stored keys and values.boolean
containsKey(java.lang.String key)
Returns whether the store contains the given key.boolean
containsValue(V value)
Returns whether the store contains the given value.DataStore<V>
delete(java.lang.String key)
Deletes the stored key and value based on the given key, or ignored if the key doesn't already exist.V
get(java.lang.String key)
Returns the stored value for the given key ornull
if not found.boolean
isEmpty()
Returns whether there are any stored keys.java.util.Set<java.lang.String>
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()
.DataStore<V>
set(java.lang.String key, V value)
Stores the given value for the given key (replacing any existing value).int
size()
Returns the number of stored keys.java.lang.String
toString()
java.util.Collection<V>
values()
Returns the unmodifiable collection of all stored values.-
Methods inherited from class com.google.api.client.util.store.AbstractDataStore
getDataStoreFactory, getId
-
-
-
-
Constructor Detail
-
AbstractMemoryDataStore
protected AbstractMemoryDataStore(DataStoreFactory dataStoreFactory, java.lang.String id)
- Parameters:
dataStoreFactory
- data store factoryid
- data store ID
-
-
Method Detail
-
keySet
public final java.util.Set<java.lang.String> keySet() throws java.io.IOException
Description copied from interface:DataStore
Returns the unmodifiable set of all stored keys.Order of the keys is not specified.
- Throws:
java.io.IOException
-
values
public final java.util.Collection<V> values() throws java.io.IOException
Description copied from interface:DataStore
Returns the unmodifiable collection of all stored values.- Throws:
java.io.IOException
-
get
public final V get(java.lang.String key) throws java.io.IOException
Description copied from interface:DataStore
Returns the stored value for the given key ornull
if not found.- Parameters:
key
- key ornull
fornull
result- Throws:
java.io.IOException
-
set
public final DataStore<V> set(java.lang.String key, V value) throws java.io.IOException
Description copied from interface:DataStore
Stores the given value for the given key (replacing any existing value).- Parameters:
key
- keyvalue
- value object- Throws:
java.io.IOException
-
delete
public DataStore<V> delete(java.lang.String key) throws java.io.IOException
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:
java.io.IOException
-
clear
public final DataStore<V> clear() throws java.io.IOException
Description copied from interface:DataStore
Deletes all of the stored keys and values.- Throws:
java.io.IOException
-
containsKey
public boolean containsKey(java.lang.String key) throws java.io.IOException
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 java.io.Serializable>
- Overrides:
containsKey
in classAbstractDataStore<V extends java.io.Serializable>
- Throws:
java.io.IOException
-
containsValue
public boolean containsValue(V value) throws java.io.IOException
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 java.io.Serializable>
- Overrides:
containsValue
in classAbstractDataStore<V extends java.io.Serializable>
- Throws:
java.io.IOException
-
isEmpty
public boolean isEmpty() throws java.io.IOException
Description copied from class:AbstractDataStore
Returns whether there are any stored keys.Default implementation is to check if
AbstractDataStore.size()
is0
.
-
size
public int size() throws java.io.IOException
Description copied from class:AbstractDataStore
Returns the number of stored keys.Default implementation is to call
Set.size()
onDataStore.keySet()
.
-
save
void save() throws java.io.IOException
Persist the key-value map into storage at the end ofset(java.lang.String, V)
,delete(String)
, andclear()
.- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-