com.samskivert.util
Class KeyValue<K extends Comparable<? super K>,V>

java.lang.Object
  extended by com.samskivert.util.KeyValue<K,V>
All Implemented Interfaces:
Comparable<KeyValue<K,V>>

public class KeyValue<K extends Comparable<? super K>,V>
extends Object
implements Comparable<KeyValue<K,V>>

Used to wrap a key/value pair into an object that behaves like the key but holds on to the value. This might be used to maintain a list of objects sorted by some unrelated key in a SortableArrayList. For example:

 SortableArrayList list = new SortableArrayList();
 Integer key = new Integer(4);
 Object value = ...;
 KeyValue kval = new KeyValue(key, value);
 list.insertSorted(kval);
 // ...
 Integer key = new Integer(4);
 int oidx = list.indexOf(key);
 Object value = (oidx == -1) ? null : list.get(oidx);
 


Field Summary
 K key
          The key in this key/value pair.
 V value
          The value in this key/value pair.
 
Constructor Summary
KeyValue(K key, V value)
          Creates a key/value pair with the specified key and value.
 
Method Summary
 int compareTo(KeyValue<K,V> other)
           
 boolean equals(Object other)
           
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

key

public K extends Comparable<? super K> key
The key in this key/value pair.


value

public V value
The value in this key/value pair.

Constructor Detail

KeyValue

public KeyValue(K key,
                V value)
Creates a key/value pair with the specified key and value.

Method Detail

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(KeyValue<K,V> other)
Specified by:
compareTo in interface Comparable<KeyValue<K extends Comparable<? super K>,V>>


Copyright © 2000-2008 Michael Bayne. All Rights Reserved.