de.knipp.rritoolkit
Class KVList

java.lang.Object
  extended by de.knipp.rritoolkit.KVList
All Implemented Interfaces:
java.lang.Iterable<KVList.Pair>

public class KVList
extends java.lang.Object
implements java.lang.Iterable<KVList.Pair>

class that represents a key-value list as used in DENIC Key Value messages for requests and part of responses. Please note that the comparison of keys is performed case-sensitive. Therefore, all keys are expected to be lower-case normalized.

Version:
$Revision: 14936 $
Author:
Klaus Malorny

Nested Class Summary
private static class KVList.EmptyIterator<E>
          small class implementing an iterator for no elements
static class KVList.Pair
          small class holding a key value pair (used for the iterator
private static class KVList.RemoveDisabledIterator<E>
          small wrapper class of an Iterator the suppresses the use of the remove method
private static class KVList.SingletonIterator<E>
          small class repesenting a singleton iterator
static interface KVList.Value
          public interface to values.
protected static class KVList.ValueImpl
          inner class that implements a value
 
Field Summary
private  java.util.LinkedHashMap<java.lang.String,KVList.ValueImpl> pairs
          all key value pairs
 
Constructor Summary
KVList()
          constructor
 
Method Summary
 void add(java.lang.String key, java.util.Collection<java.lang.String> col)
          add a collection of values for the given key
 void add(java.lang.String key, java.lang.String... values)
          add all values for the given key
 void add(java.lang.String key, java.lang.String value)
          add a value for the given key
 void clear(java.lang.String key)
          clear the given key
 boolean containsKey(java.lang.String key)
          return whether the given key exists
 java.lang.String[] getAll(java.lang.String key)
          return all strings associated with the key
 java.lang.String[] getAll(java.lang.String key, java.lang.String[] values)
          return all strings associated with the key
 int getCount(java.lang.String key)
          return the number of strings associated with a key
 java.lang.String getFirst(java.lang.String key)
          return the first string of the key
 java.util.Iterator<java.lang.String> getIterator(java.lang.String key)
          return an iterator over all strings of a key
 java.util.Iterator<java.lang.String> getKeyIterator()
          return an iterator over the keys
 java.util.List<java.lang.String> getList(java.lang.String key)
          return the strings associated with the key as a list
 java.util.Iterator<KVList.Pair> iterator()
          return an iterator over the key-value pairs
 void set(java.lang.String key, java.util.Collection<java.lang.String> col)
          set the given key, replacing all previous contents
 void set(java.lang.String key, java.lang.String... values)
          set the given key, replacing all previous contents
 void set(java.lang.String key, java.lang.String value)
          set the given key, replacing all previous contents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pairs

private java.util.LinkedHashMap<java.lang.String,KVList.ValueImpl> pairs
all key value pairs

Constructor Detail

KVList

public KVList()
constructor

Method Detail

add

public void add(java.lang.String key,
                java.lang.String value)
add a value for the given key

Parameters:
key - the key
value - the value

add

public void add(java.lang.String key,
                java.lang.String... values)
add all values for the given key

Parameters:
key - the key
values - the values

add

public void add(java.lang.String key,
                java.util.Collection<java.lang.String> col)
add a collection of values for the given key

Parameters:
key - the key
col - the values

set

public void set(java.lang.String key,
                java.lang.String value)
set the given key, replacing all previous contents

Parameters:
key - the key
value - the value

set

public void set(java.lang.String key,
                java.lang.String... values)
set the given key, replacing all previous contents

Parameters:
key - the key
values - the values

set

public void set(java.lang.String key,
                java.util.Collection<java.lang.String> col)
set the given key, replacing all previous contents

Parameters:
key - the key
col - the values

clear

public void clear(java.lang.String key)
clear the given key

Parameters:
key - the key

containsKey

public boolean containsKey(java.lang.String key)
return whether the given key exists

Parameters:
key - the key
Returns:
true if so

getCount

public int getCount(java.lang.String key)
return the number of strings associated with a key

Parameters:
key - the key
Returns:
the number of strings, 0 indicating that the key does not exist

getFirst

public java.lang.String getFirst(java.lang.String key)
return the first string of the key

Parameters:
key - the key
Returns:
the first string or null if the key does not exist

getAll

public java.lang.String[] getAll(java.lang.String key,
                                 java.lang.String[] values)
return all strings associated with the key

Parameters:
key - the key
values - the array where the strings are stored (may be null)
Returns:
the given array or a new array if the given one was too small or null. If the key does not exist, null is returned

getAll

public java.lang.String[] getAll(java.lang.String key)
return all strings associated with the key

Parameters:
key - the key
Returns:
the array with the strings or null

getList

public java.util.List<java.lang.String> getList(java.lang.String key)
return the strings associated with the key as a list

Parameters:
key - the key
Returns:
the list, which is empty in case that the key does not exist

getIterator

public java.util.Iterator<java.lang.String> getIterator(java.lang.String key)
return an iterator over all strings of a key

Parameters:
key - the key
Returns:
the iterator. If the key does not exist, the returned iterator does not enumerate any value

getKeyIterator

public java.util.Iterator<java.lang.String> getKeyIterator()
return an iterator over the keys

Returns:
the iterator

iterator

public java.util.Iterator<KVList.Pair> iterator()
return an iterator over the key-value pairs

Specified by:
iterator in interface java.lang.Iterable<KVList.Pair>
Returns:
the iterator


Copyright © 2005-2011 Knipp Medien und Kommunikation GmbH