Skip to content

Commit

Permalink
Merge pull request #133 from oskopek/PLANNER-284-fix
Browse files Browse the repository at this point in the history
PLANNER-284: Code style + performance
  • Loading branch information
ge0ffrey committed Aug 26, 2015
2 parents 7473adf + a6c3352 commit bdb6b8c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Expand Up @@ -257,28 +257,28 @@ protected interface ConstraintUndoListener {

private static class MultiLevelActivationUnMatchListener implements ActivationUnMatchListener {

private final Map<Integer, ConstraintUndoListener> scoreLevelToConstraintUndoListenerMap;
private static final int INITIAL_MAP_CAPACITY = 2;

private Map<Integer, ConstraintUndoListener> scoreLevelToConstraintUndoListenerMap;

public MultiLevelActivationUnMatchListener(int scoreLevel, ConstraintUndoListener constraintUndoListener) {
// Most use cases use only 1 scoreLevel per score rule and there are likely many instances of this class,
// so the initialCapacity is very memory conservative
scoreLevelToConstraintUndoListenerMap = new HashMap<Integer, ConstraintUndoListener>(2);
scoreLevelToConstraintUndoListenerMap = new HashMap<Integer, ConstraintUndoListener>(INITIAL_MAP_CAPACITY);
scoreLevelToConstraintUndoListenerMap.put(scoreLevel, constraintUndoListener);
}

@Override
public final void unMatch(RuleRuntime ruleRuntime, Match match) {
for (ConstraintUndoListener constraintUndoListener : scoreLevelToConstraintUndoListenerMap.values()) {
// Both parameters can be null because they are not used by our constraintUndoListeners anyway
constraintUndoListener.unMatch();
}
scoreLevelToConstraintUndoListenerMap.clear();
scoreLevelToConstraintUndoListenerMap = new HashMap<Integer, ConstraintUndoListener>(INITIAL_MAP_CAPACITY);
}

public void overwriteMatch(int scoreLevel, ConstraintUndoListener constraintUndoListener) {
ConstraintUndoListener oldConstraintUndoListener = scoreLevelToConstraintUndoListenerMap.put(scoreLevel, constraintUndoListener);
if (oldConstraintUndoListener != null) {
// Both parameters can be null because they are not used by our constraintUndoListeners anyway
oldConstraintUndoListener.unMatch();
}
}
Expand Down
Expand Up @@ -39,7 +39,6 @@ public void addConstraintMatchWithoutConstraintMatch() {
public void addConstraintMatch(boolean constraintMatchEnabled) {
BendableBigDecimalScoreHolder scoreHolder = new BendableBigDecimalScoreHolder(constraintMatchEnabled, 1, 2);


scoreHolder.addHardConstraintMatch(mockRuleContext("scoreRule1"), 0, BigDecimal.valueOf(-10000));

RuleContext ruleContext2 = mockRuleContext("scoreRule2");
Expand Down
Expand Up @@ -2637,7 +2637,7 @@ Before in *.drl:
then
scoreHolder.addSoftConstraintMatch(kcontext, -1); // Employee happiness cost
end
Before in *.drl:
After in *.drl:
rule "Costly and unfair"
when
// Complex pattern
Expand Down

0 comments on commit bdb6b8c

Please sign in to comment.