Package de.alpharogroup.random
Class RandomExtensions
- java.lang.Object
-
- de.alpharogroup.random.RandomExtensions
-
public final class RandomExtensions extends java.lang.ObjectUtility 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> TgetRandomEntry(java.util.List<T> list)Returns a random entry from the given List.static <K,V>
java.lang.ObjectgetRandomEntry(java.util.Map<K,V> map)Returns a random entry from the given map.static <T extends java.lang.Enum<?>>
TgetRandomEnumFromClass(java.lang.Class<T> clazz)Gets the random enum.static <T extends java.lang.Enum<?>>
TgetRandomEnumFromClassname(java.lang.String classname)Gets the random enum.static <T extends java.lang.Enum<?>>
TgetRandomEnumFromEnumValues(T[] values)Gets the random enum.static <T extends java.lang.Enum<?>>
TgetRandomEnumFromObject(T obj)Gets the random enum.static java.lang.StringgetRandomHexString(int numberOfCharacters)Generates a random hexadecimalStringstatic <T> intgetRandomIndex(java.util.Collection<T> list)Returns a random index from the given List.static <K,V>
java.lang.ObjectgetRandomKey(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 intnewRandomPixel()Generates a random int for use with pixel.static intnewRandomPixel(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.BigIntegerrandomSerialNumber()Returns a random serial number that can be used for a serial number.static java.lang.StringrandomToken()Returns a random token for use in web services.static java.util.UUIDrandomUUID()Factory method for create a new randomUUID
-
-
-
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 typeV- 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 hexadecimalString- 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 typeV- 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 lengthcharset- 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
BigIntegerobject.
-
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 randomUUID- Returns:
- the new random
UUID
-
-