Class RandomObjectFactory


  • public final class RandomObjectFactory
    extends java.lang.Object
    A factory for creating random objects
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static de.alpharogroup.random.enums.RandomAlgorithm newRandomAlgorithm()
      Factory method for create a new random RandomAlgorithm object
      static java.lang.Byte[] newRandomByteObjects​(int length)
      Factory method for create a new random Byte object array
      static java.lang.Float newRandomFloat​(int afterComma, int beforeComma)
      Factory method for create a new random Float object
      static <T> T newRandomObject​(java.lang.Class<T> cls, java.lang.String... ignoreFieldNames)
      Factory method for create a new random object of the given Class.
      static java.lang.Object newRandomValue​(java.lang.reflect.Field field)
      Factory method for create a new random value for the given field
      static <T> T setRandomValues​(java.lang.Class<T> cls, T instance, java.lang.String... ignoreFieldNames)
      Sets the random values to the fields of the given instance
      • Methods inherited from class java.lang.Object

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

      • newRandomAlgorithm

        public static de.alpharogroup.random.enums.RandomAlgorithm newRandomAlgorithm()
        Factory method for create a new random RandomAlgorithm object
        Returns:
        the random algorithm
      • newRandomByteObjects

        public static java.lang.Byte[] newRandomByteObjects​(int length)
        Factory method for create a new random Byte object array
        Parameters:
        length - the length.
        Returns:
        the new random Byte object array
      • newRandomFloat

        public static java.lang.Float newRandomFloat​(int afterComma,
                                                     int beforeComma)
        Factory method for create a new random Float object
        Parameters:
        afterComma - How many decimal places after the comma
        beforeComma - How many decimal places before the comma
        Returns:
        the new random Float object
      • newRandomObject

        public static <T> T newRandomObject​(java.lang.Class<T> cls,
                                            java.lang.String... ignoreFieldNames)
                                     throws java.lang.IllegalAccessException,
                                            java.lang.InstantiationException,
                                            java.lang.NoSuchFieldException
        Factory method for create a new random object of the given Class.
        Type Parameters:
        T - the generic type
        Parameters:
        cls - the class
        ignoreFieldNames - an optional array with the field names that shell be ignored
        Returns:
        the new random object
        Throws:
        java.lang.IllegalAccessException - is thrown if the class or its default constructor is not accessible.
        java.lang.InstantiationException - is thrown if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no default constructor; or if the instantiation fails for some other reason.
        java.lang.NoSuchFieldException - is thrown if no such field exists
      • newRandomValue

        public static java.lang.Object newRandomValue​(java.lang.reflect.Field field)
                                               throws java.lang.IllegalAccessException,
                                                      java.lang.InstantiationException,
                                                      java.lang.NoSuchFieldException
        Factory method for create a new random value for the given field
        Parameters:
        field - the field
        Returns:
        the new random value
        Throws:
        java.lang.IllegalAccessException - is thrown if the class or its default constructor is not accessible.
        java.lang.InstantiationException - is thrown if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no default constructor; or if the instantiation fails for some other reason.
        java.lang.NoSuchFieldException - is thrown if no such field exists
      • setRandomValues

        public static <T> T setRandomValues​(java.lang.Class<T> cls,
                                            T instance,
                                            java.lang.String... ignoreFieldNames)
                                     throws java.lang.IllegalAccessException,
                                            java.lang.InstantiationException,
                                            java.lang.NoSuchFieldException
        Sets the random values to the fields of the given instance
        Type Parameters:
        T - the generic type
        Parameters:
        cls - the cls
        instance - the instance to set random values
        ignoreFieldNames - the ignore field names
        Returns:
        the new random object
        Throws:
        java.lang.IllegalAccessException - is thrown if the class or its default constructor is not accessible.
        java.lang.InstantiationException - is thrown if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no default constructor; or if the instantiation fails for some other reason.
        java.lang.NoSuchFieldException - is thrown if no such field exists