    001    package com.hammurapi.eventbus;
    002
    003
    004    /**
    005     * Discards post commands with derivation loops, i.e. when one of inputs is derived from the event.
    006     * @author Pavel Vlasov
    007     */
    008    public class DerivationLoopFilter<E, P extends Comparable<P>, C, K, H extends EventBus.Handle<E,P,C>, S extends EventStore<E,P,C,H,S>> implements InferenceFilter<E,P,C,K,H,S> {
    009
    010            public boolean accept(InferenceCommand<E,P,C,K,H,S> inferenceCommand, EventBus<E,P,C,K,H,S> bus) {
    011                    if (inferenceCommand instanceof PostCommand) {
    012                            PostCommand<E,P,C,K,H,S> postCommand = (PostCommand<E,P,C,K,H,S>) inferenceCommand;
    013                            E event = postCommand.getEvent();
    014                            for (AbstractEventBus.Handle<E, P, C, K> handle: postCommand.getInputs()) {
    015                                    if (handle.isDerivedFrom(event)) {
    016                                            return false;
    017                                    }
    018                            }
    019                    }
    020                    return true;
    021            }
    022    }