/**
 * DictionaryPayload.java
 * Created Apr 26, 2006
 * Copyright (C) Tandberg Television 2006
 */
package com.tandbergtv.workflow.message;

import java.util.HashMap;
import java.util.Map;

/**
 * A type of payload comprised of key-value pairs
 * 
 * @author Sahil Verma
 */
public class DictionaryPayload {

	// Maintains the dictionary of key - value pairs that constitute the payload
	protected Map<String, String> map = new HashMap<String, String>();
	
	/**
	 * Constructor
	 */
	public DictionaryPayload() {
		super();
	}
	
	/**
	 * Get the value associated with the specified key maintained in the payload content.
	 * 
	 * @param name
	 *            The key name in the payload
	 *            
	 * @return The value associated with the key, or null if the key is not present in the payload.
	 */
	public String getValue(String name) {
		return this.map.get(name);
	}
	
	/**
	 * Adds a key-value pair to the payload content. Replaces any existing value associated with the
	 * key.
	 * 
	 * @param name
	 *            The key name in the payload
	 * @param value
	 *            the value associated with the key.
	 */
	public void putValue(String name, String value) {
		this.map.put(name, value);
	}

	/**
	 * Checks if the payload contains the key.
	 * 
	 * @param name
	 *            The key name
	 *
	 * @return true if the key is present in the payload, false otherwise.
	 */
	public boolean containsKey(String name) {
		return this.map.containsKey(name);
	}

	/**
	 * Removes the key from the payload content, and returns the key's previous associated value.
	 * 
	 * @param name
	 *            The name of the key
	 * @return The value associated with the key, or null if the key is not present in the payload.
	 */
	public String removeKey(String name) {
		return this.map.remove(name);
	}
	
	/**
	 * Method to get the entire map of key-value pairs.
	 * 
	 * @return A Map of the key-value pairs maintained by the payload.
	 */
	public Map<String, String> getAll() {
		/* FIXME Is this safe? Mebbe just clone it... */
		return this.map;
	}
}
