All Downloads are FREE. Search and download functionalities are using the official Maven repository.

base.MapQueryResult Maven / Gradle / Ivy

/**
 * Creative commons Attribution-NonCommercial license.
 *
 * http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB
 *
 * NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 */
package base;

import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import base.json.Json;


public class MapQueryResult implements QueryResult {

	private Map values;

	public MapQueryResult(Map values) {
		this.values = values;
	}

	public MapQueryResult() {
	}

	public String toString() {
		return toJson();
	}

	public String toJson() {
		return Json.toJson(values);
	}

	public Map getValues() {
		return values;
	}

	public void setValues(Map values) {
		this.values = values;
	}

	public Object getValue(String key) {
		return values.get(key);
	}

	@SuppressWarnings("unchecked")
	public List getValues(String key) {
		return (List) values.get(key);
	}

	public void setValue(String key, Object value) {
		if(key == null) {
			throw new IllegalArgumentException("Must specify a valid key");
		}
		if(values == null) {
			values = new Hashtable<>();
		}
		if(value == null) {
			values.remove(key);
			return;
		}
		values.put(key, value);
	}

}