Search in sources :

Example 1 with LeftStartRightEndContextEntry

use of org.drools.core.rule.VariableRestriction.LeftStartRightEndContextEntry in project drools by kiegroup.

the class TemporalEvaluatorFactoryTest method getContextEntry.

private VariableContextEntry getContextEntry(final Evaluator evaluator, final InternalReadAccessor extractor, final ValueType valueType, final Object[] row, final boolean left) {
    final Declaration declaration = new Declaration("test", extractor, null);
    final ValueType coerced = evaluator.getCoercedValueType();
    if (evaluator.isTemporal()) {
        if (evaluator instanceof BeforeEvaluatorDefinition.BeforeEvaluator || evaluator instanceof MeetsEvaluatorDefinition.MeetsEvaluator) {
            LeftStartRightEndContextEntry context = new LeftStartRightEndContextEntry(extractor, declaration, evaluator);
            if (left) {
                context.timestamp = ((EventFactHandle) row[2]).getStartTimestamp();
            } else {
                context.timestamp = ((EventFactHandle) row[0]).getEndTimestamp();
            }
            return context;
        }
        if (evaluator instanceof AfterEvaluatorDefinition.AfterEvaluator || evaluator instanceof MetByEvaluatorDefinition.MetByEvaluator) {
            LeftEndRightStartContextEntry context = new LeftEndRightStartContextEntry(extractor, declaration, evaluator);
            if (left) {
                context.timestamp = ((EventFactHandle) row[2]).getEndTimestamp();
            } else {
                context.timestamp = ((EventFactHandle) row[0]).getStartTimestamp();
            }
            return context;
        }
        // else
        TemporalVariableContextEntry context = new TemporalVariableContextEntry(extractor, declaration, evaluator);
        if (left) {
            context.startTS = ((EventFactHandle) row[2]).getStartTimestamp();
            context.endTS = ((EventFactHandle) row[2]).getEndTimestamp();
        } else {
            context.startTS = ((EventFactHandle) row[0]).getStartTimestamp();
            context.endTS = ((EventFactHandle) row[0]).getEndTimestamp();
        }
        return context;
    }
    if (coerced.isIntegerNumber()) {
        final LongVariableContextEntry context = new LongVariableContextEntry(extractor, declaration, evaluator);
        if (row[2] == null) {
            context.leftNull = true;
        } else {
            context.left = ((Number) row[2]).longValue();
        }
        if (row[0] == null) {
            context.rightNull = true;
        } else {
            context.right = ((Number) row[0]).longValue();
        }
        return context;
    } else if (coerced.isChar()) {
        final CharVariableContextEntry context = new CharVariableContextEntry(extractor, declaration, evaluator);
        if (row[2] == null) {
            context.leftNull = true;
        } else {
            context.left = ((Character) row[2]).charValue();
        }
        if (row[0] == null) {
            context.rightNull = true;
        } else {
            context.right = ((Character) row[0]).charValue();
        }
        return context;
    } else if (coerced.isBoolean()) {
        final BooleanVariableContextEntry context = new BooleanVariableContextEntry(extractor, declaration, evaluator);
        if (row[2] == null) {
            context.leftNull = true;
        } else {
            context.left = ((Boolean) row[2]).booleanValue();
        }
        if (row[0] == null) {
            context.rightNull = true;
        } else {
            context.right = ((Boolean) row[0]).booleanValue();
        }
        return context;
    } else if (coerced.isFloatNumber()) {
        final DoubleVariableContextEntry context = new DoubleVariableContextEntry(extractor, declaration, evaluator);
        if (row[2] == null) {
            context.leftNull = true;
        } else {
            context.left = ((Number) row[2]).doubleValue();
        }
        if (row[0] == null) {
            context.rightNull = true;
        } else {
            context.right = ((Number) row[0]).doubleValue();
        }
        return context;
    } else {
        final ObjectVariableContextEntry context = new ObjectVariableContextEntry(extractor, declaration, evaluator);
        if (row[2] == null) {
            context.leftNull = true;
        } else {
            context.left = row[2];
        }
        if (row[0] == null) {
            context.rightNull = true;
        } else {
            context.right = row[0];
        }
        return context;
    }
}
Also used : BeforeEvaluatorDefinition(org.drools.core.base.evaluators.BeforeEvaluatorDefinition) AfterEvaluatorDefinition(org.drools.core.base.evaluators.AfterEvaluatorDefinition) MetByEvaluatorDefinition(org.drools.core.base.evaluators.MetByEvaluatorDefinition) LongVariableContextEntry(org.drools.core.rule.VariableRestriction.LongVariableContextEntry) CharVariableContextEntry(org.drools.core.rule.VariableRestriction.CharVariableContextEntry) ObjectVariableContextEntry(org.drools.core.rule.VariableRestriction.ObjectVariableContextEntry) LeftStartRightEndContextEntry(org.drools.core.rule.VariableRestriction.LeftStartRightEndContextEntry) BooleanVariableContextEntry(org.drools.core.rule.VariableRestriction.BooleanVariableContextEntry) DoubleVariableContextEntry(org.drools.core.rule.VariableRestriction.DoubleVariableContextEntry) TemporalVariableContextEntry(org.drools.core.rule.VariableRestriction.TemporalVariableContextEntry) Declaration(org.drools.core.rule.Declaration) LeftEndRightStartContextEntry(org.drools.core.rule.VariableRestriction.LeftEndRightStartContextEntry) MeetsEvaluatorDefinition(org.drools.core.base.evaluators.MeetsEvaluatorDefinition)

Aggregations

AfterEvaluatorDefinition (org.drools.core.base.evaluators.AfterEvaluatorDefinition)1 BeforeEvaluatorDefinition (org.drools.core.base.evaluators.BeforeEvaluatorDefinition)1 MeetsEvaluatorDefinition (org.drools.core.base.evaluators.MeetsEvaluatorDefinition)1 MetByEvaluatorDefinition (org.drools.core.base.evaluators.MetByEvaluatorDefinition)1 Declaration (org.drools.core.rule.Declaration)1 BooleanVariableContextEntry (org.drools.core.rule.VariableRestriction.BooleanVariableContextEntry)1 CharVariableContextEntry (org.drools.core.rule.VariableRestriction.CharVariableContextEntry)1 DoubleVariableContextEntry (org.drools.core.rule.VariableRestriction.DoubleVariableContextEntry)1 LeftEndRightStartContextEntry (org.drools.core.rule.VariableRestriction.LeftEndRightStartContextEntry)1 LeftStartRightEndContextEntry (org.drools.core.rule.VariableRestriction.LeftStartRightEndContextEntry)1 LongVariableContextEntry (org.drools.core.rule.VariableRestriction.LongVariableContextEntry)1 ObjectVariableContextEntry (org.drools.core.rule.VariableRestriction.ObjectVariableContextEntry)1 TemporalVariableContextEntry (org.drools.core.rule.VariableRestriction.TemporalVariableContextEntry)1