org.jminor.common.model.valuemap
Class StringProvider<K>

java.lang.Object
  extended by org.jminor.common.model.valuemap.StringProvider<K>
Type Parameters:
K - the type of the map keys
All Implemented Interfaces:
Serializable, ValueMap.ToString<K>

public final class StringProvider<K>
extends Object
implements ValueMap.ToString<K>, Serializable

Provides String representations of ValueMap objects.
Given a ValueMap named valueMap containing the following mappings:

 "key1" -> value1
 "key2" -> value2
 "key3" -> value3
 "key4" -> {ValueMap instance with a single mapping "refKey" -> refValue}
 
StringProvider provider = new StringProvider();
provider.addText("key1=").addValue("key1").addText(", key3='").addValue("key3")
.addText("' referenced value=").addReferencedValue("key4", "refKey");
System.out.println(provider.toString(valueMap));

outputs the following String:

key1=value1, key3='value3' referenced value=refValue

See Also:
Serialized Form

Constructor Summary
StringProvider()
          Instantiates a new StringProvider instance
StringProvider(K key)
          Instantiates a new StringProvider instance, with the value mapped to the given key
 
Method Summary
 StringProvider<K> addFormattedValue(K key, Format format)
          Adds the value mapped to the given key to this StringProvider
 StringProvider<K> addReferencedValue(K referenceKey, K key)
          Adds the value mapped to the given key in the ValueMap instance mapped to the given foreignKeyPropertyID to this StringProvider
 StringProvider<K> addText(String text)
          Adds the given static text to this StringProvider
 StringProvider<K> addValue(K key)
          Adds the value mapped to the given key to this StringProvider
 String toString(ValueMap<K,?> valueMap)
          Builds a string from the given value map
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringProvider

public StringProvider()
Instantiates a new StringProvider instance


StringProvider

public StringProvider(K key)
Instantiates a new StringProvider instance, with the value mapped to the given key

Parameters:
key - the key
Method Detail

toString

public String toString(ValueMap<K,?> valueMap)
Builds a string from the given value map

Specified by:
toString in interface ValueMap.ToString<K>
Parameters:
valueMap - the value map
Returns:
a string representation of the given value map

addValue

public StringProvider<K> addValue(K key)
Adds the value mapped to the given key to this StringProvider

Parameters:
key - the key
Returns:
this StringProvider instance

addFormattedValue

public StringProvider<K> addFormattedValue(K key,
                                           Format format)
Adds the value mapped to the given key to this StringProvider

Parameters:
key - the key
format - the Format to use when appending the value
Returns:
this StringProvider instance

addReferencedValue

public StringProvider<K> addReferencedValue(K referenceKey,
                                            K key)
Adds the value mapped to the given key in the ValueMap instance mapped to the given foreignKeyPropertyID to this StringProvider

Parameters:
referenceKey - the reference key
key - the key
Returns:
this StringProvider instance

addText

public StringProvider<K> addText(String text)
Adds the given static text to this StringProvider

Parameters:
text - the text to add
Returns:
this StringProvider instance