Package de.alpharogroup.random.object
Class RandomObjectFactory
- java.lang.Object
-
- de.alpharogroup.random.object.RandomObjectFactory
-
public final class RandomObjectFactory extends java.lang.ObjectA factory for creating random objects
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static de.alpharogroup.random.enums.RandomAlgorithmnewRandomAlgorithm()Factory method for create a new randomRandomAlgorithmobjectstatic java.lang.Byte[]newRandomByteObjects(int length)Factory method for create a new randomByteobject arraystatic java.lang.FloatnewRandomFloat(int afterComma, int beforeComma)Factory method for create a new randomFloatobjectstatic <T> TnewRandomObject(java.lang.Class<T> cls, java.lang.String... ignoreFieldNames)Factory method for create a new random object of the givenClass.static java.lang.ObjectnewRandomValue(java.lang.reflect.Field field)Factory method for create a new random value for the givenfieldstatic <T> TsetRandomValues(java.lang.Class<T> cls, T instance, java.lang.String... ignoreFieldNames)Sets the random values to the fields of the given instance
-
-
-
Method Detail
-
newRandomAlgorithm
public static de.alpharogroup.random.enums.RandomAlgorithm newRandomAlgorithm()
Factory method for create a new randomRandomAlgorithmobject- Returns:
- the random algorithm
-
newRandomByteObjects
public static java.lang.Byte[] newRandomByteObjects(int length)
Factory method for create a new randomByteobject array- Parameters:
length- the length.- Returns:
- the new random
Byteobject array
-
newRandomFloat
public static java.lang.Float newRandomFloat(int afterComma, int beforeComma)Factory method for create a new randomFloatobject- Parameters:
afterComma- How many decimal places after the commabeforeComma- How many decimal places before the comma- Returns:
- the new random
Floatobject
-
newRandomObject
public static <T> T newRandomObject(java.lang.Class<T> cls, java.lang.String... ignoreFieldNames) throws java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.NoSuchFieldExceptionFactory 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:
java.lang.IllegalAccessException- is thrown if the class or its default constructor is not accessible.java.lang.InstantiationException- is thrown if thisClassrepresents 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.NoSuchFieldExceptionFactory method for create a new random value for the givenfield- 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 thisClassrepresents 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.NoSuchFieldExceptionSets 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 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 thisClassrepresents 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
-
-