Class SimpleJumbleStrategy

java.lang.Object
com.slinky.hackmaster.model.text.SimpleJumbleStrategy
All Implemented Interfaces:
JumbleStrategy

public class SimpleJumbleStrategy extends Object implements JumbleStrategy
Implements the JumbleStrategy to generate a jumbled string by inserting random symbols between words from an input list to achieve a specified size.

This strategy uses a static array of symbols to randomly intersperse these characters among the words in the provided list. The goal is to reach a total character count specified by the size parameter, ensuring that each word from the input is included once and the total length matches the specified size. If the desired size is smaller than the combined length of all input words, an IllegalArgumentException is thrown.

The SimpleJumbleStrategy class leverages the StringUtil.countCharacters(java.lang.String[]) to calculate the total number of characters in the input word list and uses methods from ThreadLocalRandom.current() to generate random indices for symbol insertion.

Author:
Kheagen Haskins
  • Constructor Details

    • SimpleJumbleStrategy

      public SimpleJumbleStrategy()
  • Method Details

    • jumble

      public String jumble(String[] wordList, int size)
      Generates a string with the specified size, inserting random symbols between the words.

      The generated string includes each word from the list with random symbols added between them to reach the specified size.

      Specified by:
      jumble in interface JumbleStrategy
      Parameters:
      wordList - The list of words to be interspersed.
      size - the desired size of the game string.
      Returns:
      the generated game string.