LimeWire Collection Component API

org.limewire.collection
Class KeyValue<K,V>

java.lang.Object
  extended by org.limewire.collection.KeyValue<K,V>
All Implemented Interfaces:
Map.Entry<K,V>

public class KeyValue<K,V>
extends Object
implements Map.Entry<K,V>

Stores a property key and its corresponding value pair. KeyValue implements Map.Entry, but there's no backing map.

    System.out.println(new KeyValue<String, String>("myKey", "myValue")); 

    Output:
        myKey = myValue


Constructor Summary
KeyValue()
          Default Constructor
KeyValue(K key, V value)
          Constructor
 
Method Summary
 boolean equals(Object o)
          Compares the instance of this class with another instance.
 K getKey()
          Returns the key(key) in the key value pair
 V getValue()
          Returns the value corresponding to this entry.
 int hashCode()
          Returns the hash code value for this map entry.
 void set(K key, V value)
          Sets the key and value fields
 V setValue(V value)
          Replaces the value corresponding to this entry with the specified value.
 String toString()
          Converts the key Value pair into a string representation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

KeyValue

public KeyValue(K key,
                V value)
Constructor

Parameters:
key - key of the property
value - corresponding value of the property

KeyValue

public KeyValue()
Default Constructor

Method Detail

set

public void set(K key,
                V value)
Sets the key and value fields

Parameters:
key - key of the property
value - corresponding value of the property

equals

public boolean equals(Object o)
Compares the instance of this class with another instance. Returns true, if the key field is same, regardless of the value.

Specified by:
equals in interface Map.Entry<K,V>
Overrides:
equals in class Object
Parameters:
o - Another instance of the KeyValue class to which it has to be compared.

toString

public String toString()
Converts the key Value pair into a string representation

Overrides:
toString in class Object

getKey

public K getKey()
Returns the key(key) in the key value pair

Specified by:
getKey in interface Map.Entry<K,V>
Returns:
the key(key) in the key value pair

getValue

public V getValue()
Returns the value corresponding to this entry.

Specified by:
getValue in interface Map.Entry<K,V>
Returns:
the value corresponding to this entry.

setValue

public V setValue(V value)
Replaces the value corresponding to this entry with the specified value.

Specified by:
setValue in interface Map.Entry<K,V>
Parameters:
value - new value to be stored in this entry.
Returns:
old value corresponding to the entry.

hashCode

public int hashCode()
Returns the hash code value for this map entry. The hash code of a map entry e is defined to be:
    (e.getKey()==null   ? 0 : e.getKey().hashCode()) ^
    (e.getValue()==null ? 0 : e.getValue().hashCode())
 
This ensures that e1.equals(e2) implies that e1.hashCode()==e2.hashCode() for any two Entries e1 and e2, as required by the general contract of Object.hashCode.

Specified by:
hashCode in interface Map.Entry<K,V>
Overrides:
hashCode in class Object
Returns:
the hash code value for this map entry.
See Also:
Object.hashCode(), Object.equals(Object), equals(Object)

LimeWire Collection Component API

Copyright © 2008 Lime Wire LLC. All Rights Reserved.