<commit_before>package org.lightmare.utils.reflect;

import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.AccessibleObject;

import javax.persistence.EntityManager;

import org.junit.Assert;
import org.junit.Test;
import org.lightmare.bean.LightMareBean;
import org.lightmare.entities.Email;
import org.lightmare.utils.ObjectUtils;

public class MetaUtilsTest {

    protected EntityManager em;

    @Test
    public void testDefaultValues() {

	System.out.println(MetaUtils.getDefault(byte.class));
	System.out.println(MetaUtils.getDefault(boolean.class));
	System.out.println(MetaUtils.getDefault(char.class));
	System.out.println(MetaUtils.getDefault(short.class));
	System.out.println(MetaUtils.getDefault(int.class));
	System.out.println(MetaUtils.getDefault(long.class));
	System.out.println(MetaUtils.getDefault(float.class));
	System.out.println(MetaUtils.getDefault(double.class));
    }

    @Test
    public void testAccessibleObjectInstances() {

	try {
	    AccessibleObject acc1 = MetaUtils.getDeclaredField(
		    LightMareBean.class, "em");
	    AccessibleObject acc2 = MetaUtils.getDeclaredField(
		    LightMareBean.class, "em");

	    AccessibleObject acc3 = MetaUtils.getDeclaredField(
		    MetaUtilsTest.class, "em");

	    Assert.assertTrue("AccessibleObject instances are not the same",
		    acc1.equals(acc2));
	    System.out.format("%s %s", acc1, acc2);
	    Assert.assertTrue(
		    "AccessibleObject instances should not be the same",
		    ObjectUtils.notEquals(acc1, acc3));
	    System.out.format("%s %s", acc1, acc3);
	} catch (IOException ex) {
	    ex.printStackTrace();
	}
    }

    @Test
    public void getterFinderTest() {

	try {
	    Email email = new Email();
	    email.setEmailId(100);
	    email.setPersonId(1000);
	    email.setEmailAddress("<EMAIL>");
	    MethodType type = MethodType.methodType(Integer.class);
	    MethodHandle handle = MethodHandles.publicLookup().findVirtual(
		    Email.class, "getPersonId", type);
	    Integer personId = (Integer) handle.invoke(email);
	    System.out.format("%s - %s", "personId", personId);
	} catch (NoSuchFieldException ex) {
	    ex.printStackTrace();
	} catch (IllegalAccessException ex) {
	    ex.printStackTrace();
	} catch (Throwable ex) {
	    ex.printStackTrace();
	}
    }
}<commit_msg>improved / commented code in utility classes<commit_after>package org.lightmare.utils.reflect;

import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.AccessibleObject;

import javax.persistence.EntityManager;

import org.junit.Assert;
import org.junit.Test;
import org.lightmare.bean.LightMareBean;
import org.lightmare.entities.Email;
import org.lightmare.utils.ObjectUtils;

public class MetaUtilsTest {

    protected EntityManager em;

    @Test
    public void testDefaultValues() {

	System.out.println(MetaUtils.getDefault(byte.class));
	System.out.println(MetaUtils.getDefault(boolean.class));
	System.out.println(MetaUtils.getDefault(char.class));
	System.out.println(MetaUtils.getDefault(short.class));
	System.out.println(MetaUtils.getDefault(int.class));
	System.out.println(MetaUtils.getDefault(long.class));
	System.out.println(MetaUtils.getDefault(float.class));
	System.out.println(MetaUtils.getDefault(double.class));
    }

    @Test
    public void testAccessibleObjectInstances() {

	try {
	    AccessibleObject acc1 = MetaUtils.getDeclaredField(
		    LightMareBean.class, "em");
	    AccessibleObject acc2 = MetaUtils.getDeclaredField(
		    LightMareBean.class, "em");

	    AccessibleObject acc3 = MetaUtils.getDeclaredField(
		    MetaUtilsTest.class, "em");

	    Assert.assertTrue("AccessibleObject instances are not the same",
		    acc1.equals(acc2));
	    System.out.format("%s %s", acc1, acc2);
	    Assert.assertTrue(
		    "AccessibleObject instances should not be the same",
		    ObjectUtils.notEquals(acc1, acc3));
	    System.out.format("%s %s", acc1, acc3);
	} catch (IOException ex) {
	    ex.printStackTrace();
	}
    }

    @Test
    public void getterFinderTest() {

	try {
	    Email email = new Email();
	    email.setEmailId(100);
	    email.setPersonId(1000);
	    email.setEmailAddress("<EMAIL>");
	    MethodType type = MethodType.methodType(Integer.class);
	    MethodHandle handle = MethodHandles.publicLookup().findVirtual(
		    Email.class, "getPersonId", type);
	    Integer personId = (Integer) handle.invoke(email);
	    System.out.format("%s - %s", "personId", personId);
	} catch (NoSuchFieldException ex) {
	    ex.printStackTrace();
	} catch (IllegalAccessException ex) {
	    ex.printStackTrace();
	} catch (Throwable ex) {
	    ex.printStackTrace();
	}
    }

    public void setterFinderTest() {

	try {
	    Email email = new Email();
	    email.setEmailId(100);
	    email.setPersonId(1000);
	    email.setEmailAddress("<EMAIL>");
	    MethodType setterType = MethodType.methodType(void.class,
		    Integer.class);
	    MethodHandle setterHandle = MethodHandles.publicLookup()
		    .findVirtual(Email.class, "setPersonId", setterType);
	    setterHandle.invoke(email, 1500);

	    MethodType getterType = MethodType.methodType(Integer.class);
	    MethodHandle getterHandle = MethodHandles.publicLookup()
		    .findVirtual(Email.class, "getPersonId", getterType);
	    Integer personId = (Integer) getterHandle.invoke(email);
	    System.out.format("%s - %s", "personId", personId);
	} catch (NoSuchFieldException ex) {
	    ex.printStackTrace();
	} catch (IllegalAccessException ex) {
	    ex.printStackTrace();
	} catch (Throwable ex) {
	    ex.printStackTrace();
	}
    }
}
{'fraction_non_alphanumeric': 0.12554262892863344, 'fraction_numerical': 0.008161139086646988, 'mean_word_length': 4.138269402319358, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '1216458', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1744, 'n_words': 321}