org.optaplanner.core.impl.domain.variable.listener

## Interface VariableListener<Entity_>

- All Superinterfaces:
    Supply
  All Known Subinterfaces:
    CustomShadowVariable.NullVariableListener, StatefulVariableListener<Entity_>
  All Known Implementing Classes:
    AnchorVariableListener, CollectionInverseVariableListener, ExternalizedAnchorVariableSupply, ExternalizedCollectionInverseVariableSupply, ExternalizedSingletonInverseVariableSupply, SingletonInverseVariableListener, VariableListenerAdapter

      public interface VariableListener<Entity_>
      extends Supply

  Changes shadow variables when a genuine planning variable changes.

  Important: it must only change the shadow variable(s) for which it's configured! It should never change a genuine variable or a problem fact. It can change its shadow variable(s) on multiple entity instances (for example: an arrivalTime change affects all trailing entities too).

  Each `ScoreDirector` has a different `VariableListener` instance, so it can be stateful. If it is stateful, it must implement `StatefulVariableListener`.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterEntityAdded(ScoreDirector scoreDirector, Entity_ entity)`
    `void` | `afterEntityRemoved(ScoreDirector scoreDirector, Entity_ entity)`
    `void` | `afterVariableChanged(ScoreDirector scoreDirector, Entity_ entity)`
    `void` | `beforeEntityAdded(ScoreDirector scoreDirector, Entity_ entity)`
    `void` | `beforeEntityRemoved(ScoreDirector scoreDirector, Entity_ entity)`
    `void` | `beforeVariableChanged(ScoreDirector scoreDirector, Entity_ entity)`
    `default boolean` | `requiresUniqueEntityEvents()` When set to `true`, this has a slight performance loss in Planner.

- - ### Method Detail

    - #### requiresUniqueEntityEvents

          default boolean requiresUniqueEntityEvents()

      When set to `true`, this has a slight performance loss in Planner. When set to `false`, it's often easier to make the listener implementation correct and fast.
      Returns:
        true to guarantee that each of the before/after methods will only be called once per entity instance per operation type (add, change or remove).

    - #### beforeEntityAdded

          void beforeEntityAdded(ScoreDirector scoreDirector,
                                 Entity_ entity)

      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### afterEntityAdded

          void afterEntityAdded(ScoreDirector scoreDirector,
                                Entity_ entity)

      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### beforeVariableChanged

          void beforeVariableChanged(ScoreDirector scoreDirector,
                                     Entity_ entity)

      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### afterVariableChanged

          void afterVariableChanged(ScoreDirector scoreDirector,
                                    Entity_ entity)

      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### beforeEntityRemoved

          void beforeEntityRemoved(ScoreDirector scoreDirector,
                                   Entity_ entity)

      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### afterEntityRemoved

          void afterEntityRemoved(ScoreDirector scoreDirector,
                                  Entity_ entity)

      Parameters:
        `scoreDirector` - never null
        `entity` - never null

Copyright © 2006–2020 JBoss by Red Hat. All rights reserved.