package com.googlecode.objectify.impl;

import com.googlecode.objectify.Key;
import com.googlecode.objectify.util.ResultNow;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * The basic session cache.  A lot easier than passing the generic arguments around!
 *
 * @author Jeff Schnitzer <jeff@infohazard.org>
 */
public class Session
{
	/** */
	private static final Logger log = Logger.getLogger(Session.class.getName());

	/** */
	private Map<Key<?>, SessionValue<?>> map = new HashMap<>();

	/**
	 * Add/overwrite a SV.
	 */
	public void add(Key<?> key, SessionValue<?> value) {
		if (log.isLoggable(Level.FINEST))
			log.finest("Adding to session: " + key + " -> " + value.getResult());

		map.put(key, value);
	}

	/**
	 * Convenience method
	 */
	public void addValue(Key<?> key, Object value) {
		add(key, new SessionValue<>(new ResultNow<Object>(value)));
	}

	/** Add all entries in the other session to this one */
	public void addAll(Session other) {
		if (log.isLoggable(Level.FINEST))
			log.finest("Adding all values to session: " + other.map.keySet());

		map.putAll(other.map);
	}

	/** */
	@SuppressWarnings("unchecked")
	public <T> SessionValue<T> get(Key<T> key) {
		return (SessionValue<T>)map.get(key);
	}

	/** */
	public boolean contains(Key<?> key) {
		return map.containsKey(key);
	}

	/** */
	public void clear() {
		if (log.isLoggable(Level.FINEST))
			log.finest("Clearing session");

		map.clear();
	}

	/** Convenient for debugging */
	@Override
	public String toString() {
		return map.toString();
	}
}

@@ -162,24 +162,46 @@
 a.util.Map;%0A
+import java.util.Set;%0A
 import java.
@@ -1615,11 +1615,225 @@
 ng();%0A%09%7D
+%0A%0A%09/**%0A%09 * @return all the keys currently in the session. If you really want this data, subclass ObjectifyImpl and%0A%09 * use the protected getSession() method.%0A%09 */%0A%09public Set%3CKey%3C?%3E%3E keys() %7B return map.keySet(); %7D
 %0A%7D%0A

Add method Session.keys()