Class EngineSupportUtils

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

public final class EngineSupportUtils extends Object
Static utility methods for engine operations.
  • Field Details

    • STREAM_NAMES

      public static final Set<String> STREAM_NAMES
      Set of valid stream names in the simulation engine. Includes equipment streams, sales streams, and trade streams.
    • RECYCLE_RECOVER_STREAM

      public static final String RECYCLE_RECOVER_STREAM
      The stream used for recycled material recovery operations.
      See Also:
  • Method Details

    • getIsInRange

      public static boolean getIsInRange(YearMatcher yearMatcher, int currentYear)
      Check if a year matcher is in range for the given current year.
      Parameters:
      yearMatcher - The year matcher to check (can be null)
      currentYear - The current year to check against
      Returns:
      True if in range or no matcher provided
    • getIsInRange

      public static boolean getIsInRange(Optional<YearMatcher> yearMatcher, int currentYear)
      Check if a year matcher is in range for the given current year.
      Parameters:
      yearMatcher - The optional year matcher to check
      currentYear - The current year to check against
      Returns:
      True if in range or no matcher provided
    • isSalesSubstream

      public static boolean isSalesSubstream(String name)
      Check if a stream name represents a sales substream (domestic or import).

      Sales substreams are the component streams that make up the overall sales stream, representing domestic manufacturing and imported products.

      Parameters:
      name - The stream name to check
      Returns:
      true if the stream is domestic or import
    • getIsSalesStream

      public static boolean getIsSalesStream(String stream, boolean includeExports)
      Check if a stream is a sales-related stream.

      A sales-related stream includes the core sales stream and its substreams (domestic and import). Optionally, the export stream can be included depending on the context of the operation being performed.

      This is the centralized implementation for stream classification logic and should be used throughout the engine instead of local implementations to ensure consistent behavior.

      Parameters:
      stream - The stream name to check
      includeExports - Whether to include export stream as a sales stream
      Returns:
      true if the stream is a sales-related stream (sales, domestic, or import); or export if includeExports is true
    • createUnitConverterWithTotal

      public static UnitConverter createUnitConverterWithTotal(ConverterStateGetter stateGetter, String stream, EngineNumber currentValue, EngineNumber initialCharge)
      Creates a unit converter with total values initialized.
      Parameters:
      stateGetter - The converter state getter from the engine
      stream - The stream identifier to create converter for
      currentValue - The current stream value
      initialCharge - The initial charge (for sales substreams only, can be null)
      Returns:
      A configured unit converter instance
    • createUnitConverterWithTotal

      public static UnitConverter createUnitConverterWithTotal(Engine engine, String stream)
      Creates a unit converter with total values initialized (convenience method).
      Parameters:
      engine - The Engine instance to get state from
      stream - The stream identifier to create converter for
      Returns:
      A configured unit converter instance
    • hasUnitBasedSalesSpecifications

      public static boolean hasUnitBasedSalesSpecifications(SimulationState simulationState, UseKey scope)
      Check if sales streams were specified in equipment units for the given scope. When streams are specified in units, certain operations need different handling (e.g., retirement affects recharge calculations, carry-over logic differs).
      Parameters:
      simulationState - the SimulationState instance to query
      scope - the scope to check
      Returns:
      true if sales streams were specified in units
    • ensurePositive

      public static BigDecimal ensurePositive(BigDecimal value)
      Ensures a value is positive, clamping to zero if negative.

      This method checks if a value would be negative and returns zero if so, otherwise returns the value unchanged. It's used to enforce constraints that prevent negative stream values when the operation being performed doesn't allow them.

      Parameters:
      value - The value to check
      Returns:
      The value if positive, or zero if negative
    • getDistributedRecharge

      public static BigDecimal getDistributedRecharge(String streamName, EngineNumber totalRecharge, UseKey useKey, SimulationState simulationState)
      Gets the distributed recharge amount for a specific stream.

      This method distributes total recharge volume across sales streams based on their current distribution percentages. The sales stream receives 100% of the recharge (to be distributed internally), sales substreams (domestic/import) receive their proportional share, and other streams receive zero.

      Parameters:
      streamName - The name of the stream
      totalRecharge - The total recharge amount
      useKey - The use key containing application and substance
      simulationState - The simulation state to query for distribution
      Returns:
      The distributed recharge amount based on stream percentages
      Throws:
      IllegalArgumentException - if streamName is a sales substream but not domestic or import