All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.hsac.fitnesse.slim.interaction.ReflectionHelper Maven / Gradle / Ivy

There is a newer version: 5.3.17
Show newest version
package nl.hsac.fitnesse.slim.interaction;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ReflectionHelper {
    private ReflectionHelper() {}

    public static Set validateMethodNames(Class clazz, String... names) {
        HashSet result = new HashSet(Arrays.asList(names));
        Method[] allMethods = clazz.getMethods();
        List methodsNotMentioned = new ArrayList(allMethods.length);
        for (Method method : allMethods) {
            methodsNotMentioned.add(method.getName());
        }
        List notFound = new ArrayList(0);
        for (String methodName : result) {
            if (!methodsNotMentioned.contains(methodName)) {
                notFound.add(methodName);
            } else {
                methodsNotMentioned.remove(methodName);
            }
        }
        if (!notFound.isEmpty()) {
            throw new RuntimeException("Unable to locate methods: " + notFound);
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy