Class NameValuePair<N,V>

java.lang.Object
com.globalmentor.model.DefaultNamed<N>
com.globalmentor.model.NameValuePair<N,V>
All Implemented Interfaces:
IDed<N>, Named<N>, Valued<V>
Direct Known Subclasses:
MediaType.Parameter, NameValuePairMapEntry, URIQueryParameter

public class NameValuePair<N,V> extends DefaultNamed<N> implements IDed<N>, Valued<V>
A convenience tuple for a name and a value. The class allows identification (though not necessarily unique) through its name object.
Author:
Garret Wilson
  • Constructor Details

    • NameValuePair

      public NameValuePair(N newName, V newValue)
      Constructor specifying the name and value.
      Parameters:
      newName - The object's new name.
      newValue - The object's new value
  • Method Details

    • getValue

      public V getValue()
      Specified by:
      getValue in interface Valued<N>
      Returns:
      The value of the object.
    • getID

      public N getID()
      Specified by:
      getID in interface IDed<N>
      Returns:
      The name of the name-value pair, allowing identification.
    • fromMapEntry

      public static <MEK, MEV> NameValuePair<MEK,MEV> fromMapEntry(@Nonnull Map.Entry<MEK,MEV> mapEntry)
      Static factory method to create a name-value pair from a map entry copy.
      Type Parameters:
      MEK - The type of map entry key.
      MEV - The type of map entry value.
      Parameters:
      mapEntry - The map entry the values of which to use in creating this name/value pair.
      Returns:
      A name-value pair from the map entry.
      Throws:
      NullPointerException - if the given map entry is null.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class DefaultNamed<N>
      Returns:
      A hashcode value composed from the name.
    • equals

      public boolean equals(Object object)
      Determines if the given object is another name value pair with the same name and value.
      Overrides:
      equals in class DefaultNamed<N>
      Parameters:
      object - The object with which to compare this name/value pair.
      Returns:
      true if this name/value pair equals that specified in object.
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class DefaultNamed<N>
      Returns:
      A string representation of this object in the format "name=\"value\"".