Package org.optaplanner.core.impl.domain.variable.inverserelation

## Class ExternalizedSingletonInverseVariableSupply<Solution_>

- java.lang.Object
- - org.optaplanner.core.impl.domain.variable.inverserelation.ExternalizedSingletonInverseVariableSupply<Solution_>

- All Implemented Interfaces:
    `Closeable`, `AutoCloseable`, `VariableListener<Solution_,​Object>`, `SingletonInverseVariableSupply`, `SourcedVariableListener<Solution_,​Object>`, `Supply`

      public class ExternalizedSingletonInverseVariableSupply<Solution_>
      extends Object
      implements SourcedVariableListener<Solution_,​Object>, SingletonInverseVariableSupply

  Alternative to `SingletonInverseVariableListener`.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected Map<Object,​Object>` | `inverseEntityMap` |
    `protected VariableDescriptor<Solution_>` | `sourceVariableDescriptor` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ExternalizedSingletonInverseVariableSupply​(VariableDescriptor<Solution_> sourceVariableDescriptor)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `afterEntityAdded​(ScoreDirector<Solution_> scoreDirector, Object entity)` |
    `void` | `afterEntityRemoved​(ScoreDirector<Solution_> scoreDirector, Object entity)` |
    `void` | `afterVariableChanged​(ScoreDirector<Solution_> scoreDirector, Object entity)` |
    `void` | `beforeEntityAdded​(ScoreDirector<Solution_> scoreDirector, Object entity)` |
    `void` | `beforeEntityRemoved​(ScoreDirector<Solution_> scoreDirector, Object entity)` |
    `void` | `beforeVariableChanged​(ScoreDirector<Solution_> scoreDirector, Object entity)` |
    `void` | `close()` | Called before this `VariableListener` is thrown away and not used anymore.
    `Object` | `getInverseSingleton​(Object value)` | If entity1.varA = x then the inverse of x is entity1.
    `VariableDescriptor<Solution_>` | `getSourceVariableDescriptor()` |
    `protected void` | `insert​(ScoreDirector<Solution_> scoreDirector, Object entity)` |
    `void` | `resetWorkingSolution​(ScoreDirector<Solution_> scoreDirector)` | Called when the entire working solution changes.
    `protected void` | `retract​(ScoreDirector<Solution_> scoreDirector, Object entity)` |
    `String` | `toString()` |

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

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

    - ### Methods inherited from interface org.optaplanner.core.api.domain.variable.VariableListener

      `requiresUniqueEntityEvents`

- - ### Field Detail

    - #### sourceVariableDescriptor

          protected final VariableDescriptor<Solution_> sourceVariableDescriptor

    - #### inverseEntityMap

          protected Map<Object,​Object> inverseEntityMap

  - ### Constructor Detail

    - #### ExternalizedSingletonInverseVariableSupply

          public ExternalizedSingletonInverseVariableSupply​(VariableDescriptor<Solution_> sourceVariableDescriptor)

  - ### Method Detail

    - #### getSourceVariableDescriptor

          public VariableDescriptor<Solution_> getSourceVariableDescriptor()

      Specified by:
        `getSourceVariableDescriptor` in interface `SourcedVariableListener<Solution_,​Object>`

    - #### resetWorkingSolution

          public void resetWorkingSolution​(ScoreDirector<Solution_> scoreDirector)

      Description copied from interface: `VariableListener`
      Called when the entire working solution changes. In this event, the other before..()/after...() methods will not be called. At this point, implementations should clear state, if any.
      Specified by:
        `resetWorkingSolution` in interface `VariableListener<Solution_,​Object>`
      Parameters:
        `scoreDirector` - never null

    - #### close

          public void close()

      Description copied from interface: `VariableListener`
      Called before this `VariableListener` is thrown away and not used anymore.
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `VariableListener<Solution_,​Object>`

    - #### beforeEntityAdded

          public void beforeEntityAdded​(ScoreDirector<Solution_> scoreDirector,
                                        Object entity)

      Specified by:
        `beforeEntityAdded` in interface `VariableListener<Solution_,​Object>`
      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### afterEntityAdded

          public void afterEntityAdded​(ScoreDirector<Solution_> scoreDirector,
                                       Object entity)

      Specified by:
        `afterEntityAdded` in interface `VariableListener<Solution_,​Object>`
      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### beforeVariableChanged

          public void beforeVariableChanged​(ScoreDirector<Solution_> scoreDirector,
                                            Object entity)

      Specified by:
        `beforeVariableChanged` in interface `VariableListener<Solution_,​Object>`
      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### afterVariableChanged

          public void afterVariableChanged​(ScoreDirector<Solution_> scoreDirector,
                                           Object entity)

      Specified by:
        `afterVariableChanged` in interface `VariableListener<Solution_,​Object>`
      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### beforeEntityRemoved

          public void beforeEntityRemoved​(ScoreDirector<Solution_> scoreDirector,
                                          Object entity)

      Specified by:
        `beforeEntityRemoved` in interface `VariableListener<Solution_,​Object>`
      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### afterEntityRemoved

          public void afterEntityRemoved​(ScoreDirector<Solution_> scoreDirector,
                                         Object entity)

      Specified by:
        `afterEntityRemoved` in interface `VariableListener<Solution_,​Object>`
      Parameters:
        `scoreDirector` - never null
        `entity` - never null

    - #### insert

          protected void insert​(ScoreDirector<Solution_> scoreDirector,
                                Object entity)

    - #### retract

          protected void retract​(ScoreDirector<Solution_> scoreDirector,
                                 Object entity)

    - #### getInverseSingleton

          public Object getInverseSingleton​(Object value)

      Description copied from interface: `SingletonInverseVariableSupply`
      If entity1.varA = x then the inverse of x is entity1.
      Specified by:
        `getInverseSingleton` in interface `SingletonInverseVariableSupply`
      Parameters:
        `value` - never null
      Returns:
        sometimes null, an entity for which the planning variable is the planningValue.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`