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 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 <T> T newRandomObject​(T obj, java.lang.String... ignoreFieldNames)
      Factory method for create a new random object of the given object
      static java.lang.Object newRandomValue​(java.lang.reflect.Field field)
      Factory method for create a new random value for the given field
      static byte[] newSalt()
      Factory method for create a new random salt.
      static <T extends java.lang.Enum<?>>
      T
      randomEnumFromClass​(java.lang.Class<T> clazz)
      Gets the random enum.
      static <T extends java.lang.Enum<?>>
      T
      randomEnumFromClassname​(java.lang.String classname)
      Gets the random enum.
      static <T extends java.lang.Enum<?>>
      T
      randomEnumFromEnumValues​(T[] values)
      Gets the random enum.
      static <T extends java.lang.Enum<?>>
      T
      randomEnumFromObject​(T obj)
      Gets the random enum.
      static <T> int randomIndex​(java.util.Collection<T> list)
      Returns a random index from the given List.
      static <K,​V>
      java.lang.Object
      randomKey​(java.util.Map<K,​V> map)
      Returns a random key from the given map.
      static <T> T randomListEntry​(java.util.List<T> list)
      Returns a random entry from the given List.
      static <K,​V>
      java.lang.Object
      randomMapEntry​(java.util.Map<K,​V> map)
      Returns a random entry from the given map.
      static java.awt.Point randomNeighborPoint​(java.awt.Point fromPoint)
      Gets a random neighbor Point object around of the given Point object
      static java.awt.Point randomNeighborPoint​(java.awt.Point fromPoint, boolean withNegativeValues)
      Gets a random neighbor Point object around of the given Point object
      static int randomPixel()
      Generates a random int for use with pixel.
      static int randomPixel​(int red, int green, int blue, int alpha)
      Generates a random int for use with pixel.
      static byte[] randomSalt​(int length, java.nio.charset.Charset charset)
      Gets the random salt.
      static java.lang.String randomToken()
      Returns a random token for use in web services.
      static java.util.UUID randomUUID()
      Factory method for create a new random UUID
      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 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
      • newRandomObject

        public static <T> T newRandomObject​(T obj,
                                            java.lang.String... ignoreFieldNames)
                                     throws java.lang.IllegalAccessException,
                                            java.lang.InstantiationException,
                                            java.lang.NoSuchFieldException,
                                            java.lang.ClassNotFoundException
        Factory method for create a new random object of the given object
        Type Parameters:
        T - the generic type
        Parameters:
        obj - the object
        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
        java.lang.ClassNotFoundException - is thrown if the class cannot be located
      • 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 field names to ignore
        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
      • randomListEntry

        public static <T> T randomListEntry​(java.util.List<T> list)
        Returns a random entry from the given List.
        Type Parameters:
        T - the generic type
        Parameters:
        list - The List.
        Returns:
        Return's a random entry from the List.
      • randomMapEntry

        public static <K,​V> java.lang.Object randomMapEntry​(java.util.Map<K,​V> map)
        Returns a random entry from the given map.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map - The map.
        Returns:
        Return's a random entry from the map.
      • randomEnumFromClass

        public static <T extends java.lang.Enum<?>> T randomEnumFromClass​(java.lang.Class<T> clazz)
        Gets the random enum.
        Type Parameters:
        T - the generic type
        Parameters:
        clazz - the clazz
        Returns:
        the random enum
      • randomEnumFromClassname

        public static <T extends java.lang.Enum<?>> T randomEnumFromClassname​(java.lang.String classname)
        Gets the random enum.
        Type Parameters:
        T - the generic type
        Parameters:
        classname - the classname
        Returns:
        the random enum
      • randomEnumFromEnumValues

        public static <T extends java.lang.Enum<?>> T randomEnumFromEnumValues​(T[] values)
        Gets the random enum.
        Type Parameters:
        T - the generic type
        Parameters:
        values - the values
        Returns:
        the random enum
      • randomEnumFromObject

        public static <T extends java.lang.Enum<?>> T randomEnumFromObject​(T obj)
        Gets the random enum.
        Type Parameters:
        T - the generic type
        Parameters:
        obj - the obj
        Returns:
        the random enum
      • randomIndex

        public static <T> int randomIndex​(java.util.Collection<T> list)
        Returns a random index from the given List.
        Type Parameters:
        T - the generic type
        Parameters:
        list - The List.
        Returns:
        Return's a random index from the List.
      • randomKey

        public static <K,​V> java.lang.Object randomKey​(java.util.Map<K,​V> map)
        Returns a random key from the given map.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        map - The map.
        Returns:
        Return's a random key from the map.
      • randomSalt

        public static byte[] randomSalt​(int length,
                                        java.nio.charset.Charset charset)
        Gets the random salt.
        Parameters:
        length - the length
        charset - the charset
        Returns:
        the random salt
      • randomPixel

        public static int randomPixel()
        Generates a random int for use with pixel.
        Returns:
        a random int for use with pixel.
      • randomPixel

        public static int randomPixel​(int red,
                                      int green,
                                      int blue,
                                      int alpha)
        Generates a random int for use with pixel.
        Parameters:
        red - The red value.
        green - The green value.
        blue - The blue value.
        alpha - The alpha value.
        Returns:
        a random int for use with pixel.
      • newSalt

        public static byte[] newSalt()
        Factory method for create a new random salt.
        Returns:
        the byte[] with the new random salt.
      • randomNeighborPoint

        public static java.awt.Point randomNeighborPoint​(java.awt.Point fromPoint)
        Gets a random neighbor Point object around of the given Point object
        Parameters:
        fromPoint - The Point object to start
        Returns:
        a random point around from the given Point object
      • randomNeighborPoint

        public static java.awt.Point randomNeighborPoint​(java.awt.Point fromPoint,
                                                         boolean withNegativeValues)
        Gets a random neighbor Point object around of the given Point object
        Parameters:
        fromPoint - The Point object to start
        withNegativeValues - The flag if negative values are allowed for x or y
        Returns:
        a random point around from the given Point object
      • randomToken

        public static java.lang.String randomToken()
        Returns a random token for use in web services.
        Returns:
        A random token.
      • randomUUID

        public static java.util.UUID randomUUID()
        Factory method for create a new random UUID
        Returns:
        the new random UUID