// Path: siden-core/src/main/java/ninja/siden/AttributeContainer.java
// public interface AttributeContainer extends Iterable<AttributeContainer.Attr> {
// 
// 	/**
// 	 * @param key
// 	 *            attribute name
// 	 * @param newone
// 	 *            new attribute
// 	 * @return existing value
// 	 */
// 	<T> Optional<T> attr(String key, T newone);
// 
// 	<T> Optional<T> attr(String key);
// 
// 	/**
// 	 * @param key
// 	 * @return existing value
// 	 */
// 	<T> Optional<T> remove(String key);
// 
// 	interface Attr {
// 		String name();
// 
// 		<T> T value();
// 
// 		<T> T remove();
// 	}
// }
// 
// Path: siden-core/src/main/java/ninja/siden/Session.java
// public interface Session extends AttributeContainer {
// 
// 	String id();
// 
// 	void invalidate();
// 
// 	Session regenerate();
// 
// 	io.undertow.server.session.Session raw();
// }


import io.undertow.server.HttpServerExchange;
import io.undertow.server.session.SessionConfig;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Formatter;
import java.util.Iterator;
import java.util.Optional;
import ninja.siden.AttributeContainer;
import ninja.siden.Session;
/*
 * Copyright 2014 SATO taichi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ninja.siden.internal;




/**
 * @author taichi
 */
public class SidenSession implements Session {

	final HttpServerExchange exchange;
	final io.undertow.server.session.Session delegate;

	public SidenSession(HttpServerExchange exchange,
			io.undertow.server.session.Session delegate) {
		this.exchange = exchange;
		this.delegate = delegate;
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> Optional<T> attr(String key, T newone) {
		return Optional.ofNullable((T) this.delegate.setAttribute(key, newone));
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> Optional<T> attr(String key) {
		return Optional.ofNullable((T) this.delegate.getAttribute(key));
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> Optional<T> remove(String key) {
		return Optional.ofNullable((T) this.delegate.removeAttribute(key));
	}

	@Override
	public Iterator<Attr> iterator() {
		Iterator<String> names = this.delegate.getAttributeNames().iterator();
// Path: siden-core/src/main/java/ninja/siden/AttributeContainer.java
// public interface AttributeContainer extends Iterable<AttributeContainer.Attr> {
// 
// 	/**
// 	 * @param key
// 	 *            attribute name
// 	 * @param newone
// 	 *            new attribute
// 	 * @return existing value
// 	 */
// 	<T> Optional<T> attr(String key, T newone);
// 
// 	<T> Optional<T> attr(String key);
// 
// 	/**
// 	 * @param key
// 	 * @return existing value
// 	 */
// 	<T> Optional<T> remove(String key);
// 
// 	interface Attr {
// 		String name();
// 
// 		<T> T value();
// 
// 		<T> T remove();
// 	}
// }
// 
// Path: siden-core/src/main/java/ninja/siden/Session.java
// public interface Session extends AttributeContainer {
// 
// 	String id();
// 
// 	void invalidate();
// 
// 	Session regenerate();
// 
// 	io.undertow.server.session.Session raw();
// }


// Path: siden-core/src/main/java/ninja/siden/internal/SidenSession.java
import io.undertow.server.HttpServerExchange;
import io.undertow.server.session.SessionConfig;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Formatter;
import java.util.Iterator;
import java.util.Optional;
import ninja.siden.AttributeContainer;
import ninja.siden.Session;

/*
 * Copyright 2014 SATO taichi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ninja.siden.internal;




/**
 * @author taichi
 */
public class SidenSession implements Session {

	final HttpServerExchange exchange;
	final io.undertow.server.session.Session delegate;

	public SidenSession(HttpServerExchange exchange,
			io.undertow.server.session.Session delegate) {
		this.exchange = exchange;
		this.delegate = delegate;
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> Optional<T> attr(String key, T newone) {
		return Optional.ofNullable((T) this.delegate.setAttribute(key, newone));
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> Optional<T> attr(String key) {
		return Optional.ofNullable((T) this.delegate.getAttribute(key));
	}

	@Override
	@SuppressWarnings("unchecked")
	public <T> Optional<T> remove(String key) {
		return Optional.ofNullable((T) this.delegate.removeAttribute(key));
	}

	@Override
	public Iterator<Attr> iterator() {
		Iterator<String> names = this.delegate.getAttributeNames().iterator();
		return new Iterator<AttributeContainer.Attr>() {