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
public 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 protected java.util.HashMap<java.lang.String,byte[]>keyValueMapData store map from the key to the value.private java.util.concurrent.locks.LocklockLock on access to the store.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMemoryDataStore(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.booleancontainsKey(java.lang.String key)Returns whether the store contains the given key.booleancontainsValue(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.Vget(java.lang.String key)Returns the stored value for the given key ornullif not found.booleanisEmpty()Returns whether there are any stored keys.java.util.Set<java.lang.String>keySet()Returns the unmodifiable set of all stored keys.voidsave()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).intsize()Returns the number of stored keys.java.lang.StringtoString()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.IOExceptionDescription copied from interface:DataStoreReturns 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:DataStoreReturns 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:DataStoreReturns the stored value for the given key ornullif not found.- Parameters:
key- key ornullfornullresult- Throws:
java.io.IOException
-
set
public final DataStore<V> set(java.lang.String key, V value) throws java.io.IOException
Description copied from interface:DataStoreStores 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:DataStoreDeletes the stored key and value based on the given key, or ignored if the key doesn't already exist.- Parameters:
key- key ornullto ignore- Throws:
java.io.IOException
-
clear
public final DataStore<V> clear() throws java.io.IOException
Description copied from interface:DataStoreDeletes all of the stored keys and values.- Throws:
java.io.IOException
-
containsKey
public boolean containsKey(java.lang.String key) throws java.io.IOExceptionDescription copied from class:AbstractDataStoreReturns whether the store contains the given key.Default implementation is to call
DataStore.get(String)and check if it isnull.- Specified by:
containsKeyin interfaceDataStore<V extends java.io.Serializable>- Overrides:
containsKeyin classAbstractDataStore<V extends java.io.Serializable>- Throws:
java.io.IOException
-
containsValue
public boolean containsValue(V value) throws java.io.IOException
Description copied from class:AbstractDataStoreReturns whether the store contains the given value.Default implementation is to call
Collection.contains(Object)onDataStore.values().- Specified by:
containsValuein interfaceDataStore<V extends java.io.Serializable>- Overrides:
containsValuein classAbstractDataStore<V extends java.io.Serializable>- Throws:
java.io.IOException
-
isEmpty
public boolean isEmpty() throws java.io.IOExceptionDescription copied from class:AbstractDataStoreReturns whether there are any stored keys.Default implementation is to check if
AbstractDataStore.size()is0.
-
size
public int size() throws java.io.IOExceptionDescription copied from class:AbstractDataStoreReturns the number of stored keys.Default implementation is to call
Set.size()onDataStore.keySet().
-
save
public void save() throws java.io.IOExceptionPersist 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:
toStringin classjava.lang.Object
-
-