Interface ProblemChangeDirector

All Known Implementing Classes:
DefaultProblemChangeDirector

public interface ProblemChangeDirector
Allows external changes to the working solution. If the changes are not applied through the ProblemChangeDirector, both internal and custom variable listeners are never notified about them, resulting to inconsistencies in the working solution. Should be used only from a ProblemChange implementation. To see an example implementation, please refer to the ProblemChange Javadoc.
  • Method Details

    • addEntity

      <Entity> void addEntity(@NonNull Entity entity, @NonNull Consumer<Entity> entityConsumer)
      Add a new PlanningEntity instance into the working solution.
      Type Parameters:
      Entity - the planning entity object type
      Parameters:
      entity - the PlanningEntity instance
      entityConsumer - adds the entity to the working solution
    • removeEntity

      <Entity> void removeEntity(@NonNull Entity entity, @NonNull Consumer<Entity> entityConsumer)
      Remove an existing PlanningEntity instance from the working solution. Translates the entity to a working planning entity by performing a lookup as defined by lookUpWorkingObjectOrFail(Object).
      Type Parameters:
      Entity - the planning entity object type
      Parameters:
      entity - the PlanningEntity instance
      entityConsumer - removes the working entity from the working solution
    • changeVariable

      <Entity> void changeVariable(@NonNull Entity entity, @NonNull String variableName, @NonNull Consumer<Entity> entityConsumer)
      Change a PlanningVariable value of a PlanningEntity. Translates the entity to a working planning entity by performing a lookup as defined by lookUpWorkingObjectOrFail(Object).
      Type Parameters:
      Entity - the planning entity object type
      Parameters:
      entity - the PlanningEntity instance
      variableName - name of the PlanningVariable
      entityConsumer - updates the value of the PlanningVariable inside the PlanningEntity
    • addProblemFact

      <ProblemFact> void addProblemFact(@NonNull ProblemFact problemFact, @NonNull Consumer<ProblemFact> problemFactConsumer)
      Add a new problem fact into the working solution.
      Type Parameters:
      ProblemFact - the problem fact object type
      Parameters:
      problemFact - the problem fact instance
      problemFactConsumer - removes the working problem fact from the working solution
    • removeProblemFact

      <ProblemFact> void removeProblemFact(@NonNull ProblemFact problemFact, @NonNull Consumer<ProblemFact> problemFactConsumer)
      Remove an existing problem fact from the working solution. Translates the problem fact to a working problem fact by performing a lookup as defined by lookUpWorkingObjectOrFail(Object).
      Type Parameters:
      ProblemFact - the problem fact object type
      Parameters:
      problemFact - the problem fact instance
      problemFactConsumer - removes the working problem fact from the working solution
    • changeProblemProperty

      <EntityOrProblemFact> void changeProblemProperty(@NonNull EntityOrProblemFact problemFactOrEntity, @NonNull Consumer<EntityOrProblemFact> problemFactOrEntityConsumer)
      Change a property of either a PlanningEntity or a problem fact. Translates the entity or the problem fact to its working solution counterpart by performing a lookup as defined by lookUpWorkingObjectOrFail(Object).
      Type Parameters:
      EntityOrProblemFact - the planning entity or problem fact object type
      Parameters:
      problemFactOrEntity - the PlanningEntity or the problem fact instance
      problemFactOrEntityConsumer - updates the property of the PlanningEntity or the problem fact
    • lookUpWorkingObjectOrFail

      <EntityOrProblemFact> @Nullable EntityOrProblemFact lookUpWorkingObjectOrFail(@Nullable EntityOrProblemFact externalObject)
      Translate an entity or fact instance (often from another Thread or JVM) to this ProblemChangeDirector's internal working instance.

      Matching is determined by the LookUpStrategyType on PlanningSolution. Matching uses a PlanningId by default.

      Type Parameters:
      EntityOrProblemFact - the object type
      Returns:
      null if externalObject is null
      Throws:
      IllegalArgumentException - if there is no workingObject for externalObject, if it cannot be looked up or if the externalObject's class is not supported
      IllegalStateException - if it cannot be looked up
    • lookUpWorkingObject

      <EntityOrProblemFact> Optional<EntityOrProblemFact> lookUpWorkingObject(@Nullable EntityOrProblemFact externalObject)
      As defined by lookUpWorkingObjectOrFail(Object), but doesn't fail fast if no workingObject was ever added for the externalObject. It's recommended to use lookUpWorkingObjectOrFail(Object) instead.
      Type Parameters:
      EntityOrProblemFact - the object type
      Returns:
      Optional.empty() if externalObject is null or if there is no workingObject for externalObject
      Throws:
      IllegalArgumentException - if it cannot be looked up or if the externalObject's class is not supported
      IllegalStateException - if it cannot be looked up
    • updateShadowVariables

      void updateShadowVariables()
      Calls variable listeners on the external changes submitted so far.

      This happens automatically after the entire ProblemChange has been processed, but this method allows the user to specifically request it in the middle of the ProblemChange.