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

panda.io.resource.MapResource Maven / Gradle / Ivy

package panda.io.resource;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

/**
 * resource bundle for map
 */
public class MapResource extends AbstractResource {
	/**
	 * contents map
	 */
	protected final Map map;

	/**
	 * Constructor
	 * @param props content map
	 * @param parent parent resource object
	 * @param locale locale
	 */
	public MapResource(Properties props, Resource parent, Locale locale) {
		super(parent, locale);

		if (props == null) {
			throw new NullPointerException();
		}
		this.map = new HashMap();
		for (Entry en : props.entrySet()) {
			this.map.put(en.getKey().toString(), en.getValue());
		}
	}

	/**
	 * Constructor
	 * @param map content map
	 * @param parent parent resource object
	 * @param locale locale
	 */
	public MapResource(Map map, Resource parent, Locale locale) {
		super(parent, locale);

		if (map == null) {
			throw new NullPointerException();
		}
		this.map = map;
	}
	
	protected Object internalGetObject(String key) {
		if (key == null) {
			throw new NullPointerException();
		}
		return map.get(key);
	}

	/**
	 * Returns a Set of the keys contained
	 * only in this ResourceBundle.
	 *
	 * @return a Set of the keys contained only in this
	 *         ResourceBundle
	 */
	protected Set internalKeySet() {
		return map.keySet();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy