Class Episodes
java.lang.Object
org.machanism.machai.gw.processor.Episodes
Maintains ordered act episodes and provides execution helpers for normal,
selected, repeated, and redirected episode flow.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetEpisodeId(Integer requestedEpisodeId, MoveToEpisodeException e) Resolves the next episode index from a move request exception.intgetEpisodeIdByName(String episodeName) Returns the zero-based index of the episode whose prompt text contains a heading that matches the specified episode name.getEpisodeInformation(int episodeId) Builds act metadata that is prepended to an episode prompt.getEpisodeName(int episodeId) Extracts and returns the episode name (heading) from the prompt text of the episode at the specified index.Returns the configured episode prompts.getName()Returns the act name associated with these episodes.booleanReturns whether no explicit episode subset has been selected.voidregularOrder(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.intrequestedOrder(BiFunction<Integer, String, String> func) Executes only the explicitly selected episodes in their requested order.voidsetEpisodes(List<String> episodes) Replaces the current ordered episode list.voidSets the act name associated with these episodes.voidsetSelectedEpisodes(List<Integer> selectedEpisodeIds) Sets the list of explicitly requested episode identifiers.intsize()Returns the number of configured episodes.
-
Constructor Details
-
Episodes
public Episodes()
-
-
Method Details
-
setSelectedEpisodes
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
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
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,nullis 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
nullif no heading is found or the heading is empty
-
regularOrder
Executes episodes in regular order starting from the supplied zero-based index while honoring repeat and move requests.- Parameters:
startEpisodeId- starting zero-based episode indexfunc- callback used to execute an episode
-
requestedOrder
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
Resolves the next episode index from a move request exception.- Parameters:
requestedEpisodeId- current fallback episode indexe- exception describing the requested move- Returns:
- resolved zero-based episode index
-
setEpisodes
Replaces the current ordered episode list.- Parameters:
episodes- episode prompts to execute
-
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:
truewhen regular order should be used
-
size
public int size()Returns the number of configured episodes.- Returns:
- episode count
-
getEpisodeInformation
Builds act metadata that is prepended to an episode prompt.- Parameters:
episodeId- zero-based current episode index- Returns:
- formatted act metadata block
-
getName
Returns the act name associated with these episodes.- Returns:
- act name
-
setName
Sets the act name associated with these episodes.- Parameters:
name- act name
-