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

com.automationrockstars.gunter.events.EventStore Maven / Gradle / Ivy

The newest version!
/*
 * 
 */
package com.automationrockstars.gunter.events;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;

import java.util.Map;

import static java.util.Arrays.asList;

public class EventStore {

    private static final ThreadLocal, Event>> gevents = new InheritableThreadLocal, Event>>() {
        @Override
        protected Map, Event> initialValue() {
            return Maps.newHashMap();
        }

        @Override
        protected Map, Event> childValue(Map, Event> parentValue) {
            return Maps.newHashMap(parentValue);

        }

    };

    public static final  T getEvent(Class klass) {
        return (T) gevents.get().get(klass);
    }

    public static final void putEvent(Event event) {

        Class key = (Class) Iterables.find(asList(event.getClass().getInterfaces()), new Predicate>() {
            public boolean test(Class input){
                return apply(input);
            }
            @Override
            public boolean apply(Class input) {
                return input.getName().startsWith("com.automationrockstars.gunter.events.");
            }

            ;
        });

        gevents.get().put(key, event);
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy