    001    package com.hammurapi.eventbus;
    002
    003    import java.util.Collections;
    004    import java.util.Map;
    005    import java.util.Set;
    006
    007    import com.hammurapi.extract.ComparisonResult;
    008    import com.hammurapi.extract.Extractor;
    009
    010    /**
    011     * Extracts event from handle. This is a helper class to construct bus stores.
    012     * @author Pavel Vlasov
    013     *
    014     * @param <V>
    015     * @param <P>
    016     * @param <C>
    017     * @param <K>
    018     */
    019    public class HandleExtractor<E, P extends Comparable<P>, C, K, H extends EventBus.Handle<E,P,C>, S extends EventStore<E,P,C,H,S>> implements Extractor<H,E,S> {
    020
    021            private static Set<Integer> ZERO_IDX = Collections.singleton(0);
    022
    023            @Override
    024            public Set<Integer> parameterIndices() {
    025                    return ZERO_IDX;
    026            }
    027
    028            @Override
    029            public boolean isContextDependent() {
    030                    return false;
    031            }
    032
    033            @Override
    034            public E extract(S context, Map<S, Map<Extractor<H, ? super E, S>, ? super E>> cache, H... obj) {
    035                    return obj[0].getEvent();
    036            }
    037
    038            @Override
    039            public ComparisonResult compareTo(Extractor<H, E, S> other) {
    040                    return other.getClass().equals(getClass()) ? ComparisonResult.EQUAL_NM : ComparisonResult.NOT_EQUAL_NM ;
    041            }
    042
    043            @Override
    044            public double getCost() {
    045                    return 0;
    046            }
    047
    048    }