// Path: situation-model/src/main/java/br/ufes/inf/lprm/situation/model/Situation.java
// public interface Situation {
// 
//     public long getUID();
//     public SituationEvent getActivation();
//     public SituationEvent getDeactivation();
//     public void setDeactivation(SituationEvent deactivation);
//     public boolean isActive();
//     public List<? extends Participation> getParticipations();
//     public SituationType getType();
// }


import br.ufes.inf.lprm.situation.model.Situation;
import org.drools.core.base.ValueType;
import org.drools.core.base.evaluators.FinishesEvaluatorDefinition;
import org.drools.core.common.DefaultFactHandle;
import org.drools.core.common.EventFactHandle;
import org.drools.core.common.InternalFactHandle;
import org.drools.core.common.InternalWorkingMemory;
import org.drools.core.rule.VariableRestriction;
import org.drools.core.rule.VariableRestriction.VariableContextEntry;
import org.drools.core.rule.VariableRestriction.ObjectVariableContextEntry;
import org.drools.core.spi.FieldValue;
import org.drools.core.spi.InternalReadAccessor;
import java.lang.reflect.Field;
        }

        rightStartTS = ((VariableRestriction.TemporalVariableContextEntry) context).startTS;
        rightEndTS = ((VariableRestriction.TemporalVariableContextEntry) context).endTS;

        long distStart = rightStartTS - leftStartTS;
        long distEnd = Math.abs( leftEndTS - rightEndTS );
        return this.getOperator().isNegated() ^ (distStart > 0 && distEnd <= this.endDev);

    }

    @Override
    public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory, VariableContextEntry context, InternalFactHandle right) {
        if ( context.leftNull ||
                context.extractor.isNullValue( workingMemory, right.getObject() ) ) {
            return false;
        }

        long leftStartTS, leftEndTS, rightStartTS, rightEndTS;

        leftStartTS = ((VariableRestriction.TemporalVariableContextEntry) context).startTS;
        leftEndTS = ((VariableRestriction.TemporalVariableContextEntry) context).endTS;

        if (right.getObject() instanceof Situation) {
            Situation sit = (Situation) right.getObject();
            if (sit.isActive()) return false;
            rightStartTS = sit.getActivation().getTimestamp();
            rightEndTS   = sit.getDeactivation().getTimestamp();
        } else {
            rightStartTS = ((EventFactHandle) right).getStartTimestamp();
// Path: situation-model/src/main/java/br/ufes/inf/lprm/situation/model/Situation.java
// public interface Situation {
// 
//     public long getUID();
//     public SituationEvent getActivation();
//     public SituationEvent getDeactivation();
//     public void setDeactivation(SituationEvent deactivation);
//     public boolean isActive();
//     public List<? extends Participation> getParticipations();
//     public SituationType getType();
// }


// Path: scene-core/src/main/java/br/ufes/inf/lprm/scene/base/evaluators/implementation/FinishesEvaluator.java
import br.ufes.inf.lprm.situation.model.Situation;
import org.drools.core.base.ValueType;
import org.drools.core.base.evaluators.FinishesEvaluatorDefinition;
import org.drools.core.common.DefaultFactHandle;
import org.drools.core.common.EventFactHandle;
import org.drools.core.common.InternalFactHandle;
import org.drools.core.common.InternalWorkingMemory;
import org.drools.core.rule.VariableRestriction;
import org.drools.core.rule.VariableRestriction.VariableContextEntry;
import org.drools.core.rule.VariableRestriction.ObjectVariableContextEntry;
import org.drools.core.spi.FieldValue;
import org.drools.core.spi.InternalReadAccessor;
import java.lang.reflect.Field;

        }

        rightStartTS = ((VariableRestriction.TemporalVariableContextEntry) context).startTS;
        rightEndTS = ((VariableRestriction.TemporalVariableContextEntry) context).endTS;

        long distStart = rightStartTS - leftStartTS;
        long distEnd = Math.abs( leftEndTS - rightEndTS );
        return this.getOperator().isNegated() ^ (distStart > 0 && distEnd <= this.endDev);

    }

    @Override
    public boolean evaluateCachedLeft(InternalWorkingMemory workingMemory, VariableContextEntry context, InternalFactHandle right) {
        if ( context.leftNull ||
                context.extractor.isNullValue( workingMemory, right.getObject() ) ) {
            return false;
        }

        long leftStartTS, leftEndTS, rightStartTS, rightEndTS;

        leftStartTS = ((VariableRestriction.TemporalVariableContextEntry) context).startTS;
        leftEndTS = ((VariableRestriction.TemporalVariableContextEntry) context).endTS;

        if (right.getObject() instanceof Situation) {
            Situation sit = (Situation) right.getObject();
            if (sit.isActive()) return false;
            rightStartTS = sit.getActivation().getTimestamp();
            rightEndTS   = sit.getDeactivation().getTimestamp();
        } else {
            rightStartTS = ((EventFactHandle) right).getStartTimestamp();
            rightEndTS = ((EventFactHandle) right).getEndTimestamp();