<commit_before>/**
 * 
 */
package edu.ucdenver.ccp.datasource.fileparsers;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import edu.ucdenver.ccp.common.reflection.PrivateAccessor;

/**
 * A utility class for handling {@link Record} and {@link RecordField} annotations
 * 
 * @author Colorado Computational Pharmacology, UC Denver; <EMAIL>
 * 
 */
public class RecordUtil {

	/**
	 * @param record
	 * @return a mapping from {@link Field} to {@link RecordField} annotation for those fields that
	 *         have RecordField annotations in the input {@link DataRecord}
	 */
	public static Map<Field, RecordField> getFieldToRecordFieldAnnotationsMap(DataRecord record) {
		Map<Field, RecordField> fieldNameToRecordFieldAnnotationMap = new HashMap<Field, RecordField>();
		Set<Field> fields = PrivateAccessor.getAllFields(record.getClass(), new HashSet<Field>());
		for (Field field : fields) {
			if (field.isAnnotationPresent(RecordField.class)) {
				fieldNameToRecordFieldAnnotationMap.put(field, field.getAnnotation(RecordField.class));
			}
		}
		return fieldNameToRecordFieldAnnotationMap;
	}

	public static Record getRecordAnnotation(Class<? extends DataRecord> recordClass) {
		if (recordClass.isAnnotationPresent(Record.class)) {
			return recordClass.getAnnotation(Record.class);
		}
		throw new IllegalArgumentException("Detected missing Record annotation. Please add a Record annotation to the "
				+ recordClass.getName() + " class.");
	}

	/**
	 * @param recordClass
	 * @return
	 */
	public static String getRecordSchemaVersion(Class<? extends DataRecord> recordClass) {
		return getRecordAnnotation(recordClass).schemaVersion();
	}

	/**
	 * @param recordClass
	 * @param name
	 * @return
	 */
	public static String getRecordFieldVersion(Class<?> recordClass, String fieldName) {
		Set<Field> fields = PrivateAccessor.getAllFields(recordClass, new HashSet<Field>());
		for (Field field : fields) {
			if (field.getName().equals(fieldName)) {
				if (field.isAnnotationPresent(RecordField.class)) {
					return field.getAnnotation(RecordField.class).version();
				}
				throw new IllegalArgumentException(
						"Detected missing RecordField annotation. Please add a RecordField annotation to the '"
								+ fieldName + "' field in the " + recordClass.getName() + " class.");
			}
		}
		throw new IllegalArgumentException("The '" + fieldName + "' field does not exist in class: "
				+ recordClass.getName());
	}

	private RecordUtil() {
		// this class should not be instantiated
	}
}
<commit_msg>added more helper methods to get Record and RecordField annotation parameters<commit_after>/**
 * 
 */
package edu.ucdenver.ccp.datasource.fileparsers;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import edu.ucdenver.ccp.common.reflection.PrivateAccessor;
import edu.ucdenver.ccp.datasource.identifiers.DataSource;

/**
 * A utility class for handling {@link Record} and {@link RecordField} annotations
 * 
 * @author Colorado Computational Pharmacology, UC Denver; <EMAIL>
 * 
 */
public class RecordUtil {

	/**
	 * @param record
	 * @return a mapping from {@link Field} to {@link RecordField} annotation for those fields that
	 *         have RecordField annotations in the input {@link DataRecord}
	 */
	public static Map<Field, RecordField> getFieldToRecordFieldAnnotationsMap(Class<? extends DataRecord> recordClass) {
		Map<Field, RecordField> fieldNameToRecordFieldAnnotationMap = new HashMap<Field, RecordField>();
		Set<Field> fields = PrivateAccessor.getAllFields(recordClass, new HashSet<Field>());
		for (Field field : fields) {
			if (field.isAnnotationPresent(RecordField.class)) {
				fieldNameToRecordFieldAnnotationMap.put(field, field.getAnnotation(RecordField.class));
			}
		}
		return fieldNameToRecordFieldAnnotationMap;
	}

	public static Record getRecordAnnotation(Class<? extends DataRecord> recordClass) {
		if (recordClass.isAnnotationPresent(Record.class)) {
			return recordClass.getAnnotation(Record.class);
		}
		throw new IllegalArgumentException("Detected missing Record annotation. Please add a Record annotation to the "
				+ recordClass.getName() + " class.");
	}

	public static DataSource getRecordDataSource(Class<? extends DataRecord> recordClass) {
		return getRecordAnnotation(recordClass).dataSource();
	}

	public static String getRecordComment(Class<? extends DataRecord> recordClass) {
		return getRecordAnnotation(recordClass).comment();
	}

	/**
	 * @param recordClass
	 * @return
	 */
	public static String getRecordSchemaVersion(Class<? extends DataRecord> recordClass) {
		return getRecordAnnotation(recordClass).schemaVersion();
	}

	/**
	 * @param recordClass
	 * @param name
	 * @return
	 */
	public static RecordField getRecordFieldAnnotation(Class<? extends DataRecord> recordClass, String fieldName) {
		Set<Field> fields = PrivateAccessor.getAllFields(recordClass, new HashSet<Field>());
		for (Field field : fields) {
			if (field.getName().equals(fieldName)) {
				if (field.isAnnotationPresent(RecordField.class)) {
					return field.getAnnotation(RecordField.class);
				}
				throw new IllegalArgumentException(
						"Detected missing RecordField annotation. Please add a RecordField annotation to the '"
								+ fieldName + "' field in the " + recordClass.getName() + " class.");
			}
		}
		throw new IllegalArgumentException("The '" + fieldName + "' field does not exist in class: "
				+ recordClass.getName());
	}

	public static String getRecordFieldVersion(Class<? extends DataRecord> recordClass, String fieldName) {
		return getRecordFieldAnnotation(recordClass, fieldName).version();
	}

	public static String getRecordFieldComment(Class<? extends DataRecord> recordClass, String fieldName) {
		return getRecordFieldAnnotation(recordClass, fieldName).comment();
	}

	public static boolean isKeyRecordField(Class<? extends DataRecord> recordClass, String fieldName) {
		return getRecordFieldAnnotation(recordClass, fieldName).isKeyField();
	}

	private RecordUtil() {
		// this class should not be instantiated
	}
}

{'fraction_non_alphanumeric': 0.1065242026873887, 'fraction_numerical': 0.0, 'mean_word_length': 4.895038167938932, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '3755903', 'n_tokens_mistral': 1854, 'n_tokens_neox': 1663, 'n_words': 452}