package tester;

import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;



public final class AuDoscoreUtils {

	private static interface Matcher<T> {
		boolean match(T elem);
	}



	private AuDoscoreUtils() { }



	/**
	 * Returns an array of fields explicitly declared in the specified class.
	 *
	 * @param theClass the class
	 * @return array of declared fields
	 */
	public static Field[] getExplicitlyDeclaredFields(final Class<?> theClass) {
		return getMatching(theClass.getDeclaredFields(), new Matcher<Field>() {
			@Override
			public boolean match(final Field elem) {
				return !elem.isSynthetic();
			}
		});
	}



	/**
	 * Returns an array of methods explicitly declared in the specified class.
	 *
	 * @param theClass the class
	 * @return array of declared methods
	 */
	public static Method[] getExplicitlyDeclaredMethods(final Class<?> theClass) {
		return getMatching(theClass.getDeclaredMethods(), new Matcher<Method>() {
			@Override
			public boolean match(final Method elem) {
				return !elem.isBridge() && !elem.isSynthetic();
			}
		});
	}



	private static <T> T[] getMatching(final T[] array, final Matcher<T> matcher) {
		if (array == null) {
			return null;
		}

		final List<T> resultList = getMatching(Arrays.asList(array), matcher);
		if (resultList.isEmpty() && array.length == 0) {
			return array;
		}
		return resultList.toArray(
				(T[]) Array.newInstance(array[0].getClass(), resultList.size()));
	}



	private static <T> List<T> getMatching(final List<T> list, final Matcher<T> matcher) {
		if (list == null) {
			return null;
		}

		final List<T> result = new ArrayList<>(list.size());
		for (final T elem : list) {
			if (elem != null && matcher.match(elem)) {
				result.add(elem);
			}
		}
		return result;
	}
}


@@ -223,16 +223,38 @@
 tils %7B%0A%0A
+%09@FunctionalInterface%0A
 %09private
@@ -284,16 +284,16 @@
 er%3CT%3E %7B%0A
-
 %09%09boolea
@@ -637,98 +637,15 @@
 (), 
-new Matcher%3CField%3E() %7B%0A%09%09%09@Override%0A%09%09%09public boolean match(final Field elem) %7B%0A%09%09%09%09return
+elem -%3E
  !el
@@ -656,34 +656,24 @@
 sSynthetic()
-;%0A%09%09%09%7D%0A%09%09%7D
 );%0A%09%7D%0A%0A%0A%0A%09/*
@@ -962,101 +962,20 @@
 s(),
- new Matcher%3CMethod%3E() %7B%0A%09%09%09@Override%0A%09%09%09public boolean match(final Method elem) %7B%0A%09%09%09%09return
+%0A%09%09%09%09elem -%3E
  !el
@@ -1010,26 +1010,16 @@
 thetic()
-;%0A%09%09%09%7D%0A%09%09%7D
 );%0A%09%7D%0A%0A%0A

Use lambda functions instead of anonymous classes