|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectdk.rode.thesis.meta.util.KeyValue<K,V>
public class KeyValue<K,V>
A placeholder for a key with an associated value, where a non-null key or value can only be set once.
This class is not thread-safe!
| Field Summary | |
|---|---|
private K |
key
The key. |
private V |
value
The value, which can only be non-null if a key is also set. |
| Constructor Summary | |
|---|---|
KeyValue(K key)
Constructor. |
|
KeyValue(KeyValue<? extends K,? extends V> keyValue)
Copy constructor. |
|
KeyValue(K key,
V value)
Constructor. |
|
| Method Summary | |
|---|---|
KeyValue<K,V> |
copyKey()
Returns a new (key,value) placeholder with a value of null and a key value matching the key value of this (key,value) placeholder. |
boolean |
equals(Object o)
Returns true if o is a (key,value) placeholder
having a key that is equivalent to the key of this (key,value)
placeholder, regardless of the associated values, false if not. |
K |
getKey()
Returns the key of this (key,value) placeholder. |
V |
getValue()
Returns the value of this (key,value) placeholder. |
int |
hashCode()
Returns the hash code of this (key,value) placeholder. |
KeyValue<K,V> |
setKey(K key)
Sets the key of this (key,value) placeholder to key. |
KeyValue<K,V> |
setValue(V value)
Sets the value of this (key,value) placeholder to value. |
String |
toString()
Returns the string representation of this (key,value) placeholder. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private K key
Can be null if not set.
private V value
key is also set. Can be null if not set.
| Constructor Detail |
|---|
public KeyValue(K key)
key - The key; can be null.public KeyValue(KeyValue<? extends K,? extends V> keyValue)
keyValue - The (key,value) placeholder to copy; cannot be null.
NullPointerException - If keyValue is null.
public KeyValue(K key,
V value)
key - The key; can be null.value - The value; can be null, and not allowed to be non-null if
key is null.
IllegalStateException - If key is null and value
is not.| Method Detail |
|---|
public KeyValue<K,V> copyKey()
public boolean equals(Object o)
o is a (key,value) placeholder
having a key that is equivalent to the key of this (key,value)
placeholder, regardless of the associated values, false if not.
equals in class Objecto - The object to test; can be null.
public K getKey()
public V getValue()
key is set.public int hashCode()
hashCode in class Objectpublic KeyValue<K,V> setKey(K key)
key.
key - The key to set; can be null.
IllegalStateException - If a non-null key has already been
set.public KeyValue<K,V> setValue(V value)
value.
value - The value to set; can be null.
IllegalStateException - If a non-null key has not been set, or if a non-null
value has been set.public String toString()
toString in class Object
|
Gunni Rode / rode.dk | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||