class AbstractRuleContext {

    private final List<ViewItem<?>> viewItems;

    protected AbstractRuleContext(ViewItem<?>... viewItems) {
        this.viewItems = Arrays.stream(viewItems).collect(Collectors.toList());
    }

    protected static void runConsequence(DroolsConstraint<?> constraint, Drools drools,
            WeightedScoreImpacter<?, ?> scoreImpacter, int impact, JustificationsSupplier justificationsSupplier) {
        try {
            constraint.assertCorrectImpact(impact);
            UndoScoreImpacter undoImpact = scoreImpacter.impactScore(impact, justificationsSupplier);
            addUndo(drools, undoImpact);
        } catch (Exception e) {
            throw createExceptionOnImpact(constraint, e);
        }
    }

    private static void addUndo(Drools drools, UndoScoreImpacter undoImpact) {
        InternalMatch match = (InternalMatch) ((RuleContext) drools).getMatch();
        match.setCallback(undoImpact);
    }

    private static RuntimeException createExceptionOnImpact(DroolsConstraint<?> constraint, Exception cause) {<FILL_FUNCTION_BODY>}

    protected static void runConsequence(DroolsConstraint<?> constraint, Drools drools,
            WeightedScoreImpacter<?, ?> scoreImpacter, long impact, JustificationsSupplier justificationsSupplier) {
        try {
            constraint.assertCorrectImpact(impact);
            UndoScoreImpacter undoImpact = scoreImpacter.impactScore(impact, justificationsSupplier);
            addUndo(drools, undoImpact);
        } catch (Exception e) {
            throw createExceptionOnImpact(constraint, e);
        }
    }

    protected static void runConsequence(DroolsConstraint<?> constraint, Drools drools,
            WeightedScoreImpacter<?, ?> scoreImpacter, BigDecimal impact, JustificationsSupplier justificationsSupplier) {
        try {
            constraint.assertCorrectImpact(impact);
            UndoScoreImpacter undoImpact = scoreImpacter.impactScore(impact, justificationsSupplier);
            addUndo(drools, undoImpact);
        } catch (Exception e) {
            throw createExceptionOnImpact(constraint, e);
        }
    }

    protected <Solution_> RuleBuilder<Solution_> assemble(ConsequenceBuilder<Solution_> consequenceBuilder) {
        return (constraint, scoreImpacterGlobal) -> {
            List<RuleItemBuilder<?>> ruleItemBuilderList = new ArrayList<>(viewItems);
            ruleItemBuilderList.add(consequenceBuilder.apply(constraint, scoreImpacterGlobal));
            return rule(constraint.getConstraintPackage(), constraint.getConstraintName())
                    .build(ruleItemBuilderList.toArray(new RuleItemBuilder[0]));
        };
    }

}

        return new IllegalStateException(
                "Consequence of a constraint (" + constraint.getConstraintId() + ") threw an exception.", cause);
    
<no_super_class>