Class Episodes

java.lang.Object
org.machanism.machai.gw.processor.Episodes

public class Episodes extends Object
Maintains ordered act episodes and provides execution helpers for normal, selected, repeated, and redirected episode flow.
  • Constructor Details

    • Episodes

      public Episodes()
  • Method Details

    • setSelectedEpisodes

      public void setSelectedEpisodes(List<Integer> selectedEpisodeIds)
      Sets the list of explicitly requested episode identifiers.
      Parameters:
      selectedEpisodeIds - 1-based episode identifiers to execute
      Throws:
      IllegalArgumentException - if any identifier is outside the available episode range
    • getEpisodeIdByName

      public int getEpisodeIdByName(String episodeName)
      Returns the zero-based index of the episode whose prompt text contains a heading that matches the specified episode name.

      The method scans each episode's prompt text, extracts the first line that appears between the heading marker "# " and the next newline character, trims any leading or trailing whitespace, and compares it to the provided episodeName. If a match is found, the corresponding episode index is returned.

      Example:

       episodes.get(0): "# Introduction\nWelcome to the show!"
       episodes.get(1): "# Recap\nLast time on our show..."
      
       getEpisodeIdByName("Recap") returns 1
       getEpisodeIdByName("Introduction") returns 0
       
      Parameters:
      episodeName - the heading text to match (e.g., "Recap")
      Returns:
      the zero-based index of the matching episode
      Throws:
      EpisodeNotFoundException - if no episode with the specified heading exists
    • getEpisodeName

      public String getEpisodeName(int episodeId)
      Extracts and returns the episode name (heading) from the prompt text of the episode at the specified index.

      The method retrieves the episode prompt at index i, extracts the substring between the first occurrence of the heading marker "#" and the next newline character, and trims any leading or trailing whitespace. If the extracted heading is empty after trimming, null is returned.

      Example:

       episodes.get(0): "# Introduction\nWelcome to the show!"
       getEpisodeName(0) returns "Introduction"
       
      Parameters:
      episodeId - the zero-based index of the episode
      Returns:
      the trimmed episode name, or null if no heading is found or the heading is empty
    • regularOrder

      public void regularOrder(Integer startEpisodeId, BiFunction<Integer,String,String> func)
      Executes episodes in regular order starting from the supplied zero-based index while honoring repeat and move requests.
      Parameters:
      startEpisodeId - starting zero-based episode index
      func - callback used to execute an episode
    • requestedOrder

      public int requestedOrder(BiFunction<Integer,String,String> func)
      Executes only the explicitly selected episodes in their requested order.
      Parameters:
      func - callback used to execute an episode
      Returns:
      the last processed selection index
    • getEpisodeId

      public Integer getEpisodeId(Integer requestedEpisodeId, MoveToEpisodeException e)
      Resolves the next episode index from a move request exception.
      Parameters:
      requestedEpisodeId - current fallback episode index
      e - exception describing the requested move
      Returns:
      resolved zero-based episode index
    • setEpisodes

      public void setEpisodes(List<String> episodes)
      Replaces the current ordered episode list.
      Parameters:
      episodes - episode prompts to execute
    • getEpisodes

      public List<String> getEpisodes()
      Returns the configured episode prompts.
      Returns:
      configured episode prompt list
    • isRegularOrder

      public boolean isRegularOrder()
      Returns whether no explicit episode subset has been selected.
      Returns:
      true when regular order should be used
    • size

      public int size()
      Returns the number of configured episodes.
      Returns:
      episode count
    • getEpisodeInformation

      public String getEpisodeInformation(int episodeId)
      Builds act metadata that is prepended to an episode prompt.
      Parameters:
      episodeId - zero-based current episode index
      Returns:
      formatted act metadata block
    • getName

      public String getName()
      Returns the act name associated with these episodes.
      Returns:
      act name
    • setName

      public void setName(String name)
      Sets the act name associated with these episodes.
      Parameters:
      name - act name