| 1 | package com.hammurapi.eventbus; |
| 2 | |
| 3 | import java.util.Collections; |
| 4 | import java.util.Map; |
| 5 | import java.util.Set; |
| 6 | |
| 7 | import com.hammurapi.extract.ComparisonResult; |
| 8 | import com.hammurapi.extract.Extractor; |
| 9 | |
| 10 | /** |
| 11 | * Extracts event from handle. This is a helper class to construct bus stores. |
| 12 | * @author Pavel Vlasov |
| 13 | * |
| 14 | * @param <V> |
| 15 | * @param <P> |
| 16 | * @param <C> |
| 17 | * @param <K> |
| 18 | */ |
| 19 | 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> { |
| 20 | |
| 21 | private static Set<Integer> ZERO_IDX = Collections.singleton(0); |
| 22 | |
| 23 | @Override |
| 24 | public Set<Integer> parameterIndices() { |
| 25 | return ZERO_IDX; |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public boolean isContextDependent() { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | @Override |
| 34 | public E extract(S context, Map<S, Map<Extractor<H, ? super E, S>, ? super E>> cache, H... obj) { |
| 35 | return obj[0].getEvent(); |
| 36 | } |
| 37 | |
| 38 | @Override |
| 39 | public ComparisonResult compareTo(Extractor<H, E, S> other) { |
| 40 | return other.getClass().equals(getClass()) ? ComparisonResult.EQUAL_NM : ComparisonResult.NOT_EQUAL_NM ; |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public double getCost() { |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | } |