Class RandomObjectFactory
- java.lang.Object
-
- io.github.astrapi69.random.object.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 randomRandomAlgorithm
objectstatic java.lang.Byte[]
newRandomByteObjects(int length)
Factory method for create a new randomByte
object arraystatic java.lang.Float
newRandomFloat(int afterComma, int beforeComma)
Factory method for create a new randomFloat
objectstatic <T> T
newRandomObject(java.lang.Class<T> cls, java.lang.String... ignoreFieldNames)
Factory method for create a new random object of the givenClass
.static <T> T
newRandomObject(T obj, java.lang.String... ignoreFieldNames)
Factory method for create a new random object of the given objectstatic java.lang.Object
newRandomValue(java.lang.reflect.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 java.lang.Enum<?>>
TrandomEnumFromClass(java.lang.Class<T> clazz)
Gets the random enum.static <T extends java.lang.Enum<?>>
TrandomEnumFromClassname(java.lang.String classname)
Gets the random enum.static <T extends java.lang.Enum<?>>
TrandomEnumFromEnumValues(T[] values)
Gets the random enum.static <T extends java.lang.Enum<?>>
TrandomEnumFromObject(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.ObjectrandomKey(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.ObjectrandomMapEntry(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 neighborPoint
object around of the givenPoint
objectstatic java.awt.Point
randomNeighborPoint(java.awt.Point fromPoint, boolean withNegativeValues)
Gets a random neighborPoint
object around of the givenPoint
objectstatic 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 randomUUID
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
-
-
-
Method Detail
-
newRandomAlgorithm
public static RandomAlgorithm newRandomAlgorithm()
Factory method for create a new randomRandomAlgorithm
object- Returns:
- the random algorithm
-
newRandomByteObjects
public static java.lang.Byte[] newRandomByteObjects(int length)
Factory method for create a new randomByte
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 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(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 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 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.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 objectignoreFieldNames
- 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 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.java.lang.NoSuchFieldException
- is thrown if no such field existsjava.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 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 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.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 clsinstance
- the instance to set random valuesignoreFieldNames
- 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 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.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 typeV
- 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 typeV
- 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 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
public static java.awt.Point randomNeighborPoint(java.awt.Point fromPoint)
Gets a random neighborPoint
object around of the givenPoint
object- Parameters:
fromPoint
- ThePoint
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 neighborPoint
object around of the givenPoint
object- Parameters:
fromPoint
- ThePoint
object to startwithNegativeValues
- 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 randomUUID
- Returns:
- the new random
UUID
-
-