Package com.google.gwt.storage.client
Class StorageMap
- java.lang.Object
-
- java.util.AbstractMap<java.lang.String,java.lang.String>
-
- com.google.gwt.storage.client.StorageMap
-
- All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.String>
public class StorageMap extends java.util.AbstractMap<java.lang.String,java.lang.String>
Exposes the local/sessionStorage
as a standardMap<String, String>
.Experimental API: This API is still under development and is subject to change.
The following characteristics are associated with this Map:
- Mutable - All 'write' methods (
put(String, String)
,AbstractMap.putAll(Map)
,remove(Object)
,clear()
,Map.Entry.setValue(Object)
) operate as intended; - remove() on Iterators - All remove() operations on available
Iterators (from
AbstractMap.keySet()
,entrySet()
andAbstractMap.values()
) operate as intended; - No
null
values and keys - The Storage doesn't accept keys or values which arenull
; - String values and keys - All keys and values in this Map are String types.
-
-
Constructor Summary
Constructors Constructor Description StorageMap(Storage storage)
Creates the Map with the specified Storage as data provider.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all items from the Storage.boolean
containsKey(java.lang.Object key)
Returnstrue
if the Storage contains the specified key,false
otherwise.boolean
containsValue(java.lang.Object value)
Returnstrue
if the Storage contains the specified value,false
otherwise (or if the specified key isnull
).java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>>
entrySet()
Returns a Set containing all entries of the Storage.java.lang.String
get(java.lang.Object key)
Returns the value associated with the specified key in the Storage.java.lang.String
put(java.lang.String key, java.lang.String value)
Adds (or overwrites) a new key/value pair in the Storage.java.lang.String
remove(java.lang.Object key)
Removes the key/value pair from the Storage.int
size()
Returns the number of items in the Storage.-
Methods inherited from class java.util.AbstractMap
clone, equals, hashCode, isEmpty, keySet, putAll, toString, values
-
-
-
-
Constructor Detail
-
StorageMap
public StorageMap(Storage storage)
Creates the Map with the specified Storage as data provider.- Parameters:
storage
- a local/session Storage instance obtained by eitherStorage.getLocalStorageIfSupported()
orStorage.getSessionStorageIfSupported()
.
-
-
Method Detail
-
clear
public void clear()
Removes all items from the Storage.- Specified by:
clear
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
clear
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
- See Also:
Storage.clear()
-
containsKey
public boolean containsKey(java.lang.Object key)
Returnstrue
if the Storage contains the specified key,false
otherwise.- Specified by:
containsKey
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
containsKey
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
containsValue
public boolean containsValue(java.lang.Object value)
Returnstrue
if the Storage contains the specified value,false
otherwise (or if the specified key isnull
).- Specified by:
containsValue
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
containsValue
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
Returns a Set containing all entries of the Storage.- Specified by:
entrySet
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Specified by:
entrySet
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
get
public java.lang.String get(java.lang.Object key)
Returns the value associated with the specified key in the Storage.- Specified by:
get
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
get
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
- Parameters:
key
- the key identifying the value- See Also:
Storage.getItem(String)
-
put
public java.lang.String put(java.lang.String key, java.lang.String value)
Adds (or overwrites) a new key/value pair in the Storage.- Specified by:
put
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
put
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
- Parameters:
key
- the key identifying the value (notnull
)value
- the value associated with the key (notnull
)- See Also:
Storage.setItem(String, String)
-
remove
public java.lang.String remove(java.lang.Object key)
Removes the key/value pair from the Storage.- Specified by:
remove
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
remove
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
- Parameters:
key
- the key identifying the item to remove- Returns:
- the value associated with the key -
null
if the key was not present in the Storage - See Also:
Storage.removeItem(String)
-
size
public int size()
Returns the number of items in the Storage.- Specified by:
size
in interfacejava.util.Map<java.lang.String,java.lang.String>
- Overrides:
size
in classjava.util.AbstractMap<java.lang.String,java.lang.String>
- Returns:
- the number of items
- See Also:
Storage.getLength()
-
-