Class ReplaceExecutor

java.lang.Object
org.kigalisim.engine.support.ReplaceExecutor

public class ReplaceExecutor extends Object
Handles substance replacement operations.

This class provides execution logic for replacing one substance with another in a given stream, supporting both unit-based and volume-based replacement modes.

  • Constructor Details

    • ReplaceExecutor

      public ReplaceExecutor(Engine engine)
      Creates a new ReplaceExecutor for the given engine.
      Parameters:
      engine - The Engine instance to operate on
  • Method Details

    • execute

      public void execute(EngineNumber amountRaw, String stream, String destinationSubstance, YearMatcher yearMatcher)
      Executes a substance replacement operation.

      Replaces the specified amount of the current substance with the destination substance in the given stream. The operation removes substance from the source and adds it to the destination, using appropriate conversion rates and scope context.

      For percentage-based amounts, the last specified value is used to determine whether to use unit-based or volume-based replacement logic. Unit-based replacement uses initial charge rates specific to each substance, while volume-based replacement uses the same volume for both source and destination.

      Parameters:
      amountRaw - The amount to replace (can be units, volume, or percentage)
      stream - The stream identifier to modify (e.g., "domestic", "import", "sales")
      destinationSubstance - The substance to replace with
      yearMatcher - Matcher to determine if the change applies to current year
      Throws:
      IllegalArgumentException - if attempting to replace substance with itself
      IllegalStateException - if no application or substance is in current scope