Class PairMapEntry<K,V>

java.lang.Object
net.cscott.jutil.AbstractMapEntry<K,V>
net.cscott.jutil.PairMapEntry<K,V>
All Implemented Interfaces:
Map.Entry<K,V>

public class PairMapEntry<K,V> extends AbstractMapEntry<K,V>
PairMapEntry is the easiest implementation of a Map.Entry ever: a pair! Basically saves coders the drugery of writing an inner class at the expense of an import statement. Note that PairMapEntrys are mutable: setValue(Object) is defined in this class. Using null as a key or value will not cause this class or AbstractMapEntry to fail, but be warned that several Map implementations do not like nulls in their internal structures.
Author:
Felix S. Klock II <pnkfelix@mit.edu>
  • Constructor Details

    • PairMapEntry

      public PairMapEntry(K key, V value)
      Creates a PairMapEntry.
  • Method Details

    • getKey

      public K getKey()
      Description copied from class: AbstractMapEntry
      Returns the key corresponding to this entry.
      Specified by:
      getKey in interface Map.Entry<K,V>
      Specified by:
      getKey in class AbstractMapEntry<K,V>
    • getValue

      public V getValue()
      Description copied from class: AbstractMapEntry
      Returns the value corresponding to this entry. If the mapping has been removed from the backing map (by the iterator's remove() operation), the results of this call are undefined.
      Specified by:
      getValue in interface Map.Entry<K,V>
      Specified by:
      getValue in class AbstractMapEntry<K,V>
    • setKey

      protected K setKey(K newKey)
      For use in subclass implementations *only*.
    • setValue

      public V setValue(V newValue)
      Description copied from class: AbstractMapEntry
      Replaces the value corresponding to this entry with the specified value (optional operation). (Writes through to the map.) The behavior of this call is undefined if the mapping has already been removed from the map (by the iterator's remove() operation).
      Specified by:
      setValue in interface Map.Entry<K,V>
      Overrides:
      setValue in class AbstractMapEntry<K,V>
      Returns:
      old value corresponding to entry.