Class RandomChoice.Builder<T>

java.lang.Object
org.stubit.random.RandomChoice.Builder<T>
Enclosing class:
RandomChoice

public static class RandomChoice.Builder<T> extends Object
Randomly selects an element from a collection of choices.
  • Method Details

    • and

      public RandomChoice.Builder<T> and(Collection<T> additionalChoices)
      Add the provided additional choices to the selection
      Parameters:
      additionalChoices - the additional choices
      Returns:
      this
    • and

      @SafeVarargs public final RandomChoice.Builder<T> and(T... additionalChoices)
      Add the provided additional choices to the selection
      Parameters:
      additionalChoices - the additional choices
      Returns:
      this
    • butNot

      public RandomChoice.Builder<T> butNot(Collection<T> excluded)
      Excludes the provided choices from the selection
      Parameters:
      excluded - the excluded choices
      Returns:
      this
      Throws:
      IllegalArgumentException - if no choices remain
    • butNot

      @SafeVarargs public final RandomChoice.Builder<T> butNot(T... excluded)
      Excludes the provided choices from the selection
      Parameters:
      excluded - the excluded choices
      Returns:
      this
      Throws:
      IllegalArgumentException - if no choices remain
    • build

      public T build()
      Returns a randomly selected element from the choices.
      Returns:
      a randomly selected element form the choices