package com.googlecode.yatspec.state.givenwhenthen;

import com.googlecode.totallylazy.Option;

import java.util.LinkedHashMap;
import java.util.Map;

import static com.googlecode.totallylazy.Option.option;
import static java.util.Collections.unmodifiableMap;

@SuppressWarnings("unused")
class NiceMap<T extends NiceMap> {
    private final Map<String, Object> map = new LinkedHashMap<String, Object>();

    public NiceMap(Object... instances) {
        for (Object instance : instances) {
            add(instance);
        }
    }

    @SuppressWarnings({"unchecked"})
    public final <R> R getType(String key, Class<R> aClass) {
        Object value = map.get(key);
        if(value == null) {
            return null;
        }
        if(!aClass.isAssignableFrom(value.getClass())){
            throw new ClassCastException("You requested a " + aClass.getSimpleName() + " but got a " + value.getClass() + " (" + value + ")");
        }
        return (R) value;
    }

    public final Map<String, Object> getTypes() {
        return unmodifiableMap(map);
    }

    public final <R> R getType(Class<R> aClass) {
        return getType(defaultName(aClass),aClass);
    }

    public final <R> Option<R> getOption(String key, Class<R> aClass) {
        return option(getType(key, aClass));
    }

    public final <R> Option<R> getOption(Class<R> aClass) {
        return option(getType(aClass));
    }

    @SuppressWarnings({"unchecked"})
    public final T add(String key, Object instance){
        map.put(key, instance);
        return (T) this;
    }

    public final boolean isEmpty() {
        return map.isEmpty();
    }

    @SuppressWarnings({"unchecked"})
    public final T add(Object instance){
        if(instance == null) {
            return (T) this;
        }
        return add(defaultName(instance.getClass()), instance);
    }

    public final boolean contains(Class aClass){
        return contains(defaultName(aClass));
    }

    public final boolean contains(String name) {
        return map.containsKey(name);
    }

    private static String defaultName(Class<? extends Object> aClass) {
        return aClass.getSimpleName();
    }

}

@@ -50,51 +50,8 @@
 n;%0A%0A
-import com.googlecode.totallylazy.Option;%0A%0A
 impo
@@ -105,64 +105,8 @@
 p;%0A%0A
-import static com.googlecode.totallylazy.Option.option;%0A
 impo
@@ -1062,245 +1062,15 @@
 ss),
+ 
 aClass
-);%0A    %7D%0A%0A    public final %3CR%3E Option%3CR%3E getOption(String key, Class%3CR%3E aClass) %7B%0A        return option(getType(key, aClass));%0A    %7D%0A%0A    public final %3CR%3E Option%3CR%3E getOption(Class%3CR%3E aClass) %7B%0A        return option(getType(aClass)
 );%0A 

Remove NiceMap#getOption