From d93c8bf2b0ef0a1aeaddb38c5060fb5c0f2b6565 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Thu, 31 Jan 2013 15:56:53 +0000 Subject: [PATCH] refs #8 Further cleanup of logging. --- src/eva2/gui/BeanInspector.java | 1971 ++++++++++++------------- src/eva2/gui/GOEPanel.java | 3 +- src/eva2/gui/GenericObjectEditor.java | 4 +- src/eva2/gui/GraphWindow.java | 16 +- src/eva2/gui/JExtMenu.java | 157 +- src/eva2/server/ModuleServer.java | 30 +- src/eva2/tools/Serializer.java | 271 ++-- 7 files changed, 1194 insertions(+), 1258 deletions(-) diff --git a/src/eva2/gui/BeanInspector.java b/src/eva2/gui/BeanInspector.java index 4d0533fe..859c8336 100644 --- a/src/eva2/gui/BeanInspector.java +++ b/src/eva2/gui/BeanInspector.java @@ -1,5 +1,6 @@ package eva2.gui; +import eva2.client.EvAClient; import eva2.server.go.populations.Population; import eva2.server.go.strategies.GeneticAlgorithm; import eva2.tools.Pair; @@ -15,1054 +16,1014 @@ import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; - +import java.util.logging.Level; +import java.util.logging.Logger; /** - * Some miscellaneous functions to help with Beans, reflection, conversion and generic display. - * + * Some miscellaneous functions to help with Beans, reflection, conversion and + * generic display. + * * @author mkron, Holger Ulmer, Felix Streichert, Hannes Planatscher * */ public class BeanInspector { - public static boolean TRACE = false; + private static final Logger LOGGER = Logger.getLogger(BeanInspector.class.getName()); - /** - * Check for equality based on bean properties of two target objects. - */ - public static boolean equalProperties(Object obj_1, Object obj_2) { - if (obj_1 == null || obj_2 == null) { - System.out.println(""); - return false; - } - System.out.println("equalProperties: " + obj_1.getClass().getName() + " " + obj_2.getClass().getName()); - if (obj_1.getClass().getName().equals(obj_2.getClass().getName()) == false) { - System.out.println(""); - return false; - } - // compare each of the properties !! - BeanInfo Info_1 = null; - BeanInfo Info_2 = null; - PropertyDescriptor[] Properties_1 = null; - PropertyDescriptor[] Properties_2 = null; - try { + /** + * Check for equality based on bean properties of two target objects. + */ + public static boolean equalProperties(Object obj1, Object obj2) { + if (obj1 == null || obj2 == null) { + System.out.println(""); + return false; + } + System.out.println("equalProperties: " + obj1.getClass().getName() + " " + obj2.getClass().getName()); + if (obj1.getClass().getName().equals(obj2.getClass().getName()) == false) { + System.out.println(""); + return false; + } + // compare each of the properties !! + BeanInfo beanInfo1; + BeanInfo beanInfo2; + PropertyDescriptor[] Properties_1 = null; + PropertyDescriptor[] Properties_2 = null; + try { - Info_1 = Introspector.getBeanInfo(obj_1.getClass()); - Info_2 = Introspector.getBeanInfo(obj_2.getClass()); - Properties_1 = Info_1.getPropertyDescriptors(); - Properties_2 = Info_2.getPropertyDescriptors(); - Info_1.getMethodDescriptors(); - } catch (IntrospectionException ex) { - System.out.println("BeanTest: Couldn't introspect !!!!!!!!!"); - return false; - } - boolean BeansInside = false; - boolean BeansEqual = true; - for (int i = 0; i < Properties_1.length; i++) { - if (Properties_1[i].isHidden() || Properties_1[i].isExpert()) { - continue; - } - //String name = Properties_1[i].getDisplayName(); //System.out.println("name = "+name ); - //Class type = Properties_1[i].getPropertyType(); //System.out.println("type = "+type.getName() ); - Method getter_1 = Properties_1[i].getReadMethod(); - Method getter_2 = Properties_2[i].getReadMethod(); - Method setter_1 = Properties_1[i].getWriteMethod(); - // Only display read/write properties. - if (getter_1 == null || setter_1 == null) { - continue; - } - System.out.println("getter_1 = " + getter_1.getName() + " getter_2 = " + getter_2.getName()); - //System.out.println("type = "+type.getName() ); - Object args_1[] = {}; - Object args_2[] = {}; - //System.out.println("m_Target"+m_Target.toString()); - try { - Object value_1 = getter_1.invoke(obj_1, args_1); - Object value_2 = getter_2.invoke(obj_2, args_2); - BeansInside = true; - if (BeanInspector.equalProperties(value_1, value_2) == false) { - BeansEqual = false; - } - } catch (Exception e) { - System.out.println(" BeanTest.equalProperties " + e.getMessage()); - } - } - if (BeansInside == true) { - return BeansEqual; - } - // here we have Integer or Double ... - if (obj_1 instanceof Integer || - obj_1 instanceof Boolean || - obj_1 instanceof Float || - obj_1 instanceof Double || - obj_1 instanceof Long || - obj_1 instanceof String) { - return obj_1.equals(obj_2); - } - - System.err.println(" Attention no match !!!"); - return true; - } - - /** - * Produce a String representation of an arbitrary object. - * - * @see #toString(Object, char, boolean, String) - * @param obj - * @return - */ - public static String toString(Object obj) { - return toString(obj, ';', false, "", 1, false); - } - - /** - * Produce a string with newlines and indentation (easier readable for if an object has many properties). - * @param obj - * @return - */ - public static String niceToString(Object obj) { - return toString(obj, ';', false, " ", 1, true); - } - - /** - * Collect the accessible properties of an object and their values in a string with indentations. - * Special cases: Arrays and Lists are concatenations of their elements, Population is excepted from lists. - * If the object has its own toString method, this one is preferred. Hidden or expert properties are not - * shown. - * - * @param obj an arbitrary object - * @return a String description of the object - */ - public static String toString(Object obj, char delim, boolean tight, String indentStr) { - return toString(obj, delim, tight, indentStr, 1, false); - } - - /** - * Collect the accessible properties of an object and their values in a string. - * Special cases: Arrays and Lists are concatenations of their elements, Population is excepted from lists. - * If the object has its own toString method, this one is preferred. Hidden or expert properties are not - * shown. - * - * @param obj Description of the Parameter - * @return Description of the Return Value - */ - private static String toString(Object obj, char delim, boolean tight, String indentStr, int indentDepth, boolean withNewlines) { - if (obj == null) { - return "null"; + beanInfo1 = Introspector.getBeanInfo(obj1.getClass()); + beanInfo2 = Introspector.getBeanInfo(obj2.getClass()); + Properties_1 = beanInfo1.getPropertyDescriptors(); + Properties_2 = beanInfo2.getPropertyDescriptors(); + beanInfo1.getMethodDescriptors(); + } catch (IntrospectionException ex) { + LOGGER.log(Level.FINEST, "Could not introspect object.", ex); + return false; + } + boolean BeansInside = false; + boolean BeansEqual = true; + for (int i = 0; i < Properties_1.length; i++) { + if (Properties_1[i].isHidden() || Properties_1[i].isExpert()) { + continue; } - // try the object itself - if (obj instanceof String) { - return (String)obj; - } // directly return a string object - Class type = obj.getClass(); + //String name = Properties_1[i].getDisplayName(); //System.out.println("name = "+name ); + //Class type = Properties_1[i].getPropertyType(); //System.out.println("type = "+type.getName() ); + Method getter_1 = Properties_1[i].getReadMethod(); + Method getter_2 = Properties_2[i].getReadMethod(); + Method setter_1 = Properties_1[i].getWriteMethod(); + // Only display read/write properties. + if (getter_1 == null || setter_1 == null) { + continue; + } + System.out.println("getter_1 = " + getter_1.getName() + " getter_2 = " + getter_2.getName()); + //System.out.println("type = "+type.getName() ); + Object args_1[] = {}; + Object args_2[] = {}; + //System.out.println("m_Target"+m_Target.toString()); + try { + Object value_1 = getter_1.invoke(obj1, args_1); + Object value_2 = getter_2.invoke(obj2, args_2); + BeansInside = true; + if (BeanInspector.equalProperties(value_1, value_2) == false) { + BeansEqual = false; + } + } catch (Exception e) { + System.out.println(" BeanTest.equalProperties " + e.getMessage()); + } + } + if (BeansInside == true) { + return BeansEqual; + } + // here we have Integer or Double ... + if (obj1 instanceof Integer + || obj1 instanceof Boolean + || obj1 instanceof Float + || obj1 instanceof Double + || obj1 instanceof Long + || obj1 instanceof String) { + return obj1.equals(obj2); + } - if (type.isArray()) { // handle the array case - StringBuffer sbuf = new StringBuffer(); - sbuf.append("["); - if (!tight) { - sbuf.append(" "); - } - int len = Array.getLength(obj); - for (int i=0; i