Class JsMap<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    Direct Known Subclasses:
    JreJsMap

    @JsType(isNative=true,
            name="Map",
            namespace="<global>")
    public class JsMap<K,​V>
    extends Object
    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
    • Constructor Detail

      • JsMap

        public JsMap()
        Creates a new instance.
    • Method Detail

      • set

        public JsMap<K,​V> set​(K key,
                                    V value)
        Sets a value in this map, overwriting any previous mapping if present.
        Parameters:
        key - the key to set
        value - the value to set
        Returns:
        this map, for chaining.
      • get

        public V get​(K key)
        Gets the value mapped for the given key. Returns null if there is no mapping or if the key is explicitly mapped to null.
        Parameters:
        key - the key to get a value for
        Returns:
        the value corresponding to the given key; or null there is no mapping.
      • has

        public boolean has​(K key)
        Checks whether this map contains a mapping for the given key.
        Parameters:
        key - the key to check
        Returns:
        true if there is a mapping for the key; false if there is no mapping
      • delete

        public boolean delete​(K key)
        Removes the mapping for a given key.
        Parameters:
        key - the key for which to remove the mapping
        Returns:
        true if the map contained a mapping for the given key prior to calling this method; false if no mapping was present
      • clear

        public void clear()
        Removes all mappings from this map.
      • forEach

        public void forEach​(JsMap.ForEachCallback<K,​V> callback)
        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:
        true if the map is empty, false otherwise
      • mapValues

        @JsOverlay
        public final JsArray<V> mapValues()
        Returns an array of the values in this JsMap.
        Returns:
        an array of the values in the map