Class RandomExtensions


  • public final class RandomExtensions
    extends java.lang.Object
    Utility class for producing random data. Existing name conventions: If the method starts with random* than it returns a primitive data type. If the method starts with getRandom* than it returns an object.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T getRandomEntry​(java.util.List<T> list)
      Returns a random entry from the given List.
      static <K,​V>
      java.lang.Object
      getRandomEntry​(java.util.Map<K,​V> map)
      Returns a random entry from the given map.
      static <T extends java.lang.Enum<?>>
      T
      getRandomEnumFromClass​(java.lang.Class<T> clazz)
      Gets the random enum.
      static <T extends java.lang.Enum<?>>
      T
      getRandomEnumFromClassname​(java.lang.String classname)
      Gets the random enum.
      static <T extends java.lang.Enum<?>>
      T
      getRandomEnumFromEnumValues​(T[] values)
      Gets the random enum.
      static <T extends java.lang.Enum<?>>
      T
      getRandomEnumFromObject​(T obj)
      Gets the random enum.
      static java.lang.String getRandomHexString​(int numberOfCharacters)
      Generates a random hexadecimal String
      static <T> int getRandomIndex​(java.util.Collection<T> list)
      Returns a random index from the given List.
      static <K,​V>
      java.lang.Object
      getRandomKey​(java.util.Map<K,​V> map)
      Returns a random key from the given map.
      static byte[] getRandomSalt​(int length, java.nio.charset.Charset charset)
      Gets the random salt.
      static int newRandomPixel()
      Generates a random int for use with pixel.
      static int newRandomPixel​(int red, int green, int blue, int alpha)
      Generates a random int for use with pixel.
      static byte[] newSalt()
      Factory method for create a new random salt.
      static java.math.BigInteger randomSerialNumber()
      Returns a random serial number that can be used for a serial number.
      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
      • Methods inherited from class java.lang.Object

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

      • getRandomEntry

        public static <T> T getRandomEntry​(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.
      • getRandomEntry

        public static <K,​V> java.lang.Object getRandomEntry​(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.
      • getRandomEnumFromClass

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

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

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

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

        public static java.lang.String getRandomHexString​(int numberOfCharacters)
        Generates a random hexadecimal String
        Parameters:
        numberOfCharacters - the number of characters
        Returns:
        the generated random hexadecimal String
      • getRandomIndex

        public static <T> int getRandomIndex​(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.
      • getRandomKey

        public static <K,​V> java.lang.Object getRandomKey​(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.
      • getRandomSalt

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

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

        public static int newRandomPixel​(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.
      • randomSerialNumber

        public static java.math.BigInteger randomSerialNumber()
        Returns a random serial number that can be used for a serial number.
        Returns:
        a random serial number as a BigInteger 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