<commit_before>package metricapp.utility;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

import metricapp.entity.external.PointerBus;

/**
 * This class provides a large number of methods to generate random fields and
 * objects.
 * <p>
 * Every method can work staticly, without the need of an instance of
 * RandomGenerator. The random seed is initialized when the JVM load the class,
 * the seed is the Nanosec of the moment of charge in memory.
 * 
 * User has not to initialize this class to use it
 *
 *
 */
public class RandomGenerator {
	/**
	 * seed is time from epoch
	 */
	private static Random rnd = new Random(LocalTime.now().getNano());

	/**
	 * this function permits to fill a single field of an Object. you have to
	 * pass the object entity as Object, and the field gathered by reflection.
	 * <p>
	 * This function can randomize the content of field if it is a supported
	 * type, otherwise leave the field null. Behavior of the function is not
	 * predictable with unsupported field types
	 * 
	 * This function supports a small number of ArrayList fields.
	 * 
	 * This function could throw a large number of Exception, due to internal
	 * use of reflection with unknown classes.
	 *
	 * @param obj
	 *            is the instance to fill. (e.g. class Car has String door, you
	 *            have to pass randomAttribute(car, doorField))
	 * @param field
	 *            is the field gathered by Reflection to fill up with random
	 *            content. (e.g. Car.getClass().getAttributes()[0])
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 * @throws SecurityException
	 * @throws ClassNotFoundException
	 * @throws InstantiationException
	 */
	@SuppressWarnings("unchecked")
	static public void randomAttribute(Object obj, Field field)
			throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException,
			SecurityException, ClassNotFoundException, InstantiationException {

		
		if (field.getType().equals(String.class)) {
			//required for dto, where creationDate and LastVersionDate are Strings
			if (field.getName().equals("creationDate") || field.getName().equals("lastVersionDate")) {
				field.set(obj, RandomGenerator.randomLocalDate().toString());
			} else {
				field.set(obj, RandomGenerator.randomString());
			}
		}
		if (field.getType().equals(LocalDate.class)) {
			field.set(obj, RandomGenerator.randomLocalDate());
		}
		if (field.getType().equals(boolean.class)) {
			field.set(obj, RandomGenerator.randomBoolean());
		}
		if (field.getType().equals(double.class)) {
			field.set(obj, RandomGenerator.randomDouble());
		}
		if (field.getType().equals(List.class)) {
			try {
				field.set(obj, RandomGenerator.randomGenericArrayList(<commit_msg>fixed javadocs<commit_after>package metricapp.utility;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;

import metricapp.entity.external.PointerBus;

/**
 * This class provides a large number of methods to generate random fields and
 * objects.
 * <p>
 * Every method can work statically, without the need of an instance of
 * RandomGenerator. The random seed is initialized when the JVM load the class,
 * the seed is the Nanosec of the moment of charge in memory.
 * 
 * User has not to initialize this class to use it
 *
 *
 */
public class RandomGenerator {
	/**
	 * seed is time from epoch
	 */
	private static Random rnd = new Random(LocalTime.now().getNano());

	/**
	 * this function permits to fill a single field of an Object. you have to
	 * pass the object entity as Object, and the field gathered by reflection.
	 * <p>
	 * This function can randomize the content of field if it is a supported
	 * type, otherwise leave the field null. Behavior of the function is not
	 * predictable with unsupported field types
	 * 
	 * This function supports a small number of ArrayList fields.
	 * 
	 * This function could throw a large number of Exception, due to internal
	 * use of reflection with unknown classes.
	 * 
	 * Due to implementation, entityType can not reflect real type of object! 
	 *
	 * @param obj
	 *            is the instance to fill. (e.g. class Car has String door, you
	 *            have to pass randomAttribute(car, doorField))
	 * @param field
	 *            is the field gathered by Reflection to fill up with random
	 *            content. (e.g. Car.getClass().getAttributes()[0])
	 * @throws IllegalArgumentException
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws NoSuchMethodException
	 * @throws SecurityException
	 * @throws ClassNotFoundException
	 * @throws InstantiationException
	 * TODO fix entityType generation, the object must be setted as the right type.
	 */
	@SuppressWarnings("unchecked")
	static public void randomAttribute(Object obj, Field field)
			throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException,
			SecurityException, ClassNotFoundException, InstantiationException {

		
		if (field.getType().equals(String.class)) {
			//required for dto, where creationDate and LastVersionDate are Strings
			if (field.getName().equals("creationDate") || field.getName().equals("lastVersionDate")) {
				field.set(obj, RandomGenerator.randomLocalDate().toString());
			} else {
				field.set(obj, RandomGenerator.randomString());
			}
		}
		if (field.getType().equals(LocalDate.class)) {
			field.set(obj, RandomGenerator.randomLocalDate());
		}
		if (field.getType().equals(boolean.class)) {
			field.set(obj, RandomGenerator.randomBoolean());
		}
		if (field.getType().equals(double.class)) {
			field.set(obj, RandomGenerator.randomDouble());
		}
		if (field.getType().equals(List.class)) {
			try {
				field.set(obj, RandomGenerator.randomGenericArrayList(
{'fraction_non_alphanumeric': 0.09448943941559473, 'fraction_numerical': 0.0003176115610608226, 'mean_word_length': 3.9984126984126984, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3829089', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1639, 'n_words': 588}