java.lang.Object
io.github.astrapi69.random.object.RandomObjectFactory
A factory for creating random objects
-
Method Summary
Modifier and TypeMethodDescriptionstatic RandomAlgorithm
Factory method for create a new randomRandomAlgorithm
objectstatic Byte[]
newRandomByteObjects
(int length) Factory method for create a new randomByte
object arraystatic Float
newRandomFloat
(int afterComma, int beforeComma) Factory method for create a new randomFloat
objectstatic <T> T
newRandomObject
(Class<T> cls, String... ignoreFieldNames) Factory method for create a new random object of the givenClass
.static <T> T
newRandomObject
(T obj, String... ignoreFieldNames) Factory method for create a new random object of the given objectstatic Object
newRandomValue
(Field field) Factory method for create a new random value for the givenfield
static byte[]
newSalt()
Factory method for create a new random salt.static <T extends Enum<?>>
TrandomEnumFromClass
(Class<T> clazz) Gets the random enum.static <T extends Enum<?>>
TrandomEnumFromClassname
(String classname) Gets the random enum.static <T extends Enum<?>>
TrandomEnumFromEnumValues
(T[] values) Gets the random enum.static <T extends Enum<?>>
TrandomEnumFromObject
(T obj) Gets the random enum.static <T> int
randomIndex
(Collection<T> list) Returns a random index from the given List.static <K,
V> Object Returns a random key from the given map.static <T> T
randomListEntry
(List<T> list) Returns a random entry from the given List.static <K,
V> Object randomMapEntry
(Map<K, V> map) Returns a random entry from the given map.static Point
randomNeighborPoint
(Point fromPoint) static Point
randomNeighborPoint
(Point fromPoint, boolean withNegativeValues) static int
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, Charset charset) Gets the random salt.static String
Returns a random token for use in web services.static UUID
Factory method for create a new randomUUID
static <T> T
setRandomValues
(Class<T> cls, T instance, String... ignoreFieldNames) Sets the random values to the fields of the given instance
-
Method Details
-
newRandomAlgorithm
Factory method for create a new randomRandomAlgorithm
object- Returns:
- the random algorithm
-
newRandomByteObjects
Factory method for create a new randomByte
object array- Parameters:
length
- the length.- Returns:
- the new random
Byte
object array
-
newRandomFloat
Factory method for create a new randomFloat
object- Parameters:
afterComma
- How many decimal places after the commabeforeComma
- How many decimal places before the comma- Returns:
- the new random
Float
object
-
newRandomObject
public static <T> T newRandomObject(Class<T> cls, String... ignoreFieldNames) throws IllegalAccessException, InstantiationException, NoSuchFieldException Factory method for create a new random object of the givenClass
.- Type Parameters:
T
- the generic type- Parameters:
cls
- the classignoreFieldNames
- an optional array with the field names that shell be ignored- Returns:
- the new random object
- Throws:
IllegalAccessException
- is thrown if the class or its default constructor is not accessible.InstantiationException
- is thrown if thisClass
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.NoSuchFieldException
- is thrown if no such field exists
-
newRandomObject
public static <T> T newRandomObject(T obj, String... ignoreFieldNames) throws IllegalAccessException, InstantiationException, NoSuchFieldException, ClassNotFoundException Factory method for create a new random object of the given object- Type Parameters:
T
- the generic type- Parameters:
obj
- the objectignoreFieldNames
- an optional array with the field names that shell be ignored- Returns:
- the new random object
- Throws:
IllegalAccessException
- is thrown if the class or its default constructor is not accessible.InstantiationException
- is thrown if thisClass
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.NoSuchFieldException
- is thrown if no such field existsClassNotFoundException
- is thrown if the class cannot be located
-
newRandomValue
public static Object newRandomValue(Field field) throws IllegalAccessException, InstantiationException, NoSuchFieldException Factory method for create a new random value for the givenfield
- Parameters:
field
- the field- Returns:
- the new random value
- Throws:
IllegalAccessException
- is thrown if the class or its default constructor is not accessible.InstantiationException
- is thrown if thisClass
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.NoSuchFieldException
- is thrown if no such field exists
-
setRandomValues
public static <T> T setRandomValues(Class<T> cls, T instance, String... ignoreFieldNames) throws IllegalAccessException, InstantiationException, NoSuchFieldException Sets the random values to the fields of the given instance- Type Parameters:
T
- the generic type- Parameters:
cls
- the clsinstance
- the instance to set random valuesignoreFieldNames
- the field names to ignore- Returns:
- the new random object
- Throws:
IllegalAccessException
- is thrown if the class or its default constructor is not accessible.InstantiationException
- is thrown if thisClass
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.NoSuchFieldException
- is thrown if no such field exists
-
randomListEntry
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
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.
-
randomEnumFromClass
Gets the random enum.- Type Parameters:
T
- the generic type- Parameters:
clazz
- the clazz- Returns:
- the random enum
-
randomEnumFromClassname
Gets the random enum.- Type Parameters:
T
- the generic type- Parameters:
classname
- the classname- Returns:
- the random enum
-
randomEnumFromEnumValues
Gets the random enum.- Type Parameters:
T
- the generic type- Parameters:
values
- the values- Returns:
- the random enum
-
randomEnumFromObject
Gets the random enum.- Type Parameters:
T
- the generic type- Parameters:
obj
- the obj- Returns:
- the random enum
-
randomIndex
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
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.
-
randomSalt
Gets the random salt.- Parameters:
length
- the lengthcharset
- 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
-
randomNeighborPoint
-
randomToken
Returns a random token for use in web services.- Returns:
- A random token.
-
randomUUID
Factory method for create a new randomUUID
- Returns:
- the new random
UUID
-