Class MapEntry<K,​V>

  • Type Parameters:
    K - the key type
    V - the value type
    All Implemented Interfaces:
    java.io.Serializable, java.util.Map.Entry<K,​V>

    public final class MapEntry<K,​V>
    extends java.lang.Object
    implements java.util.Map.Entry<K,​V>, java.io.Serializable
    An immutable key-value object for constructing map instances programmatically.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private K key  
      private static long serialVersionUID  
      private V value  
    • Constructor Summary

      Constructors 
      Constructor Description
      MapEntry​(K key, V value)
      Construct a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <K,​V>
      java.util.Map<K,​V>
      addTo​(java.util.Map<K,​V> map, MapEntry<? extends K,​? extends V>... entries)
      Add entries to a map.
      static <K,​V>
      MapEntry<K,​V>
      entry​(K key, V value)
      Construct a new instance.
      boolean equals​(java.lang.Object obj)
      Compare this entry with another.
      boolean equals​(MapEntry<?,​?> obj)
      Compare this entry with another.
      K getKey()
      Get the map key.
      V getValue()
      Get the map value.
      int hashCode()
      Get the hash code of this object.
      V setValue​(V value)
      Unsupported operation.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • key

        private final K key
      • value

        private final V value
    • Constructor Detail

      • MapEntry

        public MapEntry​(K key,
                        V value)
        Construct a new instance.
        Parameters:
        key - the map key
        value - the map value
    • Method Detail

      • entry

        public static <K,​V> MapEntry<K,​V> entry​(K key,
                                                            V value)
        Construct a new instance.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        key - the map key
        value - the map value
        Returns:
        the entry
      • getKey

        public K getKey()
        Get the map key.
        Specified by:
        getKey in interface java.util.Map.Entry<K,​V>
        Returns:
        the map key
      • getValue

        public V getValue()
        Get the map value.
        Specified by:
        getValue in interface java.util.Map.Entry<K,​V>
        Returns:
        the map value
      • setValue

        public V setValue​(V value)
        Unsupported operation.
        Specified by:
        setValue in interface java.util.Map.Entry<K,​V>
        Parameters:
        value - ignored
        Returns:
        nothing
        Throws:
        java.lang.UnsupportedOperationException - always
      • equals

        public boolean equals​(java.lang.Object obj)
        Compare this entry with another.
        Specified by:
        equals in interface java.util.Map.Entry<K,​V>
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the other entry
        Returns:
        true if this object equals the other MapEntry instance, false otherwise
      • equals

        public boolean equals​(MapEntry<?,​?> obj)
        Compare this entry with another.
        Parameters:
        obj - the other entry
        Returns:
        true if this object equals the other MapEntry instance, false otherwise
      • hashCode

        public int hashCode()
        Get the hash code of this object.
        Specified by:
        hashCode in interface java.util.Map.Entry<K,​V>
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code
      • addTo

        public static <K,​V> java.util.Map<K,​V> addTo​(java.util.Map<K,​V> map,
                                                                 MapEntry<? extends K,​? extends V>... entries)
        Add entries to a map.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map - the map to add to
        entries - the entries to add
        Returns:
        the map