Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLANNER-284: Code style + performance #133

Merged
merged 2 commits into from Aug 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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