Class DefaultKeyedValue<K extends java.lang.Comparable<K>>

  • Type Parameters:
    K - the key type (String is a good default).
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, PublicCloneable, KeyedValue<K>, Value

    public class DefaultKeyedValue<K extends java.lang.Comparable<K>>
    extends java.lang.Object
    implements KeyedValue<K>, java.lang.Cloneable, PublicCloneable, java.io.Serializable
    A (key, value) pair. This class provides a default implementation of the KeyedValue interface.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private K key
      The key.
      private static long serialVersionUID
      For serialization.
      private java.lang.Number value
      The value.
    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultKeyedValue​(K key, java.lang.Number value)
      Creates a new (key, value) item.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()
      Returns a clone.
      boolean equals​(java.lang.Object obj)
      Tests this key-value pair for equality with an arbitrary object.
      K getKey()
      Returns the key.
      java.lang.Number getValue()
      Returns the value.
      int hashCode()
      Returns a hash code.
      void setValue​(java.lang.Number value)
      Sets the value.
      java.lang.String toString()
      Returns a string representing this instance, primarily useful for debugging.
      • Methods inherited from class java.lang.Object

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

      • serialVersionUID

        private static final long serialVersionUID
        For serialization.
        See Also:
        Constant Field Values
      • key

        private final K extends java.lang.Comparable<K> key
        The key.
      • value

        private java.lang.Number value
        The value.
    • Constructor Detail

      • DefaultKeyedValue

        public DefaultKeyedValue​(K key,
                                 java.lang.Number value)
        Creates a new (key, value) item.
        Parameters:
        key - the key (should be immutable, null not permitted).
        value - the value (null permitted).
    • Method Detail

      • getKey

        public K getKey()
        Returns the key.
        Specified by:
        getKey in interface KeyedValue<K extends java.lang.Comparable<K>>
        Returns:
        The key (never null).
      • getValue

        public java.lang.Number getValue()
        Returns the value.
        Specified by:
        getValue in interface Value
        Returns:
        The value (possibly null).
      • setValue

        public void setValue​(java.lang.Number value)
        Sets the value.
        Parameters:
        value - the value (null permitted).
      • equals

        public boolean equals​(java.lang.Object obj)
        Tests this key-value pair for equality with an arbitrary object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object (null permitted).
        Returns:
        A boolean.
      • hashCode

        public int hashCode()
        Returns a hash code.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A hash code.
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a clone. It is assumed that both the key and value are immutable objects, so only the references are cloned, not the objects themselves.
        Specified by:
        clone in interface PublicCloneable
        Overrides:
        clone in class java.lang.Object
        Returns:
        A clone.
        Throws:
        java.lang.CloneNotSupportedException - Not thrown by this class, but subclasses (if any) might.
      • toString

        public java.lang.String toString()
        Returns a string representing this instance, primarily useful for debugging.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string.