From 17061b147514d2feb3f62cb8ab1b55df254599a3 Mon Sep 17 00:00:00 2001 From: Fabian Becker Date: Mon, 23 Apr 2012 13:36:56 +0000 Subject: [PATCH] Removed unused class LogProxy Refactored tools package and removed debugging statements / replaced them with proper calls to the logger. --- src/eva2/client/EvAComAdapter.java | 8 +- src/eva2/server/ModuleServer.java | 122 ++++++++-------- src/eva2/tools/LogProxy.java | 102 ------------- src/eva2/tools/jproxy/ComAdapter.java | 202 ++++++++++---------------- src/eva2/tools/math/Mathematics.java | 88 +++++------ 5 files changed, 165 insertions(+), 357 deletions(-) delete mode 100644 src/eva2/tools/LogProxy.java diff --git a/src/eva2/client/EvAComAdapter.java b/src/eva2/client/EvAComAdapter.java index ff3dbdf8..628d2f46 100644 --- a/src/eva2/client/EvAComAdapter.java +++ b/src/eva2/client/EvAComAdapter.java @@ -87,7 +87,6 @@ public class EvAComAdapter extends ComAdapter { */ public String[] getModuleNameList() { String[] list; - if (TRACE) System.out.println("ComAdapter.GetModuleNameList()"); if ((m_RMIServer == null) && isRunLocally()) { list = getLocalMainAdapter().getModuleNameList(); @@ -117,12 +116,7 @@ public class EvAComAdapter extends ComAdapter { } return (MainAdapter) invocHandler.getWrapper(); } - - protected void logInfo(String msg) { - if (m_LogPanel != null) { - m_LogPanel.logMessage(msg); - } else super.logInfo(msg); - } + protected RMIConnection createRMIConnection(String Host, MainAdapter mainRemoteObject, MainAdapterClient client) { return new RMIConnectionEvA(Host, mainRemoteObject, client); diff --git a/src/eva2/server/ModuleServer.java b/src/eva2/server/ModuleServer.java index d0e8a955..30ad9017 100644 --- a/src/eva2/server/ModuleServer.java +++ b/src/eva2/server/ModuleServer.java @@ -19,31 +19,31 @@ import eva2.tools.jproxy.MainAdapterClient; import eva2.tools.jproxy.RMIProxyLocal; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.util.List; import java.util.ArrayList; import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Collect available ModuleAdapter implementations and load them on request. */ public class ModuleServer { - public static boolean TRACE = false; + private static final Logger logger = Logger.getLogger(eva2.EvAInfo.defaultLogger); private int m_InstanceCounter = 0; - private ArrayList> m_ModuleClassList; + private List> moduleClassList; // private ArrayList m_RunnungModules; - private ModuleAdapter m_ModuleAdapter; - private int m_ModuleAdapterCounter = 0; + private ModuleAdapter moduleAdapter; + private int moduleAdapterCounter = 0; /** * */ public ModuleServer(Properties EvAProps) { - if (TRACE) - System.out.println("Constructor ModuleServer():"); if (m_InstanceCounter > 0) { - EVAERROR.EXIT("ModuleServer twice created"); + EVAERROR.EXIT("ModuleServer created twice"); } -// m_RunnungModules = new ArrayList(); - m_ModuleClassList = new ArrayList>(); + moduleClassList = new ArrayList>(); String modulePckg = null; Class filterBy = null; @@ -60,8 +60,7 @@ public class ModuleServer { // this gets a list of all valid modules from the package Class[] classes = ReflectPackage.getAssignableClassesInPackage(modulePckg, filterBy, true, true); for (Object cls : classes) { - if (TRACE) System.out.println("- " + ((Class)cls).getName()); - m_ModuleClassList.add((Class)cls); + moduleClassList.add((Class) cls); } m_InstanceCounter++; @@ -71,16 +70,16 @@ public class ModuleServer { * */ public String[] getModuleNameList() { - ArrayList ModuleNameList = new ArrayList(); - for (int i = 0; i < m_ModuleClassList.size(); i++) { + List moduleNameList = new ArrayList(); + for (int i = 0; i < moduleClassList.size(); i++) { try { - Class Modul = (Class) m_ModuleClassList.get(i); + Class Modul = (Class) moduleClassList.get(i); Method[] methods = Modul.getDeclaredMethods(); for (int ii = 0; ii < methods.length; ii++) { if (methods[ii].getName().equals("getName") == true) { //System.out.println("name is =="+methods[ii].invoke(null,null)); String name = (String)methods[ii].invoke((Object[])null, (Object[])null); - if (name != null) ModuleNameList.add(name); + if (name != null) moduleNameList.add(name); break; } } @@ -105,8 +104,8 @@ public class ModuleServer { // ModuleNameList.add(AdapterName); // } - String[] x = new String[ModuleNameList.size()]; - ModuleNameList.toArray(x); + String[] x = new String[moduleNameList.size()]; + moduleNameList.toArray(x); return x; } @@ -120,47 +119,40 @@ public class ModuleServer { public ModuleAdapter createModuleAdapter(String selectedModuleName, MainAdapterClient Client, boolean runWithoutRMI, String hostAddress, InterfaceGOParameters goParams, String noGuiLogFile) { - m_ModuleAdapterCounter++; - String adapterName = new String("ERROR MODULADAPTER !!"); - if (TRACE) { - System.out.println("ModuleServer.CreateModuleAdapter()"); - System.out.println(" ModuleServer.CreateModuleAdapter for:" + - selectedModuleName); - System.out.println(" m_ModulAdapterCounter =" + m_ModuleAdapterCounter); - System.out.println(" Start of EvA RMI-ModulAdapter for Module: " + - selectedModuleName); - } - String moduleName; + moduleAdapterCounter++; + String adapterName = "ERROR MODULADAPTER !!"; + String moduleName = null; Class module; Method[] methods; - for (int i = 0; i < m_ModuleClassList.size(); i++) { - moduleName = null; - module = m_ModuleClassList.get(i); - + for (int i = 0; i < moduleClassList.size(); i++) { + module = moduleClassList.get(i); try { methods = module.getDeclaredMethods(); for (int ii = 0; ii < methods.length; ii++) { - if (methods[ii].getName().equals("getName") == true) - moduleName = (String) methods[ii].invoke((Object[])null, (Object[])null); + if (methods[ii].getName().equals("getName") == true) { + moduleName = (String) methods[ii].invoke((Object[]) null, (Object[]) null); + } } } - catch (Exception e) { - System.err.println("ModuleServer.createModuleAdapter() " + e.getMessage()); - e.printStackTrace(); + catch (Exception ex) { + logger.log(Level.WARNING, ex.getMessage(), ex); } if ((moduleName != null) && (selectedModuleName.equals(moduleName))) { - if (TRACE) System.out.println("ModuleName: " + moduleName); try { - adapterName = new String(m_ModuleAdapterCounter + "_Running_" + - selectedModuleName); + adapterName = moduleAdapterCounter + "_Running_" + selectedModuleName; Constructor[] constructorArr = module.getConstructors(); - // create a module instance - int constrIndex=0; + /* create a module instance */ + int constrIndex = 0; + if ((goParams==null && noGuiLogFile==null) || !module.equals(GOModuleAdapter.class)) { - if (goParams!=null) System.err.println("Cant set params - no matching constructor found for " + adapterName + " (ModuleServer)"); - if (noGuiLogFile!=null) System.err.println("Cant deactivate GUI - no matching constructor found for " + adapterName + " (ModuleServer)"); + if (goParams != null) { + System.err.println("Cant set params - no matching constructor found for " + adapterName + " (ModuleServer)"); + } + if (noGuiLogFile != null) { + System.err.println("Cant deactivate GUI - no matching constructor found for " + adapterName + " (ModuleServer)"); + } Object[] Para = new Object[2]; while ((constructorArr[constrIndex].getParameterTypes().length!=2) && (constrIndex < constructorArr.length)) { constrIndex++; @@ -168,35 +160,35 @@ public class ModuleServer { Class paramTypes[] = (constructorArr[constrIndex]).getParameterTypes(); Para[0] = paramTypes[0].cast(adapterName); Para[1] = paramTypes[1].cast(Client); - m_ModuleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(Para); + moduleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(Para); } else { - Object[] Para = new Object[4]; - Para[0] = (String)adapterName; - Para[1] = (InterfaceGOParameters)goParams; - Para[2] = (String)noGuiLogFile; - Para[3] = (MainAdapterClient)Client; + Object[] param = new Object[4]; + param[0] = (String)adapterName; + param[1] = (InterfaceGOParameters)goParams; + param[2] = (String)noGuiLogFile; + param[3] = (MainAdapterClient)Client; while ((constructorArr[constrIndex].getParameterTypes().length!=4) && (constrIndex < constructorArr.length)) { constrIndex++; } - m_ModuleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(Para); + moduleAdapter = (ModuleAdapter) constructorArr[constrIndex].newInstance(param); } - if (!runWithoutRMI) { // if we're using RMI, send the object to a remote server -// for this to work the class of m_ModuleAdapter itself must implement the ModuleAdapter interface -// for a strange reason, it is _not_ enough if a superclass implements the same interface! - m_ModuleAdapter = (ModuleAdapter)RMIProxyLocal.newInstance(m_ModuleAdapter, adapterName); - (m_ModuleAdapter).setRemoteThis(m_ModuleAdapter); + if (!runWithoutRMI) { + /* if we're using RMI, send the object to a remote server + * for this to work the class of moduleAdapter itself must + * implement the ModuleAdapter interface for a strange reason, + * it is _not_ enough if a superclass implements the same interface! + */ + moduleAdapter = (ModuleAdapter)RMIProxyLocal.newInstance(moduleAdapter, adapterName); + (moduleAdapter).setRemoteThis(moduleAdapter); } // m_RunnungModules.add(m_ModuleAdapter); } - catch (Exception e) { - System.err.println("CLASSPATH " + - System.getProperty("java.class.path")); - e.printStackTrace(); - EVAERROR.EXIT("Error in RMI-Moduladapter initialization: " + e.getMessage()); + catch (Exception ex) { + logger.log(Level.SEVERE, "Error in RMI-Moduladapter initialization", ex); + EVAERROR.EXIT("Error in RMI-Moduladapter initialization: " + ex.getMessage()); return null; - } - if (TRACE) System.out.println("End of RMI-Moduladapter initialization !"); - return (ModuleAdapter) m_ModuleAdapter; + } + return (ModuleAdapter) moduleAdapter; } } // // @todo running modules sind gerade noch abgeschaltet @@ -215,7 +207,7 @@ public class ModuleServer { // } // } - System.err.println("NO VALID MODULE DEFINED: " + selectedModuleName); + logger.log(Level.SEVERE, "No valid module defined: {0}", selectedModuleName); return null; } } \ No newline at end of file diff --git a/src/eva2/tools/LogProxy.java b/src/eva2/tools/LogProxy.java deleted file mode 100644 index 4518ffd1..00000000 --- a/src/eva2/tools/LogProxy.java +++ /dev/null @@ -1,102 +0,0 @@ -package eva2.tools; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - - -/*==========================================================================* - * CLASS DECLARATION - *==========================================================================*/ - -/** - * - */ -public class LogProxy implements InvocationHandler -{ - //~ Static fields/initializers ///////////////////////////////////////////// - - public static final boolean TRACE = false; - - //~ Instance fields //////////////////////////////////////////////////////// - - private Object m_Object; - private String m_ObjectName; - private double m_timeges = 0; - private long m_counter = 0; - private long m_timestart = 0; - - //~ Constructors /////////////////////////////////////////////////////////// - - /** - * - */ - public LogProxy(Object obj) - { - m_Object = obj; - m_ObjectName = obj.getClass().getName(); - m_timestart = System.currentTimeMillis(); - } - - //~ Methods //////////////////////////////////////////////////////////////// - - /** - * - */ - public static Object newInstance(Object obj) - { - return Proxy.newProxyInstance(obj.getClass().getClassLoader(), - obj.getClass().getInterfaces(), new LogProxy(obj)); - } - - /** - * - */ - public Object invoke(Object proxy, Method m, Object[] args) - throws Throwable - { - long start = System.currentTimeMillis(); - ++m_counter; - - Object ret = null; - - try - { - //if (TRACE)System.out.println("Before invoke:" +m.getName()); - long t = System.currentTimeMillis(); - ret = m.invoke(m_Object, args); - - long t2 = System.currentTimeMillis(); - t = t2 - t; - m_timeges = m_timeges + t; - - double x = m_timeges / ((double) (t2 - m_timestart)); - System.out.println("x=" + x + "timeges" + m_timeges); - } - catch (InvocationTargetException e) - { - System.out.println("LogProxy: InvocationTargetException" + - e.getMessage()); - } - catch (Exception e) - { - System.out.println("Exception" + e.getMessage()); - } - finally - { - //long finish = System.currentTimeMillis(); - - //System.out.println("Calling :"+m.getName()+" of "+m_ObjectName+ " time :"+(finish-start)); - } - if (ret == m_Object) - { - return this; - } - - return ret; - - } - -} - diff --git a/src/eva2/tools/jproxy/ComAdapter.java b/src/eva2/tools/jproxy/ComAdapter.java index 94d47d54..f6e6b981 100644 --- a/src/eva2/tools/jproxy/ComAdapter.java +++ b/src/eva2/tools/jproxy/ComAdapter.java @@ -22,24 +22,27 @@ import java.util.Properties; import java.util.StringTokenizer; import eva2.tools.Serializer; +import java.security.AccessControlException; +import java.util.logging.Level; +import java.util.logging.Logger; /** * */ public class ComAdapter { - static final public boolean TRACE = false; - static final public int PORT = 1099; - static final public String SEP = "_"; + private static final Logger logger = Logger.getLogger(eva2.EvAInfo.defaultLogger); + public static final int PORT = 1099; + public static final String SEP = "_"; static protected ComAdapter m_instance = null; public Registry m_Registry = null; private ArrayList m_Connections = new ArrayList(); - private String m_ownHostName; + private String hostName; private ArrayList m_HostNameList = new ArrayList(); private ArrayList m_AvailableHostNameList = new ArrayList(); // private String m_RemoteAdapterName; - private String m_UserName; + private String userName; private int m_ownHostIndex = 0; protected RMIServer m_RMIServer; private String serverListSeparator = ","; @@ -59,12 +62,22 @@ public class ComAdapter { * */ protected ComAdapter() { - if (TRACE) System.out.println("constructor ComAdapter"); - m_UserName = System.getProperty("user.name"); - - m_ownHostName = "localhost"; //"192.168.0.1"; + try { + userName = System.getProperty("user.name"); + } catch(SecurityException ex) { + /* This exception is expected to happen when + * we are using Java WebStart. + */ + logger.log(Level.INFO, "Username set to: WebStart", ex); + userName = "Webstart"; + } + hostName = "localhost"; //"192.168.0.1"; - System.setProperty("java.security.policy", "server.policy"); + try { + System.setProperty("java.security.policy", "server.policy"); + } catch(AccessControlException ex) { + // ToDo: This happens using webstart - what to do now? + } launchRMIRegistry(false); if (!m_HostNameList.contains("localhost")) { // make sure localhost is in the list @@ -85,10 +98,9 @@ public class ComAdapter { while (st.hasMoreTokens()) { String current = st.nextToken().trim(); if (!m_HostNameList.contains(current)) { - if (TRACE) System.out.println("adding server " + current); m_HostNameList.add(current); } else { - if (TRACE) System.out.println("server " + current + " was already in list"); + logger.log(Level.FINER, "Server " + current + " was already in list"); } } } @@ -107,7 +119,7 @@ public class ComAdapter { /** * Set the separator for the server list string. * - * @return + * @param sep List separator */ public void setServerListSeparator(String sep) { serverListSeparator = sep; @@ -116,7 +128,7 @@ public class ComAdapter { /** * The separator for the server list string. * - * @return + * @return The list separator */ public String getServerListSeparator() { return serverListSeparator; @@ -124,9 +136,7 @@ public class ComAdapter { /** * - * @param c - * @param host - * @return + * @param server An array of servers */ public void setServerList(String[] server){ m_HostNameList.clear(); @@ -140,10 +150,10 @@ public class ComAdapter { */ public RMIInvocationHandler getRMIHandler(Object c, String host) { System.out.println("ComAdapter.getRMIHandler() for host " + host); - m_ownHostName = host; + hostName = host; RMIInvocationHandler ret = null; while (ret == null) { - ret = getConnection(m_ownHostName).getRMIHandler(c); + ret = getConnection(hostName).getRMIHandler(c); if (ret == null) System.out.println("Error in getRMIHandler"); } @@ -155,16 +165,15 @@ public class ComAdapter { * */ public RMIThreadInvocationHandler getRMIThreadHandler(Object c, String host) { - if (TRACE) - System.out.println("ComAdapter.getRMIThreadHandler()"); int cnt=0; - m_ownHostName = host; + hostName = host; RMIThreadInvocationHandler ret = null; while (cnt<100) { //ret == null) { cnt++; - ret = getConnection(m_ownHostName).getRMIThreadHandler(c); - if (ret == null) - System.err.println("Error in getRMIThreadHandler"); + ret = getConnection(hostName).getRMIThreadHandler(c); + if (ret == null) { + logger.log(Level.WARNING, "Error in getRMIThreadHandler"); + } } return ret; } @@ -174,18 +183,17 @@ public class ComAdapter { * */ public RMIThreadInvocationHandler getRMIThreadHandler(Object c) { - if (TRACE) - System.out.println("RMIThreadInvokationHandler getRMIThreadHandler"); RMIThreadInvocationHandler ret = null; if (m_AvailableHostNameList.size() == 0) { evalAvailableHostNameList(); m_ownHostIndex = 0; } m_ownHostIndex++; - if (m_ownHostIndex >= m_AvailableHostNameList.size()) + if (m_ownHostIndex >= m_AvailableHostNameList.size()) { m_ownHostIndex = 0; - m_ownHostName = (String) m_AvailableHostNameList.get(m_ownHostIndex); - ret = getRMIThreadHandler(c, m_ownHostName); + } + hostName = (String) m_AvailableHostNameList.get(m_ownHostIndex); + ret = getRMIThreadHandler(c, hostName); return ret; } @@ -194,20 +202,20 @@ public class ComAdapter { * */ public RMIInvocationHandler getRMIHandler(Object c) { - if (TRACE) - System.out.println("RMIThreadInvokationHandler getRMIHandler"); RMIInvocationHandler ret = null; while (m_AvailableHostNameList.size() == 0) { evalAvailableHostNameList(); - if (m_AvailableHostNameList.size() == 0) - System.err.println("no host availabe waiting !!"); + if (m_AvailableHostNameList.size() == 0) { + logger.log(Level.WARNING, "No host availabe waiting.."); + } m_ownHostIndex = 0; } m_ownHostIndex++; - if (m_ownHostIndex >= m_AvailableHostNameList.size()) + if (m_ownHostIndex >= m_AvailableHostNameList.size()) { m_ownHostIndex = 0; - m_ownHostName = (String) m_AvailableHostNameList.get(m_ownHostIndex); - ret = getRMIHandler(c, m_ownHostName); + } + hostName = (String) m_AvailableHostNameList.get(m_ownHostIndex); + ret = getRMIHandler(c, hostName); return ret; } @@ -251,22 +259,20 @@ public class ComAdapter { */ public void evalAvailableHostNameList() { long time = System.currentTimeMillis(); - if (TRACE) - System.out.println("ComAdapter.getAvailableHostNameList()"); m_AvailableHostNameList.clear(); for (int i = 0; i < m_HostNameList.size(); i++) { - if (rmiPing((String) m_HostNameList.get(i)) == true) + if (rmiPing((String) m_HostNameList.get(i)) == true) { m_AvailableHostNameList.add((String) m_HostNameList.get(i)); + } String testurl = (String) m_HostNameList.get(i); for (int j = 1; j < 3; j++) { if (rmiPing(testurl + "_" + j) == true) { - if (TRACE) System.out.println("found EvAServer on: " + testurl); + logger.log(Level.INFO, "Found EvAServer on: " + testurl); m_AvailableHostNameList.add(testurl + "_" + j); } } } - time = System.currentTimeMillis() - time; - if (TRACE) System.out.println("getAvailableHostNameList: " + m_AvailableHostNameList.size() + " found time " + time); + time = System.currentTimeMillis() - time; } @@ -294,15 +300,15 @@ public class ComAdapter { * */ public String getHostName() { - return m_ownHostName; + return hostName; } /** * */ public void setHostName(String newHost) { - m_ownHostName = newHost; - Serializer.storeString("hostname.ser", m_ownHostName); + hostName = newHost; + Serializer.storeString("hostname.ser", hostName); } @@ -311,8 +317,6 @@ public class ComAdapter { * @return */ protected MainAdapter createRMIMainConnect(String HostToConnect) { - if (TRACE) - System.out.println("RMIMainConnect.RMIMainConnect() =" + HostToConnect); int len = HostToConnect.indexOf(SEP); String Host = HostToConnect; String Number = SEP + "0"; @@ -321,48 +325,24 @@ public class ComAdapter { Host = st.nextToken().trim(); Number = SEP + st.nextToken().trim(); } - String MainAdapterName = m_UserName + MainAdapterImpl.MAIN_ADAPTER_NAME + Number; // attention + String MainAdapterName = userName + MainAdapterImpl.MAIN_ADAPTER_NAME + Number; // attention - logInfo(" RMIConnect to " + HostToConnect); + logger.info("RMIConnect to " + HostToConnect); MainAdapter MainRemoteObject = null; try { - try { - try { - //System.out.println("--> ComAdapter: "+"rmi://"+Host+":"+MainAdapterImpl.PORT+"/"+MainAdapterName); -// String[] list = Naming.list("rmi://" + Host + ":" + -// MainAdapterImpl.PORT); - //for (int i=0;i max) { - return max; - } else - return v; + value = max; + } else { + value = v; + } + return value; } /** - * Create a random vector, the components will be set to gaussian + * Create a random vector, the components will be set to Gaussian * distributed values with mean zero and the given standard deviation. - * - * @param dim - * the desired dimension - * @param stdDev - * the gaussian standard deviation + * + * @param dim The desired dimension + * @param stdDev The Gaussian standard deviation * @return random vector */ - public static double[] randomVector(int dim, double stdDev) { + public static double[] randomVector(final int dim, final double stdDev) { double[] vect = new double[dim]; for (int j = 0; j < vect.length; j++) { vect[j] = RNG.gaussianDouble(stdDev); @@ -843,10 +844,10 @@ public class Mathematics { /** * Reflect the entries of x which violate the bounds to within the range. * Return the number of violating dimensions. - * + * * @param x * @param range - * @return the number of violating dimensions + * @return The number of violating dimensions */ public static int reflectBounds(double[] x, double[][] range) { int viols = 0; @@ -854,8 +855,7 @@ public class Mathematics { for (int i = 0; i < x.length; i++) { double dimLen = range[i][1] - range[i][0]; if (dimLen <= 0.) { - EVAERROR - .errorMsgOnce("Error in reflectBounds: empty range! (possibly multiple errors)"); + EVAERROR.errorMsgOnce("Error in reflectBounds: empty range! (possibly multiple errors)"); } else { if (x[i] < range[i][0]) { viols++; @@ -867,8 +867,9 @@ public class Mathematics { } else if (x[i] > range[i][1]) { viols++; d = x[i] - range[i][1]; - while (d > dimLen) + while (d > dimLen) { d -= dimLen; // avoid violating the other bound + } // immediately x[i] = range[i][1] - d; } @@ -890,12 +891,15 @@ public class Mathematics { */ public static double reflectValue(double val, double step, double min, double max) { - while (step > (max - min)) + while (step > (max - min)) { step -= (max - min); - if ((val + step) > max) + } + if ((val + step) > max) { return (2 * max - val - step); - if ((val + step) < min) + } + if ((val + step) < min) { return (2 * min - val - step); + } return (val += step); } @@ -916,15 +920,17 @@ public class Mathematics { */ public static double relDist(double[] x, double[] y, double def) throws Exception { - if (x.length != y.length) - throw new Exception( - "The vectors x and y must have the same dimension"); + if (x.length != y.length) { + throw new Exception("The vectors x and y must have the same dimension"); + } double d = 0; - for (int i = 0; i < x.length; i++) - if (y[i] != 0) + for (int i = 0; i < x.length; i++) { + if (y[i] != 0) { d += Math.pow(((x[i] - y[i]) / y[i]), 2); - else + } else { d += def; + } + } return d; } @@ -943,8 +949,9 @@ public class Mathematics { for (int i = 0; i < src.length; i++) { dst[src.length - i - 1] = src[i]; } - } else + } else { System.err.println("Mismatching array lengths!"); + } } /** @@ -1015,7 +1022,7 @@ public class Mathematics { /** * Scale a range by the given factor, meaning that the interval in each - * dimension is extended (fact>1) or reduced (fact<1) by the defined ratio + * dimension is extended (fact>1) or reduced (fact < 1) by the defined ratio * around the center. * * @param rangeScaleFact @@ -1059,33 +1066,6 @@ public class Mathematics { } } - // <<<<<<< .working - // /** - // * Computes a spline interpolation of the two point (x0,f0) and (x1,f1). - // * - // * @param x - // * @param x0 - // * @param x1 - // * @param f0 - // * @param f1 - // * @return If an error with the spline occurs, a linear interpolation will - // be - // * returned. - // */ - // /* public static double splineInterpolation(double x, double x0, double - // x1, - // double f0, double f1) { - // try { - // double[] t = { x0, x1 }, f = { f0, f1 }; - // SplineInterpolation spline = new SplineInterpolation(new BasicDataSet(t, - // f, 1)); - // return spline.getY(x); - // } catch (InterpolationException e) { - // e.printStackTrace(); - // } - // return linearInterpolation(x, x0, x1, f0, f1); - // }*/ - // ======= /** * Computes a spline interpolation of the two point (x0,f0) and (x1,f1). *