<commit_before>package org.fastnate.util;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;

/**
 * Helper for inspection of classes.
 *
 * @author <NAME>
 */
public final class ClassUtil {

	private static <I> Type getActualTypeArgument(final Class<? extends I> instanceClass, final Class<I> superClass,
			final int argumentIndex) {
		final List<Type> parents = new ArrayList<>();
		parents.add(instanceClass.getGenericSuperclass());
		parents.addAll(Arrays.asList(instanceClass.getGenericInterfaces()));
		for (final Type parentType : parents) {
			final Class<?> parentClass = parentType instanceof ParameterizedType
					? (Class<?>) ((ParameterizedType) parentType).getRawType() : (Class<?>) parentType;

			// First check if we found the super class or interface
			if (superClass.equals(parentClass)) {
				// We found the requested super class - use the binding
				return ((ParameterizedType) parentType).getActualTypeArguments()[argumentIndex];
			} else if (parentClass != null && superClass.isAssignableFrom(parentClass)) {
				// Else step up
				final Type type = getActualTypeArgument(parentClass.asSubclass(superClass), superClass, argumentIndex);
				if (type instanceof Class) {
					return type;<commit_msg>#23 Include support for entities with generic typed attributes<commit_after>package org.fastnate.util;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;

/**
 * Helper for inspection of classes.
 *
 * @author <NAME>
 */
public final class ClassUtil {

	private static <I> Type getActualTypeArgument(final Class<? extends I> instanceClass, final Class<I> superClass,
			final int argumentIndex) {
		if (instanceClass == superClass) {
			return instanceClass.getTypeParameters()[argumentIndex];
		}

		final List<Type> parents = new ArrayList<>();
		parents.add(instanceClass.getGenericSuperclass());
		parents.addAll(Arrays.asList(instanceClass.getGenericInterfaces()));
		for (final Type parentType : parents) {
			final Class<?> parentClass = parentType instanceof ParameterizedType
					? (Class<?>) ((ParameterizedType) parentType).getRawType() : (Class<?>) parentType;

			// First check if we found the super class or interface
			if (superClass.equals(parentClass)) {
				// We found the requested super class - use the binding
				return ((ParameterizedType) parentType).getActualTypeArguments()[argumentIndex];
			} else if (parentClass != null && superClass.isAssignableFrom(parentClass)) {
				// Else step up
				final Type type = getActualTypeArgument(parentClass.asSubclass(superClass), superClass, argumentIndex);
				if (type instanceof Class) {
					return type;
{'fraction_non_alphanumeric': 0.10863144076140466, 'fraction_numerical': 0.0006563833278634722, 'mean_word_length': 5.0717131474103585, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '6889012', 'n_tokens_mistral': 915, 'n_tokens_neox': 833, 'n_words': 234}