Class JsMap<K,V>
java.lang.Object
com.vaadin.client.flow.collection.JsMap<K,V>
- Type Parameters:
K- the key typeV- the value type
- Direct Known Subclasses:
JreJsMap
Native JS Map interface with an alternative implementation for JRE usage. Use
JsCollections.map() to create an appropriate instance.- Since:
- 1.0
- Author:
- Vaadin Ltd
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface for iterating all the entries in aJsMap. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all mappings from this map.booleanRemoves the mapping for a given key.voidforEach(JsMap.ForEachCallback<K, V> callback) Invokes the provided callback for each mapping in this map.Gets the value mapped for the given key.booleanChecks whether this map contains a mapping for the given key.final booleanisEmpty()Checks if the map is empty (size == 0).Returns an array of the values in thisJsMap.Sets a value in this map, overwriting any previous mapping if present.intsize()Gets the number of entries in this map.
-
Constructor Details
-
JsMap
public JsMap()Creates a new instance.
-
-
Method Details
-
set
Sets a value in this map, overwriting any previous mapping if present.- Parameters:
key- the key to setvalue- the value to set- Returns:
- this map, for chaining.
-
get
Gets the value mapped for the given key. Returnsnullif there is no mapping or if the key is explicitly mapped tonull.- Parameters:
key- the key to get a value for- Returns:
- the value corresponding to the given key; or
nullthere is no mapping.
-
has
Checks whether this map contains a mapping for the given key.- Parameters:
key- the key to check- Returns:
trueif there is a mapping for the key;falseif there is no mapping
-
delete
Removes the mapping for a given key.- Parameters:
key- the key for which to remove the mapping- Returns:
trueif the map contained a mapping for the given key prior to calling this method;falseif no mapping was present
-
clear
public void clear()Removes all mappings from this map. -
forEach
Invokes the provided callback for each mapping in this map.Note that this is the only way of iteration supported in IE11.
- Parameters:
callback- the callback to invoke for each mapping
-
size
@JsProperty(name="size") public int size()Gets the number of entries in this map.- Returns:
- the entry count
-
isEmpty
@JsOverlay public final boolean isEmpty()Checks if the map is empty (size == 0).- Returns:
trueif the map is empty,falseotherwise
-
mapValues
Returns an array of the values in thisJsMap.- Returns:
- an array of the values in the map
-