Package: groovy.lang

## [Java] Class SpreadMap

- groovy.lang.SpreadMap

-     public class SpreadMap
      extends HashMap

  Helper to turn a list with an even number of elements into a Map.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `SpreadMap(Object[] values)` Creates an immutable spread map from alternating key/value entries.
    `SpreadMap(Map map)` Creates an immutable spread map from an existing map.
    `SpreadMap(List list)` Since: 1.8.0

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public boolean` | `equals(Object that)` Compares the specified object with this map for equality. Returns `true` if the given object is also a map and the two maps represent the same mappings. More formally, two maps `m1` and `m2` represent the same mappings if `m1.entrySet().equals(m2.entrySet())`. This ensures that the `equals` method works properly across different implementations of the `Map` interface. Implementation Requirements: This implementation first checks if the specified object is this map; if so it returns `true`. Then, it checks if the specified object is a map whose size is identical to the size of this map; if not, it returns `false`. If so, it iterates over this map's `entrySet` collection, and checks that the specified map contains each mapping that this map contains. If the specified map fails to contain such a mapping, `false` is returned. If the iteration completes, `true` is returned. Parameters: `o` - object to be compared for equality with this map Returns: `true` if the specified object is equal to this map
    `` | `public boolean` | `equals(SpreadMap that)` Compares this spread map with another spread map using Groovy equality.
    `` | `public int` | `hashCode()` Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's `entrySet()` view. This ensures that `m1.equals(m2)` implies that `m1.hashCode()==m2.hashCode()` for any two maps `m1` and `m2`, as required by the general contract of Object.hashCode. Implementation Requirements: This implementation iterates over `entrySet()`, calling Map.Entry#hashCode on each element (entry) in the set, and adding up the results. Returns: the hash code value for this map See Also: Map.Entry#hashCode() Object.equals Set.equals
    `` | `public Object` | `put(Object key, Object value)` Always throws because spread maps are immutable.
    `` | `public void` | `putAll(Map t)` Always throws because spread maps are immutable.
    `` | `public Object` | `remove(Object key)` Always throws because spread maps are immutable.
    `` | `public String` | `toString()` Returns: the string expression of `this`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class HashMap` | `clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getClass, getOrDefault, hashCode, isEmpty, keySet, merge, notify, notifyAll, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, toString, values, wait, wait, wait`

- - ### Constructor Detail

    - #### public SpreadMap(Object[] values)

      Creates an immutable spread map from alternating key/value entries.

      Parameters:
        `values` - alternating keys and values

    - #### public SpreadMap(Map map)

      Creates an immutable spread map from an existing map.

      Parameters:
        `map` - the source map

    - #### public SpreadMap(List list)

      Since:
        1.8.0
      Parameters:
        `list` - the list to make spreadable

  - ### Method Detail

    - #### public boolean equals(Object that)

      Compares the specified object with this map for equality. Returns `true` if the given object is also a map and the two maps represent the same mappings. More formally, two maps `m1` and `m2` represent the same mappings if `m1.entrySet().equals(m2.entrySet())`. This ensures that the `equals` method works properly across different implementations of the `Map` interface.

      Implementation Requirements:
        This implementation first checks if the specified object is this map; if so it returns `true`. Then, it checks if the specified object is a map whose size is identical to the size of this map; if not, it returns `false`. If so, it iterates over this map's `entrySet` collection, and checks that the specified map contains each mapping that this map contains. If the specified map fails to contain such a mapping, `false` is returned. If the iteration completes, `true` is returned.
      Parameters:
        `o` - object to be compared for equality with this map
      Returns:
        `true` if the specified object is equal to this map

    - #### public boolean equals(SpreadMap that)

      Compares this spread map with another spread map using Groovy equality.

      Parameters:
        `that` - the other spread map
      Returns:
        `true` if the maps are equal

    - #### public int hashCode()

      Returns the hash code value for this map. The hash code of a map is defined to be the sum of the hash codes of each entry in the map's `entrySet()` view. This ensures that `m1.equals(m2)` implies that `m1.hashCode()==m2.hashCode()` for any two maps `m1` and `m2`, as required by the general contract of Object.hashCode.

      Implementation Requirements:
        This implementation iterates over `entrySet()`, calling Map.Entry#hashCode on each element (entry) in the set, and adding up the results.
      Returns:
        the hash code value for this map
      See Also:
        Map.Entry#hashCode()
        Object.equals
        Set.equals

    - #### public Object put(Object key, Object value)

      Always throws because spread maps are immutable.

      Parameters:
        `key` - the key to add
        `value` - the value to add
      Returns:
        never returns normally

    - #### public void putAll(Map t)

      Always throws because spread maps are immutable.

      Parameters:
        `t` - the entries to add

    - #### public Object remove(Object key)

      Always throws because spread maps are immutable.

      Parameters:
        `key` - the key to remove
      Returns:
        never returns normally

    - #### public String toString()

      Returns:
        the string expression of `this`