JUtil

net.cscott.jutil
Class PairMapEntry<K,V>

java.lang.Object
  extended by net.cscott.jutil.AbstractMapEntry<K,V>
      extended by 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.

Version:
$Id: PairMapEntry.java,v 1.3 2006-10-30 20:14:41 cananian Exp $
Author:
Felix S. Klock II

Constructor Summary
PairMapEntry(K key, V value)
          Creates a PairMapEntry.
 
Method Summary
 K getKey()
          Returns the key corresponding to this entry.
 V getValue()
          Returns the value corresponding to this entry.
protected  K setKey(K newKey)
          For use in subclass implementations *only*.
 V setValue(V newValue)
          Replaces the value corresponding to this entry with the specified value (optional operation).
 
Methods inherited from class net.cscott.jutil.AbstractMapEntry
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PairMapEntry

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

Method Detail

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.

JUtil

Copyright (c) 2006 C. Scott Ananian