ikrs.util
Class KeyValuePair<K,V>

java.lang.Object
  extended by ikrs.util.KeyValuePair<K,V>
Direct Known Subclasses:
KeyValueStringPair

public class KeyValuePair<K,V>
extends java.lang.Object

A very simple key-value-pair implementation.


Constructor Summary
KeyValuePair(K key, V value)
          Construct a new key-value-pair.
 
Method Summary
 K getKey()
          Get the key from this pair.
 V getValue()
          Get the value from this pair.
static KeyValuePair<java.lang.String,java.lang.String> splitLine(java.lang.String line, java.lang.String separator, boolean trim)
          This method splits the given string into a key-value tuple using the passed separator.
 java.lang.String toString()
          Converts this key-value-pair into a human readable form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

KeyValuePair

public KeyValuePair(K key,
                    V value)
Construct a new key-value-pair. Both params may be null.

Parameters:
key - The key (may be null).
value - The value (may be null).
Method Detail

getKey

public K getKey()
Get the key from this pair.

Returns:
The key from this pair.

getValue

public V getValue()
Get the value from this pair.

Returns:
The value from this pair.

toString

public java.lang.String toString()
Converts this key-value-pair into a human readable form.

Overrides:
toString in class java.lang.Object

splitLine

public static KeyValuePair<java.lang.String,java.lang.String> splitLine(java.lang.String line,
                                                                        java.lang.String separator,
                                                                        boolean trim)
This method splits the given string into a key-value tuple using the passed separator. If the line is null the method returns null. If the line is empty the method returns (null, null). If the separator is null or empty the method returns a key-value-pair with null entries. If there is no separator present in the string the method returns a key-value-pair with key==line and value==null. If there is a separator the key/value entries will have the respective value or be an empty string. Examples: - a=b results in (a,b) - a= results in (a, "") - =b results in ("", b) - null results in null - "" results in ("", null) - a results in (a, "") - = results in ("", "")

Parameters:
line - The line to split.
separator - The separator string that separates the key and its value.
trim - If set to true the method will trim keys and values (remove whitespace from the begining and end).
Returns:
A pair containing the split key and values from the passed string.