# Class AbstractMemoryDataStore&lt;V&gt; (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractMemoryDataStore)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.util.store.AbstractMemoryDataStore)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.store.AbstractMemoryDataStore)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.store.AbstractMemoryDataStore)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.store.AbstractMemoryDataStore)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.store.AbstractMemoryDataStore)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.store.AbstractMemoryDataStore)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.store.AbstractMemoryDataStore)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.store.AbstractMemoryDataStore)

    public class AbstractMemoryDataStore<V> extends AbstractDataStore<V>

Abstract, thread-safe, in-memory implementation of a data store factory.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> [AbstractDataStore](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore) \> AbstractMemoryDataStore\<V\>

## Inherited Members

[AbstractDataStore.containsKey(String)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_containsKey_java_lang_String_) [AbstractDataStore.containsValue(V)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_containsValue_V_) [AbstractDataStore.getDataStoreFactory()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_getDataStoreFactory__) [AbstractDataStore.getId()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_getId__) [AbstractDataStore.isEmpty()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_isEmpty__) [AbstractDataStore.size()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_size__) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

| ## Type Parameter ||
|---|---|
| **Name** | **Description** |
| `V` |   |

## Constructors

### AbstractMemoryDataStore(DataStoreFactory dataStoreFactory, String id)

    protected AbstractMemoryDataStore(DataStoreFactory dataStoreFactory, String id)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `dataStoreFactory` | `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.DataStoreFactory` data store factory |
| `id` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` data store ID |

## Fields

### keyValueMap

    protected HashMap<String,byte[]> keyValueMap

Data store map from the key to the value.

| **Field Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html,https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html[]>` |   |

## Methods

### clear()

    public final DataStore<V> clear()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.DataStore<V>` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### containsKey(String key)

    public boolean containsKey(String key)

Returns whether the store contains the given key.

Default implementation is to call [#get(String)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractMemoryDataStore#com_google_api_client_util_store_AbstractMemoryDataStore_get_java_lang_String_) and check if it is `null`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [AbstractDataStore\<V\>.containsKey(String key)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_containsKey_java_lang_String_)

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### containsValue(V value)

    public boolean containsValue(V value)

Returns whether the store contains the given value.

Default implementation is to call Collection#contains(Object) on [#values()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractMemoryDataStore#com_google_api_client_util_store_AbstractMemoryDataStore_values__).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `V` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [AbstractDataStore\<V\>.containsValue(V value)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_containsValue_V_)

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### delete(String key)

    public DataStore<V> delete(String key)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.DataStore<V>` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### get(String key)

    public final V get(String key)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `V` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### isEmpty()

    public boolean isEmpty()

Returns whether there are any stored keys.

Default implementation is to check if [#size()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractMemoryDataStore#com_google_api_client_util_store_AbstractMemoryDataStore_size__) is `0`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [AbstractDataStore\<V\>.isEmpty()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_isEmpty__)

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### keySet()

    public final Set<String> keySet()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Set.html<https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### save()

    public void save()

Persist the key-value map into storage at the end of #set, [#delete(String)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractMemoryDataStore#com_google_api_client_util_store_AbstractMemoryDataStore_delete_java_lang_String_), and
[#clear()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractMemoryDataStore#com_google_api_client_util_store_AbstractMemoryDataStore_clear__).

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### set(String key, V value)

    public final DataStore<V> set(String key, V value)

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |
| `value` | `V` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.DataStore<V>` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### size()

    public int size()

Returns the number of stored keys.

Default implementation is to call Set#size() on [#keySet()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractMemoryDataStore#com_google_api_client_util_store_AbstractMemoryDataStore_keySet__).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

**Overrides** [AbstractDataStore\<V\>.size()](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.store.AbstractDataStore#com_google_api_client_util_store_AbstractDataStore_size__)

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |

### toString()

    public String toString()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` |   |

**Overrides** [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)

### values()

    public final Collection<V> values()

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<V>` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/io/IOException.html` |   |