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/sessionStorageas 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
nullvalues 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 voidclear()Removes all items from the Storage.booleancontainsKey(java.lang.Object key)Returnstrueif the Storage contains the specified key,falseotherwise.booleancontainsValue(java.lang.Object value)Returnstrueif the Storage contains the specified value,falseotherwise (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.Stringget(java.lang.Object key)Returns the value associated with the specified key in the Storage.java.lang.Stringput(java.lang.String key, java.lang.String value)Adds (or overwrites) a new key/value pair in the Storage.java.lang.Stringremove(java.lang.Object key)Removes the key/value pair from the Storage.intsize()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:
clearin interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
clearin classjava.util.AbstractMap<java.lang.String,java.lang.String>- See Also:
Storage.clear()
-
containsKey
public boolean containsKey(java.lang.Object key)
Returnstrueif the Storage contains the specified key,falseotherwise.- Specified by:
containsKeyin interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
containsKeyin classjava.util.AbstractMap<java.lang.String,java.lang.String>
-
containsValue
public boolean containsValue(java.lang.Object value)
Returnstrueif the Storage contains the specified value,falseotherwise (or if the specified key isnull).- Specified by:
containsValuein interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
containsValuein 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:
entrySetin interfacejava.util.Map<java.lang.String,java.lang.String>- Specified by:
entrySetin 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:
getin interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
getin 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:
putin interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
putin 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:
removein interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
removein 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 -
nullif 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:
sizein interfacejava.util.Map<java.lang.String,java.lang.String>- Overrides:
sizein classjava.util.AbstractMap<java.lang.String,java.lang.String>- Returns:
- the number of items
- See Also:
Storage.getLength()
-
-