Class RandomChoice

java.lang.Object
org.stubit.random.RandomChoice

@NullMarked public class RandomChoice extends Object
Randomly select an element from a collection of choices.
  • Method Details

    • anyOf

      public static <T> T anyOf(Collection<T> choices)
      Randomly selects an element from the provided choices Collection.
      Type Parameters:
      T - the type of the choices
      Parameters:
      choices - a Collection of choices
      Returns:
      a randomly selected element from the provided choices
    • anyOf

      public static <K, V> Map.Entry<K,V> anyOf(Map<K,V> choices)
      Randomly selects an element from the provided choices Collection.
      Type Parameters:
      K - the type of the choices' keys
      V - the type of the choices' values
      Parameters:
      choices - a Collection of choices
      Returns:
      a randomly selected element from the provided choices
    • anyOf

      @SafeVarargs public static <T> T anyOf(T... choices)
      Randomly selects an element from the provided choices.
      Type Parameters:
      T - the type of the choices
      Parameters:
      choices - an array of choices
      Returns:
      a randomly selected element from the provided choices
    • any

      public static <T extends Enum<?>> T any(Class<? extends T> enumType)
      Randomly selects an element from the values of the provided choices Enum class.
      Type Parameters:
      T - the type of the choices
      Parameters:
      enumType - the Enum type
      Returns:
      a randomly selected Enum constant from the provided choices enumType
    • aChoiceFrom

      public static <T> RandomChoice.Builder<T> aChoiceFrom(Collection<T> choices)
      Type Parameters:
      T - the type of the choices
      Parameters:
      choices - a Collection of choices
      Returns:
      a new RandomChoice.Builder with the provided choices
    • aChoiceFrom

      public static <K, V> RandomChoice.Builder<Map.Entry<K,V>> aChoiceFrom(Map<K,V> choices)
      Type Parameters:
      K - the type of the choices' keys
      V - the type of the choices' values
      Parameters:
      choices - a Collection of choices
      Returns:
      a new RandomChoice.Builder with the provided choices
    • aChoiceFrom

      @SafeVarargs public static <T> RandomChoice.Builder<T> aChoiceFrom(T... choices)
      Type Parameters:
      T - the type of the choices
      Parameters:
      choices - an array of choices
      Returns:
      a new RandomChoice.Builder with the provided choices
    • aChoiceFromValuesOf

      public static <T extends Enum<?>> RandomChoice.Builder<T> aChoiceFromValuesOf(Class<? extends T> enumType)
      Type Parameters:
      T - the type of the choices
      Parameters:
      enumType - the Enum type
      Returns:
      a new RandomChoice.Builder with the provided enumType's values as choices