Class RandomObjectFactory

java.lang.Object
io.github.astrapi69.random.object.RandomObjectFactory

public final class RandomObjectFactory extends Object
A factory for creating random objects
  • Method Details

    • newRandomAlgorithm

      public static RandomAlgorithm newRandomAlgorithm()
      Factory method for create a new random RandomAlgorithm object
      Returns:
      the random algorithm
    • newRandomByteObjects

      public static Byte[] newRandomByteObjects(int length)
      Factory method for create a new random Byte object array
      Parameters:
      length - the length.
      Returns:
      the new random Byte object array
    • newRandomFloat

      public static Float newRandomFloat(int afterComma, int beforeComma)
      Factory method for create a new random Float object
      Parameters:
      afterComma - How many decimal places after the comma
      beforeComma - 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 given Class.
      Type Parameters:
      T - the generic type
      Parameters:
      cls - the class
      ignoreFieldNames - 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 this Class 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 object
      ignoreFieldNames - 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 this Class 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
      ClassNotFoundException - 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 given field
      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 this Class 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 cls
      instance - the instance to set random values
      ignoreFieldNames - 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 this Class 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

      public static <T> T randomListEntry(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> Object randomMapEntry(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.
    • randomEnumFromClass

      public static <T extends Enum<?>> T randomEnumFromClass(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 Enum<?>> T randomEnumFromClassname(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 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 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(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> Object randomKey(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.
    • randomSalt

      public static byte[] randomSalt(int length, Charset charset)
      Gets the random salt.
      Parameters:
      length - the length
      charset - 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 Point randomNeighborPoint(Point fromPoint)
      Gets a random neighbor Point object around of the given Point object
      Parameters:
      fromPoint - The Point object to start
      Returns:
      a random point around from the given Point object
    • randomNeighborPoint

      public static Point randomNeighborPoint(Point fromPoint, boolean withNegativeValues)
      Gets a random neighbor Point object around of the given Point object
      Parameters:
      fromPoint - The Point object to start
      withNegativeValues - The flag if negative values are allowed for x or y
      Returns:
      a random point around from the given Point object
    • randomToken

      public static String randomToken()
      Returns a random token for use in web services.
      Returns:
      A random token.
    • randomUUID

      public static UUID randomUUID()
      Factory method for create a new random UUID
      Returns:
      the new random UUID