Class EasyRandom

  • All Implemented Interfaces:
    java.io.Serializable

    public class EasyRandom
    extends java.util.Random
    Extension of Random that is able to generate random Java objects.
    Author:
    Mahmoud Ben Hassine ([email protected])
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T nextObject​(java.lang.Class<T> type)
      Generate a random instance of the given type.
      <T> java.util.stream.Stream<T> objects​(java.lang.Class<T> type, int streamSize)
      Generate a stream of random instances of the given type.
      • Methods inherited from class java.util.Random

        doubles, doubles, doubles, doubles, ints, ints, ints, ints, longs, longs, longs, longs, next, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong, setSeed
      • Methods inherited from class java.lang.Object

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

      • EasyRandom

        public EasyRandom()
        Create a new EasyRandom instance with default parameters.
      • EasyRandom

        public EasyRandom​(EasyRandomParameters easyRandomParameters)
        Create a new EasyRandom instance.
        Parameters:
        easyRandomParameters - randomization parameters
    • Method Detail

      • nextObject

        public <T> T nextObject​(java.lang.Class<T> type)
        Generate a random instance of the given type.
        Type Parameters:
        T - the actual type of the target object
        Parameters:
        type - the type for which an instance will be generated
        Returns:
        a random instance of the given type
        Throws:
        ObjectCreationException - when unable to create a new instance of the given type
      • objects

        public <T> java.util.stream.Stream<T> objects​(java.lang.Class<T> type,
                                                      int streamSize)
        Generate a stream of random instances of the given type.
        Type Parameters:
        T - the actual type of the target objects
        Parameters:
        type - the type for which instances will be generated
        streamSize - the number of instances to generate
        Returns:
        a stream of random instances of the given type
        Throws:
        ObjectCreationException - when unable to create a new instance of the given type