Package org.optaplanner.core.impl.score.holder

## Class AbstractScoreHolder<Score_ extends Score<Score_>>

- java.lang.Object
- - org.optaplanner.core.impl.score.holder.AbstractScoreHolder<Score_>

- Type Parameters:
    `Score_` - the `Score` type
  All Implemented Interfaces:
    `ScoreHolder<Score_>`
  Direct Known Subclasses:
    `BendableBigDecimalScoreHolderImpl`, `BendableLongScoreHolderImpl`, `BendableScoreHolderImpl`, `HardMediumSoftBigDecimalScoreHolderImpl`, `HardMediumSoftLongScoreHolderImpl`, `HardMediumSoftScoreHolderImpl`, `HardSoftBigDecimalScoreHolderImpl`, `HardSoftLongScoreHolderImpl`, `HardSoftScoreHolderImpl`, `SimpleBigDecimalScoreHolderImpl`, `SimpleLongScoreHolderImpl`, `SimpleScoreHolderImpl`

      public abstract class AbstractScoreHolder<Score_ extends Score<Score_>>
      extends Object
      implements ScoreHolder<Score_>

  Abstract superclass for `ScoreHolder`. Instances of this class are used both in DRL and in CS-D. CS-D uses the `impactScore(..., Object... justifications)` overloads, passing in the justifications that CS-D is already aware of. DRL uses the overloads that do not allow to pass justifications from the outside, therefore inferring them from the Drools working memory in `registerConstraintMatch(RuleContext, Runnable, Supplier, Object...)`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `protected static interface` | `AbstractScoreHolder.BigDecimalMatchExecutor` |
    `class` | `AbstractScoreHolder.ConstraintActivationUnMatchListener` |
    `protected static interface` | `AbstractScoreHolder.IntMatchExecutor` |
    `protected static interface` | `AbstractScoreHolder.LongMatchExecutor` |
    `protected static interface` | `AbstractScoreHolder.ScoreMatchExecutor<Score_ extends AbstractScore<Score_>>` | Unlike `AbstractScoreHolder.IntMatchExecutor` and its counterparts, this is not being used on CS-D code paths.

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected boolean` | `constraintMatchEnabled` |
    `protected Map<String,​ConstraintMatchTotal<Score_>>` | `constraintMatchTotalMap` |
    `protected static Object[]` | `EMPTY_OBJECT_ARRAY` | Exists to improve performance.
    `protected Map<Object,​Indictment<Score_>>` | `indictmentMap` |
    `protected Score_` | `zeroScore` |

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `AbstractScoreHolder​(boolean constraintMatchEnabled, Score_ zeroScore)` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `configureConstraintWeight​(org.kie.api.definition.rule.Rule rule, Score_ constraintWeight)` |
    `protected List<Object>` | `extractJustificationList​(org.kie.api.runtime.rule.RuleContext kcontext)` |
    `abstract Score_` | `extractScore​(int initScore)` |
    `Map<String,​ConstraintMatchTotal<Score_>>` | `getConstraintMatchTotalMap()` |
    `Map<Object,​Indictment<Score_>>` | `getIndictmentMap()` |
    `void` | `impactScore​(org.kie.api.runtime.rule.RuleContext kcontext)` | For internal use only, use penalize() or reward() instead.
    `void` | `impactScore​(org.kie.api.runtime.rule.RuleContext kcontext, int weightMultiplier)` | For internal use only, use penalize() or reward() instead.
    `abstract void` | `impactScore​(org.kie.api.runtime.rule.RuleContext kcontext, int weightMultiplier, Object... justifications)` | For internal use only, use penalize() or reward() instead.
    `void` | `impactScore​(org.kie.api.runtime.rule.RuleContext kcontext, long weightMultiplier)` | For internal use only, use penalize() or reward() instead.
    `abstract void` | `impactScore​(org.kie.api.runtime.rule.RuleContext kcontext, long weightMultiplier, Object... justifications)` | For internal use only, use penalize() or reward() instead.
    `void` | `impactScore​(org.kie.api.runtime.rule.RuleContext kcontext, Object... justifications)` | For internal use only, use penalize() or reward() instead.
    `void` | `impactScore​(org.kie.api.runtime.rule.RuleContext kcontext, BigDecimal weightMultiplier)` | For internal use only, use penalize() or reward() instead.
    `abstract void` | `impactScore​(org.kie.api.runtime.rule.RuleContext kcontext, BigDecimal weightMultiplier, Object... justifications)` | For internal use only, use penalize() or reward() instead.
    `boolean` | `isConstraintMatchEnabled()` |
    `protected void` | `registerConstraintMatch​(org.kie.api.runtime.rule.RuleContext kcontext, Runnable constraintUndoListener, Supplier<Score_> scoreSupplier, Object... justifications)` | Requires @`OptaPlannerRuleEventListener` to be added as event listener on `KieSession`, otherwise the score changes caused by the constraint matches would not be undone.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.optaplanner.core.api.score.holder.ScoreHolder

      `penalize, reward`

- - ### Field Detail

    - #### EMPTY_OBJECT_ARRAY

          protected static final Object[] EMPTY_OBJECT_ARRAY

      Exists to improve performance. Otherwise a call from method() to method(Object...) would always create a new array.

    - #### constraintMatchEnabled

          protected final boolean constraintMatchEnabled

    - #### constraintMatchTotalMap

          protected final Map<String,​ConstraintMatchTotal<Score_ extends Score<Score_>>> constraintMatchTotalMap

    - #### indictmentMap

          protected final Map<Object,​Indictment<Score_ extends Score<Score_>>> indictmentMap

    - #### zeroScore

          protected final Score_ extends Score<Score_> zeroScore

  - ### Constructor Detail

    - #### AbstractScoreHolder

          protected AbstractScoreHolder​(boolean constraintMatchEnabled,
                                        Score_ zeroScore)

  - ### Method Detail

    - #### isConstraintMatchEnabled

          public boolean isConstraintMatchEnabled()

    - #### getConstraintMatchTotalMap

          public Map<String,​ConstraintMatchTotal<Score_>> getConstraintMatchTotalMap()

    - #### getIndictmentMap

          public Map<Object,​Indictment<Score_>> getIndictmentMap()

    - #### configureConstraintWeight

          public void configureConstraintWeight​(org.kie.api.definition.rule.Rule rule,
                                                Score_ constraintWeight)

    - #### registerConstraintMatch

          protected void registerConstraintMatch​(org.kie.api.runtime.rule.RuleContext kcontext,
                                                 Runnable constraintUndoListener,
                                                 Supplier<Score_> scoreSupplier,
                                                 Object... justifications)

      Requires @`OptaPlannerRuleEventListener` to be added as event listener on `KieSession`, otherwise the score changes caused by the constraint matches would not be undone. See `DroolsScoreDirector.resetKieSession()` for an example.
      Parameters:
        `kcontext` - The rule for which to register the match.
        `constraintUndoListener` - The operation to run to undo the match.
        `scoreSupplier` - The score change to be undone when constraint justification enabled.
        `justifications` - the primary arguments(s) that the CS penalizes/rewards, empty when not called by CS-D

    - #### impactScore

          public final void impactScore​(org.kie.api.runtime.rule.RuleContext kcontext)

      For internal use only, use penalize() or reward() instead.
      Parameters:
        `kcontext` - never null

    - #### impactScore

          public void impactScore​(org.kie.api.runtime.rule.RuleContext kcontext,
                                  Object... justifications)

      For internal use only, use penalize() or reward() instead.
      Parameters:
        `kcontext` - never null
        `justifications` - the primary arguments(s) that the CS penalizes/rewards, not used outside of CS-D

    - #### impactScore

          public final void impactScore​(org.kie.api.runtime.rule.RuleContext kcontext,
                                        int weightMultiplier)

      For internal use only, use penalize() or reward() instead.
      Parameters:
        `kcontext` - never null
        `weightMultiplier` - any

    - #### impactScore

          public abstract void impactScore​(org.kie.api.runtime.rule.RuleContext kcontext,
                                           int weightMultiplier,
                                           Object... justifications)

      For internal use only, use penalize() or reward() instead.
      Parameters:
        `kcontext` - never null
        `weightMultiplier` - any
        `justifications` - the primary arguments(s) that the CS penalizes/rewards, not used outside of CS-D

    - #### impactScore

          public final void impactScore​(org.kie.api.runtime.rule.RuleContext kcontext,
                                        long weightMultiplier)

      For internal use only, use penalize() or reward() instead.
      Parameters:
        `kcontext` - never null
        `weightMultiplier` - any

    - #### impactScore

          public abstract void impactScore​(org.kie.api.runtime.rule.RuleContext kcontext,
                                           long weightMultiplier,
                                           Object... justifications)

      For internal use only, use penalize() or reward() instead.
      Parameters:
        `kcontext` - never null
        `weightMultiplier` - any
        `justifications` - the primary arguments(s) that the CS penalizes/rewards, not used outside of CS-D

    - #### impactScore

          public final void impactScore​(org.kie.api.runtime.rule.RuleContext kcontext,
                                        BigDecimal weightMultiplier)

      For internal use only, use penalize() or reward() instead.
      Parameters:
        `kcontext` - never null
        `weightMultiplier` - any

    - #### impactScore

          public abstract void impactScore​(org.kie.api.runtime.rule.RuleContext kcontext,
                                           BigDecimal weightMultiplier,
                                           Object... justifications)

      For internal use only, use penalize() or reward() instead.
      Parameters:
        `kcontext` - never null
        `weightMultiplier` - any
        `justifications` - the primary arguments(s) that the CS penalizes/rewards, not used outside of CS-D

    - #### extractScore

          public abstract Score_ extractScore​(int initScore)

    - #### extractJustificationList

          protected List<Object> extractJustificationList​(org.kie.api.runtime.rule.RuleContext kcontext)