use of org.drools.core.rule.VariableRestriction.TemporalVariableContextEntry 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;
}
}
Aggregations