Package net.datafaker

Class Options

java.lang.Object
net.datafaker.Options

public class Options extends Object
Since:
0.8.0
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Options(Faker faker)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <E> E
    nextElement(E[] array)
    Returns a random element from an array.
    <E> E
    nextElement(List<E> list)
    Returns a random element from a list.
    final <E> E
    option(E... options)
    Returns a random element from an varargs.
    <E extends Enum<E>>
    E
    option(Class<E> enumeration)
    Returns a random element from Enum.
    option(String... options)
    Returns a random String element from an varargs.
    final <E> Set<E>
    subset(int size, E... options)
    Returns a random unique subset of elements from an varargs.
    final Set<String>
    subset(int size, String... options)
    Returns a random unique subset of elements from an varargs.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Options

      protected Options(Faker faker)
  • Method Details

    • option

      @SafeVarargs public final <E> E option(E... options)
      Returns a random element from an varargs.
      Type Parameters:
      E - The type of the elements in the varargs.
      Parameters:
      options - The varargs to take a random element from.
      Returns:
      A randomly selected element from the varargs.
    • subset

      public final <E> Set<E> subset(int size, E... options)
      Returns a random unique subset of elements from an varargs.
      Type Parameters:
      E - The type of the elements in the varargs.
      Parameters:
      size - The size of subset to return.
      options - The varargs to take a random element from.
      Returns:
      A randomly selected unique subset from the varargs. If size is negative then IllegalArgumentException will be thrown. If size is zero then an empty subset will be returned. If size is larger than a unique set from options then all options will be returned.
    • option

      public String option(String... options)
      Returns a random String element from an varargs.
      Parameters:
      options - The varargs to take a random element from.
      Returns:
      A randomly selected element from the varargs.
    • subset

      public final Set<String> subset(int size, String... options)
      Returns a random unique subset of elements from an varargs.
      Parameters:
      size - The size of subset to return.
      options - The varargs to take a random element from.
      Returns:
      A randomly selected unique subset from the varargs. If size is negative then IllegalArgumentException will be thrown. If size is zero then an empty subset will be returned. If size is larger than a unique set from options then all options will be returned.
    • option

      public <E extends Enum<E>> E option(Class<E> enumeration)
      Returns a random element from Enum.
      Parameters:
      enumeration - The Enum to take a random element from.
      Returns:
      A randomly selected element from the enum.
    • nextElement

      public <E> E nextElement(E[] array)
      Returns a random element from an array.
      Type Parameters:
      E - The type of the elements in the array.
      Parameters:
      array - The array to take a random element from.
      Returns:
      A randomly selected element from the array.
    • nextElement

      public <E> E nextElement(List<E> list)
      Returns a random element from a list.
      Type Parameters:
      E - The type of the elements in the list.
      Parameters:
      list - The list to take a random element from.
      Returns:
      A randomly selected element from the list.