Class SampleGenerator<E>

  • Type Parameters:
    E - the type parameter
    All Implemented Interfaces:
    Generator<E>, com.rapiddweller.common.Resettable, com.rapiddweller.common.ThreadAware, java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    NonNullSampleGenerator

    public class SampleGenerator<E>
    extends AbstractSampleGenerator<E>
    Generates values from a non-weighted list of samples, applying an explicitly defined distribution.

    Created: 07.06.2006 19:04:08
    Since:
    0.1
    Author:
    Volker Bergmann
    • Constructor Detail

      • SampleGenerator

        public SampleGenerator()
        Instantiates a new Sample generator.
      • SampleGenerator

        public SampleGenerator​(java.lang.Class<E> generatedType)
        Initializes the generator to an empty sample list
        Parameters:
        generatedType - the generated type
      • SampleGenerator

        @SafeVarargs
        public SampleGenerator​(java.lang.Class<E> generatedType,
                               E... values)
        Initializes the generator to a sample list
        Parameters:
        generatedType - the generated type
        values - the values
      • SampleGenerator

        @SafeVarargs
        public SampleGenerator​(java.lang.Class<E> generatedType,
                               Distribution distribution,
                               E... values)
        Initializes the generator to a sample list
        Parameters:
        generatedType - the generated type
        distribution - the distribution
        values - the values
      • SampleGenerator

        public SampleGenerator​(java.lang.Class<E> generatedType,
                               java.lang.Iterable<E> values)
        Initializes the generator to a sample list
        Parameters:
        generatedType - the generated type
        values - the values
      • SampleGenerator

        public SampleGenerator​(java.lang.Class<E> generatedType,
                               Distribution distribution,
                               boolean unique,
                               java.lang.Iterable<E> values)
        Initializes the generator to a sample list
        Parameters:
        generatedType - the generated type
        distribution - the distribution
        unique - the unique
        values - the values
    • Method Detail

      • generate

        @SafeVarargs
        public static <T> T generate​(T... samples)
        Convenience utility method that chooses one sample out of a list with uniform random distribution
        Type Parameters:
        T - the type parameter
        Parameters:
        samples - the samples
        Returns:
        the t
      • generate

        public static <T> T generate​(java.util.List<T> samples)
        Convenience utility method that chooses one sample out of a list with uniform random distribution
        Type Parameters:
        T - the type parameter
        Parameters:
        samples - the samples
        Returns:
        the t
      • isUnique

        public boolean isUnique()
        Is unique boolean.
        Returns:
        the boolean
      • setUnique

        public void setUnique​(boolean unique)
        Sets unique.
        Parameters:
        unique - the unique
      • contains

        public <T extends E> boolean contains​(E value)
        Contains boolean.
        Type Parameters:
        T - the type parameter
        Parameters:
        value - the value
        Returns:
        the boolean
      • addValue

        public <T extends E> void addValue​(T value)
        Adds a value to the sample list
        Specified by:
        addValue in class AbstractSampleGenerator<E>
        Type Parameters:
        T - the type parameter
        Parameters:
        value - the value
      • generate

        public ProductWrapper<E> generate​(ProductWrapper<E> wrapper)
        Description copied from interface: Generator
        Returns an instance of the generic type E, using the ProductWrapper instance provided as argument. The wrapper may wrap a null value as a regular generator product. If the generator is not available (any more), it returns null instead of the ProductWrapper instance.
        Parameters:
        wrapper - the wrapper
        Returns:
        the product wrapper
      • reset

        public void reset()
        Specified by:
        reset in interface com.rapiddweller.common.Resettable
        Overrides:
        reset in class AbstractGenerator<E>
      • close

        public void close()
        Description copied from interface: Generator
        Closes the generator. After invocation the state is unavailable.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface Generator<E>
        Overrides:
        close in class AbstractGenerator<E>