Cooler error message for GradientDescentAlgorithm.
This commit is contained in:
		@@ -117,47 +117,36 @@ public class GenericObjectEditor implements PropertyEditor {
 | 
			
		||||
	 */
 | 
			
		||||
	public static ArrayList<String> getClassesFromClassPath(String className) { 
 | 
			
		||||
		ArrayList<String> classes = new ArrayList<String>();
 | 
			
		||||
		int dotIndex = className.lastIndexOf('.');
 | 
			
		||||
		if (dotIndex <= 0) {
 | 
			
		||||
			System.err.println("warning: " + className + " is not a package!");
 | 
			
		||||
		} else {		
 | 
			
		||||
			String pckg = className.substring(0, className.lastIndexOf('.'));
 | 
			
		||||
			Class<?>[] clsArr; 
 | 
			
		||||
			try {
 | 
			
		||||
				clsArr = ReflectPackage.getAssignableClassesInPackage(pckg, Class.forName(className), true, true);
 | 
			
		||||
			} catch (ClassNotFoundException e) {
 | 
			
		||||
				e.printStackTrace();
 | 
			
		||||
				clsArr = null;
 | 
			
		||||
			}
 | 
			
		||||
			if (clsArr == null) {
 | 
			
		||||
				System.err.println("Warning: No configuration property found in: "
 | 
			
		||||
						+EvAInfo.propertyFile + " "+"for "+className);
 | 
			
		||||
				classes.add(className);
 | 
			
		||||
			} else {
 | 
			
		||||
				for (Class<?> class1 : clsArr) {
 | 
			
		||||
					int m = class1.getModifiers();
 | 
			
		||||
					try {
 | 
			
		||||
						// a field allowing a class to indicate it doesnt want to be displayed
 | 
			
		||||
						Field f = class1.getDeclaredField("hideFromGOE");
 | 
			
		||||
						if (f.getBoolean(class1) == true) {
 | 
			
		||||
							if (TRACE) System.out.println("Class " + class1 + " wants to be hidden from GOE, skipping...");
 | 
			
		||||
							continue;
 | 
			
		||||
						}
 | 
			
		||||
					} catch (Exception e) {
 | 
			
		||||
						
 | 
			
		||||
					} catch (Error e) {
 | 
			
		||||
						System.err.println("Error on checking fields of " + class1 + ": " + e);
 | 
			
		||||
		Class<?>[] clsArr;
 | 
			
		||||
		clsArr=ReflectPackage.getAssignableClasses(className, true, true);
 | 
			
		||||
		if (clsArr == null) {
 | 
			
		||||
			System.err.println("Warning: No assignable classes found in property file or on classpath: "
 | 
			
		||||
					+EvAInfo.propertyFile + " for "+className);
 | 
			
		||||
			classes.add(className);
 | 
			
		||||
		} else {
 | 
			
		||||
			for (Class<?> class1 : clsArr) {
 | 
			
		||||
				int m = class1.getModifiers();
 | 
			
		||||
				try {
 | 
			
		||||
					// a field allowing a class to indicate it doesnt want to be displayed
 | 
			
		||||
					Field f = class1.getDeclaredField("hideFromGOE");
 | 
			
		||||
					if (f.getBoolean(class1) == true) {
 | 
			
		||||
						if (TRACE) System.out.println("Class " + class1 + " wants to be hidden from GOE, skipping...");
 | 
			
		||||
						continue;
 | 
			
		||||
					}
 | 
			
		||||
//					if (f)
 | 
			
		||||
					if (!Modifier.isAbstract(m) && !class1.isInterface()) {	// dont take abstract classes or interfaces
 | 
			
		||||
						try {
 | 
			
		||||
							Class<?>[] params = new Class[0];
 | 
			
		||||
							class1.getConstructor(params);
 | 
			
		||||
							classes.add(class1.getName());
 | 
			
		||||
						} catch (NoSuchMethodException e) {
 | 
			
		||||
							System.err.println("GOE warning: Class " + class1.getName() + " has no default constructor, skipping...");
 | 
			
		||||
						}
 | 
			
		||||
				} catch (Exception e) {
 | 
			
		||||
 | 
			
		||||
				} catch (Error e) {
 | 
			
		||||
					System.err.println("Error on checking fields of " + class1 + ": " + e);
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
				//					if (f)
 | 
			
		||||
				if (!Modifier.isAbstract(m) && !class1.isInterface()) {	// dont take abstract classes or interfaces
 | 
			
		||||
					try {
 | 
			
		||||
						Class<?>[] params = new Class[0];
 | 
			
		||||
						class1.getConstructor(params);
 | 
			
		||||
						classes.add(class1.getName());
 | 
			
		||||
					} catch (NoSuchMethodException e) {
 | 
			
		||||
						System.err.println("GOE warning: Class " + class1.getName() + " has no default constructor, skipping...");
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@ import eva2.server.go.problems.F1Problem;
 | 
			
		||||
import eva2.server.go.problems.InterfaceFirstOrderDerivableProblem;
 | 
			
		||||
import eva2.server.go.problems.InterfaceOptimizationProblem;
 | 
			
		||||
import eva2.tools.EVAERROR;
 | 
			
		||||
import eva2.tools.ReflectPackage;
 | 
			
		||||
 | 
			
		||||
/** 
 | 
			
		||||
 * A gradient descent algorithm by hannes planatscher don't expect any
 | 
			
		||||
@@ -195,6 +196,12 @@ public class GradientDescentAlgorithm implements InterfaceOptimizer, java.io.Ser
 | 
			
		||||
      else {
 | 
			
		||||
    	  String msg="Warning, problem of type InterfaceFirstOrderDerivableProblem and template of type InterfaceDataTypeDouble is required for " + this.getClass();
 | 
			
		||||
    	  EVAERROR.errorMsgOnce(msg);
 | 
			
		||||
    	  Class<?>[] clsArr = ReflectPackage.getAssignableClasses("eva2.server.go.problems.InterfaceFirstOrderDerivableProblem", true, true);
 | 
			
		||||
    	  msg=msg+" (available: ";
 | 
			
		||||
    	  for (Class<?> cls: clsArr) {
 | 
			
		||||
    		  msg=msg+" "+cls.getSimpleName();
 | 
			
		||||
    	  }
 | 
			
		||||
    	  msg=msg+")";
 | 
			
		||||
    	  throw new RuntimeException(msg);
 | 
			
		||||
      }
 | 
			
		||||
    } // for loop population size
 | 
			
		||||
 
 | 
			
		||||
@@ -365,17 +365,43 @@ public class ReflectPackage {
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Retrieve assignable classes of the given package from classpath.
 | 
			
		||||
	 * Retrieve assignable classes of the given package from classpath given by package name and Class instance.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param pckg	String denoting the package
 | 
			
		||||
	 * @param reqSuperCls
 | 
			
		||||
	 * @return
 | 
			
		||||
	 */
 | 
			
		||||
	public static Class[] getAssignableClassesInPackage(String pckg, Class reqSuperCls, boolean includeSubs, boolean bSort) {
 | 
			
		||||
	public static Class<?>[] getAssignableClassesInPackage(String pckg, Class reqSuperCls, boolean includeSubs, boolean bSort) {
 | 
			
		||||
		if (TRACE) System.out.println("requesting classes assignable from " + reqSuperCls.getName());
 | 
			
		||||
		return getClassesInPackageFltr(new HashSet<Class>(), pckg, includeSubs, bSort, reqSuperCls);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * Retrieve assignable classes of the given package from classpath given by full class and package String,
 | 
			
		||||
	 * such as eva2.server.go.problems.AbstractOptimizationProblem.
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param pckg	String denoting the package
 | 
			
		||||
	 * @param reqSuperCls
 | 
			
		||||
	 * @return
 | 
			
		||||
	 */
 | 
			
		||||
	public static Class<?>[] getAssignableClasses(String pckgClassName, boolean includeSubs, boolean bSort) {
 | 
			
		||||
		int dotIndex = pckgClassName.lastIndexOf('.');
 | 
			
		||||
		if (dotIndex <= 0) {
 | 
			
		||||
			System.err.println("warning: " + pckgClassName + " is not a package!");
 | 
			
		||||
			return null;
 | 
			
		||||
		} else {		
 | 
			
		||||
			String pckg = pckgClassName.substring(0, pckgClassName.lastIndexOf('.'));
 | 
			
		||||
			Class<?>[] clsArr; 
 | 
			
		||||
			try {
 | 
			
		||||
				clsArr = ReflectPackage.getAssignableClassesInPackage(pckg, Class.forName(pckgClassName), includeSubs, bSort);
 | 
			
		||||
			} catch (ClassNotFoundException e) {
 | 
			
		||||
				e.printStackTrace();
 | 
			
		||||
				clsArr = null;
 | 
			
		||||
			}
 | 
			
		||||
			return clsArr;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public static void main(String[] args) {
 | 
			
		||||
		ClassLoader cld =  Thread.currentThread().getContextClassLoader();
 | 
			
		||||
		System.out.println("1: " + cld.getResource("/eva2/server"));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user