Experiment.java

Index Score
weka.experiment
Weka

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
COMMENTSComment lines
SIZESize of the file in bytes
LINESNumber of lines in the source file
RETURNSNumber of return points from functions
EXITSProcedure exits
BLOCKSNumber of blocks
LOOPSNumber of loops
COMPARISONSNumber of comparison operators
ELOCEffective lines of code
CYCLOMATICCyclomatic complexity
LOGICAL_LINESNumber of statements
LOCLines of code
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
UNIQUE_OPERANDSNumber of unique operands
OPERANDSNumber of operands
PROGRAM_VOCABHalstead program vocabulary
INTERFACE_COMPLEXITYInterface complexity
JAVA0267JAVA0267 Use of System.err
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
EXEC_COMMENTSComments in executable code
JAVA0233JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
FUNCTIONSNumber of function declarations
LINE_COMMENTNumber of line comments
JAVA0150JAVA0150 java.lang.Error (or subclass) thrown
JAVA0034JAVA0034 Missing braces in if statement
JAVA0166JAVA0166 Generic exception caught
JAVA0265JAVA0265 Use of Throwable.printStackTrace()
NEST_DEPTHMaximum nesting depth
UNIQUE_OPERATORSNumber of unique operators
WHITESPACENumber of whitespace lines
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0177JAVA0177 Variable declaration missing initializer
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0067JAVA0067 Array descriptor on identifier name
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* * Experiment.java * Copyright (C) 1999 University of Waikato, Hamilton, New Zealand * */ package weka.experiment; import weka.core.AdditionalMeasureProducer; import weka.core.FastVector; import weka.core.Instances; import weka.core.Option; import weka.core.OptionHandler; import weka.core.RevisionHandler; import weka.core.RevisionUtils; import weka.core.Utils; import weka.core.converters.AbstractFileLoader; import weka.core.converters.ConverterUtils; import weka.core.xml.KOML; import weka.core.xml.XMLOptions; import weka.experiment.xml.XMLExperiment; import java.beans.PropertyDescriptor; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.util.Enumeration; import java.util.Vector; import javax.swing.DefaultListModel; /** * Holds all the necessary configuration information for a standard * type experiment. This object is able to be serialized for storage * on disk. * <!-- options-start --> * Valid options are: <p/> * * <pre> -L &lt;num&gt; * The lower run number to start the experiment from. * (default 1)</pre> * * <pre> -U &lt;num&gt; * The upper run number to end the experiment at (inclusive). * (default 10)</pre> * * <pre> -T &lt;arff file&gt; * The dataset to run the experiment on. * (required, may be specified multiple times)</pre> * * <pre> -P &lt;class name&gt; * The full class name of a ResultProducer (required). * eg: weka.experiment.RandomSplitResultProducer</pre> * * <pre> -D &lt;class name&gt; * The full class name of a ResultListener (required). * eg: weka.experiment.CSVResultListener</pre> * * <pre> -N &lt;string&gt; * A string containing any notes about the experiment. * (default none)</pre> * * <pre> * Options specific to result producer weka.experiment.RandomSplitResultProducer: * </pre> * * <pre> -P &lt;percent&gt; * The percentage of instances to use for training. * (default 66)</pre> * * <pre> -D * Save raw split evaluator output.</pre> * * <pre> -O &lt;file/directory name/path&gt; * The filename where raw output will be stored. * If a directory name is specified then then individual * outputs will be gzipped, otherwise all output will be * zipped to the named file. Use in conjuction with -D. (default splitEvalutorOut.zip)</pre> * * <pre> -W &lt;class name&gt; * The full class name of a SplitEvaluator. * eg: weka.experiment.ClassifierSplitEvaluator</pre> * * <pre> -R * Set when data is not to be randomized and the data sets' size. * Is not to be determined via probabilistic rounding.</pre> * * <pre> * Options specific to split evaluator weka.experiment.ClassifierSplitEvaluator: * </pre> * * <pre> -W &lt;class name&gt; * The full class name of the classifier. * eg: weka.classifiers.bayes.NaiveBayes</pre> * * <pre> -C &lt;index&gt; * The index of the class for which IR statistics * are to be output. (default 1)</pre> * * <pre> -I &lt;index&gt; * The index of an attribute to output in the * results. This attribute should identify an * instance in order to know which instances are * in the test set of a cross validation. if 0 * no output (default 0).</pre> * * <pre> -P * Add target and prediction columns to the result * for each fold.</pre> * * <pre> * Options specific to classifier weka.classifiers.rules.ZeroR: * </pre> * * <pre> -D * If set, classifier is run in debug mode and * may output additional info to the console</pre> * <!-- options-end --> * * All options after -- will be passed to the result producer. <p> * * @author Len Trigg (trigg@cs.waikato.ac.nz) * @version $Revision: 1.27 $ */ public class Experiment implements Serializable, OptionHandler, RevisionHandler { /** for serialization */ static final long serialVersionUID = 44945596742646663L; /** The filename extension that should be used for experiment files */ public static String FILE_EXTENSION = ".exp"; /** Where results will be sent */ protected ResultListener m_ResultListener = new InstancesResultListener(); /** The result producer */ protected ResultProducer m_ResultProducer = new RandomSplitResultProducer(); /** Lower run number */ protected int m_RunLower = 1; /** Upper run number */ protected int m_RunUpper = 10; /** An array of dataset files */ protected DefaultListModel m_Datasets = new DefaultListModel(); /** True if the exp should also iterate over a property of the RP */ protected boolean m_UsePropertyIterator = false; /** The path to the iterator property */ protected PropertyNode [] m_PropertyPath; /** The array of values to set the property to */ protected Object m_PropertyArray; /** User notes about the experiment */ protected String m_Notes = ""; /** Method names of additional measures of objects contained in the custom property iterator. Only methods names beginning with "measure" and returning doubles are recognised */ protected String [] m_AdditionalMeasures = null; /** True if the class attribute is the first attribute for all datasets involved in this experiment. */ protected boolean m_ClassFirst = false; /** If true an experiment will advance the current data set befor any custom itererator */ protected boolean m_AdvanceDataSetFirst = true; /** * Sets whether the first attribute is treated as the class * for all datasets involved in the experiment. This information * is not output with the result of the experiments! * * @param flag whether the class attribute is the first and not the last */ public void classFirst(boolean flag) { m_ClassFirst = flag; } /** * Get the value of m_DataSetFirstFirst. * * @return Value of m_DataSetFirstFirst. */ public boolean getAdvanceDataSetFirst() { return m_AdvanceDataSetFirst; } /** * Set the value of m_AdvanceDataSetFirst. * * @param newAdvanceDataSetFirst Value to assign to m_AdvanceRunFirst. */ public void setAdvanceDataSetFirst(boolean newAdvanceDataSetFirst) { m_AdvanceDataSetFirst = newAdvanceDataSetFirst; } /** * Gets whether the custom property iterator should be used. * * @return true if so */ public boolean getUsePropertyIterator() { return m_UsePropertyIterator; } /** * Sets whether the custom property iterator should be used. * * @param newUsePropertyIterator true if so */ public void setUsePropertyIterator(boolean newUsePropertyIterator) { m_UsePropertyIterator = newUsePropertyIterator; } /** * Gets the path of properties taken to get to the custom property * to iterate over. * * @return an array of PropertyNodes */ public PropertyNode [] getPropertyPath() { return m_PropertyPath; } /** * Sets the path of properties taken to get to the custom property * to iterate over. * * @param newPropertyPath an array of PropertyNodes */ public void setPropertyPath(PropertyNode [] newPropertyPath) { m_PropertyPath = newPropertyPath; } /** * Sets the array of values to set the custom property to. * * @param newPropArray a value of type Object which should be an * array of the appropriate values. */ public void setPropertyArray(Object newPropArray) { m_PropertyArray = newPropArray; } /** * Gets the array of values to set the custom property to. * * @return a value of type Object which should be an * array of the appropriate values. */ public Object getPropertyArray() { return m_PropertyArray; } /** * Gets the number of custom iterator values that have been defined * for the experiment. * * @return the number of custom property iterator values. */ public int getPropertyArrayLength() { return Array.getLength(m_PropertyArray); } /** * Gets a specified value from the custom property iterator array. * * @param index the index of the value wanted * @return the property array value */ public Object getPropertyArrayValue(int index) { return Array.get(m_PropertyArray, index); } /* These may potentially want to be made un-transient if it is decided * that experiments may be saved mid-run and later resumed */ /** The current run number when the experiment is running */ protected transient int m_RunNumber; /** The current dataset number when the experiment is running */ protected transient int m_DatasetNumber; /** The current custom property value index when the experiment is running */ protected transient int m_PropertyNumber; /** True if the experiment has finished running */ protected transient boolean m_Finished = true; /** The dataset currently being used */ protected transient Instances m_CurrentInstances; /** The custom property value that has actually been set */ protected transient int m_CurrentProperty; /** * When an experiment is running, this returns the current run number. * * @return the current run number. */ public int getCurrentRunNumber() { return m_RunNumber; } /** * When an experiment is running, this returns the current dataset number. * * @return the current dataset number. */ public int getCurrentDatasetNumber() { return m_DatasetNumber; } /** * When an experiment is running, this returns the index of the * current custom property value. * * @return the index of the current custom property value. */ public int getCurrentPropertyNumber() { return m_PropertyNumber; } /** * Prepares an experiment for running, initializing current iterator * settings. * * @throws Exception if an error occurs */ public void initialize() throws Exception { m_RunNumber = getRunLower(); m_DatasetNumber = 0; m_PropertyNumber = 0; m_CurrentProperty = -1; m_CurrentInstances = null; m_Finished = false; if (m_UsePropertyIterator && (m_PropertyArray == null)) { throw new Exception("Null array for property iterator"); } if (getRunLower() > getRunUpper()) { throw new Exception("Lower run number is greater than upper run number"); } if (getDatasets().size() == 0) { throw new Exception("No datasets have been specified"); } if (m_ResultProducer == null) { throw new Exception("No ResultProducer set"); } if (m_ResultListener == null) { throw new Exception("No ResultListener set"); } // if (m_UsePropertyIterator && (m_PropertyArray != null)) { determineAdditionalResultMeasures(); // } m_ResultProducer.setResultListener(m_ResultListener); m_ResultProducer.setAdditionalMeasures(m_AdditionalMeasures); m_ResultProducer.preProcess(); // constrain the additional measures to be only those allowable // by the ResultListener String [] columnConstraints = m_ResultListener. determineColumnConstraints(m_ResultProducer); if (columnConstraints != null) { m_ResultProducer.setAdditionalMeasures(columnConstraints); } } /** * Iterate over the objects in the property array to determine what * (if any) additional measures they support * * @throws Exception if additional measures don't comply to the naming * convention (starting with "measure") */ private void determineAdditionalResultMeasures() throws Exception { m_AdditionalMeasures = null; FastVector measureNames = new FastVector(); // first try the result producer, then property array if applicable if (m_ResultProducer instanceof AdditionalMeasureProducer) { Enumeration am = ((AdditionalMeasureProducer)m_ResultProducer). enumerateMeasures(); while (am.hasMoreElements()) { String mname = (String)am.nextElement(); if (mname.startsWith("measure")) { if (measureNames.indexOf(mname) == -1) { measureNames.addElement(mname); } } else { throw new Exception ("Additional measures in " + m_ResultProducer.getClass().getName() +" must obey the naming convention" +" of starting with \"measure\""); } } } if (m_UsePropertyIterator && (m_PropertyArray != null)) { for (int i = 0; i < Array.getLength(m_PropertyArray); i++) { Object current = Array.get(m_PropertyArray, i); if (current instanceof AdditionalMeasureProducer) { Enumeration am = ((AdditionalMeasureProducer)current). enumerateMeasures(); while (am.hasMoreElements()) { String mname = (String)am.nextElement(); if (mname.startsWith("measure")) { if (measureNames.indexOf(mname) == -1) { measureNames.addElement(mname); } } else { throw new Exception ("Additional measures in " + current.getClass().getName() +" must obey the naming convention" +" of starting with \"measure\""); } } } } } if (measureNames.size() > 0) { m_AdditionalMeasures = new String [measureNames.size()]; for (int i=0;i<measureNames.size();i++) { m_AdditionalMeasures[i] = (String)measureNames.elementAt(i); } } } /** * Recursively sets the custom property value, by setting all values * along the property path. * * @param propertyDepth the current position along the property path * @param origValue the value to set the property to * @throws Exception if an error occurs */ protected void setProperty(int propertyDepth, Object origValue) throws Exception { PropertyDescriptor current = m_PropertyPath[propertyDepth].property; Object subVal = null; if (propertyDepth < m_PropertyPath.length - 1) { Method getter = current.getReadMethod(); Object getArgs [] = { }; subVal = getter.invoke(origValue, getArgs); setProperty(propertyDepth + 1, subVal); } else { subVal = Array.get(m_PropertyArray, m_PropertyNumber); } Method setter = current.getWriteMethod(); Object [] args = { subVal }; setter.invoke(origValue, args); } /** * Returns true if there are more iterations to carry out in the experiment. * * @return true if so */ public boolean hasMoreIterations() { return !m_Finished; } /** * Carries out the next iteration of the experiment. * * @throws Exception if an error occurs */ public void nextIteration() throws Exception { if (m_UsePropertyIterator) { if (m_CurrentProperty != m_PropertyNumber) { setProperty(0, m_ResultProducer); m_CurrentProperty = m_PropertyNumber; } } if (m_CurrentInstances == null) { File currentFile = (File) getDatasets().elementAt(m_DatasetNumber); AbstractFileLoader loader = ConverterUtils.getLoaderForFile(currentFile); loader.setFile(currentFile); Instances data = new Instances(loader.getDataSet()); // only set class attribute if not already done by loader if (data.classIndex() == -1) { if (m_ClassFirst) { data.setClassIndex(0); } else { data.setClassIndex(data.numAttributes() - 1); } } m_CurrentInstances = data; m_ResultProducer.setInstances(m_CurrentInstances); } m_ResultProducer.doRun(m_RunNumber); advanceCounters(); } /** * Increments iteration counters appropriately. */ public void advanceCounters() { if (m_AdvanceDataSetFirst) { m_RunNumber ++; if (m_RunNumber > getRunUpper()) { m_RunNumber = getRunLower(); m_DatasetNumber ++; m_CurrentInstances = null; if (m_DatasetNumber >= getDatasets().size()) { m_DatasetNumber = 0; if (m_UsePropertyIterator) { m_PropertyNumber ++; if (m_PropertyNumber >= Array.getLength(m_PropertyArray)) { m_Finished = true; } } else { m_Finished = true; } } } } else { // advance by custom iterator before data set m_RunNumber ++; if (m_RunNumber > getRunUpper()) { m_RunNumber = getRunLower(); if (m_UsePropertyIterator) { m_PropertyNumber ++; if (m_PropertyNumber >= Array.getLength(m_PropertyArray)) { m_PropertyNumber = 0; m_DatasetNumber ++; m_CurrentInstances = null; if (m_DatasetNumber >= getDatasets().size()) { m_Finished = true; } } } else { m_DatasetNumber ++; m_CurrentInstances = null; if (m_DatasetNumber >= getDatasets().size()) { m_Finished = true; } } } } } /** * Runs all iterations of the experiment, continuing past errors. */ public void runExperiment() { while (hasMoreIterations()) { try { nextIteration(); } catch (Exception ex) { ex.printStackTrace(); System.err.println(ex.getMessage()); advanceCounters(); // Try to keep plowing through } } } /** * Signals that the experiment is finished running, so that cleanup * can be done. * * @throws Exception if an error occurs */ public void postProcess() throws Exception { m_ResultProducer.postProcess(); } /** * Gets the datasets in the experiment. * * @return the datasets in the experiment. */ public DefaultListModel getDatasets() { return m_Datasets; } /** * Set the datasets to use in the experiment * @param ds the list of datasets to use */ public void setDatasets(DefaultListModel ds) { m_Datasets = ds; } /** * Gets the result listener where results will be sent. * * @return the result listener where results will be sent. */ public ResultListener getResultListener() { return m_ResultListener; } /** * Sets the result listener where results will be sent. * * @param newResultListener the result listener where results will be sent. */ public void setResultListener(ResultListener newResultListener) { m_ResultListener = newResultListener; } /** * Get the result producer used for the current experiment. * * @return the result producer used for the current experiment. */ public ResultProducer getResultProducer() { return m_ResultProducer; } /** * Set the result producer used for the current experiment. * * @param newResultProducer result producer to use for the current * experiment. */ public void setResultProducer(ResultProducer newResultProducer) { m_ResultProducer = newResultProducer; } /** * Get the upper run number for the experiment. * * @return the upper run number for the experiment. */ public int getRunUpper() { return m_RunUpper; } /** * Set the upper run number for the experiment. * * @param newRunUpper the upper run number for the experiment. */ public void setRunUpper(int newRunUpper) { m_RunUpper = newRunUpper; } /** * Get the lower run number for the experiment. * * @return the lower run number for the experiment. */ public int getRunLower() { return m_RunLower; } /** * Set the lower run number for the experiment. * * @param newRunLower the lower run number for the experiment. */ public void setRunLower(int newRunLower) { m_RunLower = newRunLower; } /** * Get the user notes. * * @return User notes associated with the experiment. */ public String getNotes() { return m_Notes; } /** * Set the user notes. * * @param newNotes New user notes. */ public void setNotes(String newNotes) { m_Notes = newNotes; } /** * Returns an enumeration describing the available options.. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector newVector = new Vector(6); newVector.addElement(new Option( "\tThe lower run number to start the experiment from.\n" +"\t(default 1)", "L", 1, "-L <num>")); newVector.addElement(new Option( "\tThe upper run number to end the experiment at (inclusive).\n" +"\t(default 10)", "U", 1, "-U <num>")); newVector.addElement(new Option( "\tThe dataset to run the experiment on.\n" + "\t(required, may be specified multiple times)", "T", 1, "-T <arff file>")); newVector.addElement(new Option( "\tThe full class name of a ResultProducer (required).\n" +"\teg: weka.experiment.RandomSplitResultProducer", "P", 1, "-P <class name>")); newVector.addElement(new Option( "\tThe full class name of a ResultListener (required).\n" +"\teg: weka.experiment.CSVResultListener", "D", 1, "-D <class name>")); newVector.addElement(new Option( "\tA string containing any notes about the experiment.\n" +"\t(default none)", "N", 1, "-N <string>")); if ((m_ResultProducer != null) && (m_ResultProducer instanceof OptionHandler)) { newVector.addElement(new Option( "", "", 0, "\nOptions specific to result producer " + m_ResultProducer.getClass().getName() + ":")); Enumeration enm = ((OptionHandler)m_ResultProducer).listOptions(); while (enm.hasMoreElements()) { newVector.addElement(enm.nextElement()); } } return newVector.elements(); } /** * Parses a given list of options. <p/> * <!-- options-start --> * Valid options are: <p/> * * <pre> -L &lt;num&gt; * The lower run number to start the experiment from. * (default 1)</pre> * * <pre> -U &lt;num&gt; * The upper run number to end the experiment at (inclusive). * (default 10)</pre> * * <pre> -T &lt;arff file&gt; * The dataset to run the experiment on. * (required, may be specified multiple times)</pre> * * <pre> -P &lt;class name&gt; * The full class name of a ResultProducer (required). * eg: weka.experiment.RandomSplitResultProducer</pre> * * <pre> -D &lt;class name&gt; * The full class name of a ResultListener (required). * eg: weka.experiment.CSVResultListener</pre> * * <pre> -N &lt;string&gt; * A string containing any notes about the experiment. * (default none)</pre> * * <pre> * Options specific to result producer weka.experiment.RandomSplitResultProducer: * </pre> * * <pre> -P &lt;percent&gt; * The percentage of instances to use for training. * (default 66)</pre> * * <pre> -D * Save raw split evaluator output.</pre> * * <pre> -O &lt;file/directory name/path&gt; * The filename where raw output will be stored. * If a directory name is specified then then individual * outputs will be gzipped, otherwise all output will be * zipped to the named file. Use in conjuction with -D. (default splitEvalutorOut.zip)</pre> * * <pre> -W &lt;class name&gt; * The full class name of a SplitEvaluator. * eg: weka.experiment.ClassifierSplitEvaluator</pre> * * <pre> -R * Set when data is not to be randomized and the data sets' size. * Is not to be determined via probabilistic rounding.</pre> * * <pre> * Options specific to split evaluator weka.experiment.ClassifierSplitEvaluator: * </pre> * * <pre> -W &lt;class name&gt; * The full class name of the classifier. * eg: weka.classifiers.bayes.NaiveBayes</pre> * * <pre> -C &lt;index&gt; * The index of the class for which IR statistics * are to be output. (default 1)</pre> * * <pre> -I &lt;index&gt; * The index of an attribute to output in the * results. This attribute should identify an * instance in order to know which instances are * in the test set of a cross validation. if 0 * no output (default 0).</pre> * * <pre> -P * Add target and prediction columns to the result * for each fold.</pre> * * <pre> * Options specific to classifier weka.classifiers.rules.ZeroR: * </pre> * * <pre> -D * If set, classifier is run in debug mode and * may output additional info to the console</pre> * <!-- options-end --> * * All options after -- will be passed to the result producer. <p> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ public void setOptions(String [] options) throws Exception { String lowerString = Utils.getOption('L', options); if (lowerString.length() != 0) { setRunLower(Integer.parseInt(lowerString)); } else { setRunLower(1); } String upperString = Utils.getOption('U', options); if (upperString.length() != 0) { setRunUpper(Integer.parseInt(upperString)); } else { setRunUpper(10); } if (getRunLower() > getRunUpper()) { throw new Exception("Lower (" + getRunLower() + ") is greater than upper (" + getRunUpper() + ")"); } setNotes(Utils.getOption('N', options)); getDatasets().removeAllElements(); String dataName; do { dataName = Utils.getOption('T', options); if (dataName.length() != 0) { File dataset = new File(dataName); getDatasets().addElement(dataset); } } while (dataName.length() != 0); if (getDatasets().size() == 0) { throw new Exception("Required: -T <arff file name>"); } String rlName = Utils.getOption('D', options); if (rlName.length() == 0) { throw new Exception("Required: -D <ResultListener class name>"); } rlName = rlName.trim(); // split off any options int breakLoc = rlName.indexOf(' '); String clName = rlName; String rlOptionsString = ""; String [] rlOptions = null; if (breakLoc != -1) { clName = rlName.substring(0, breakLoc); rlOptionsString = rlName.substring(breakLoc).trim(); rlOptions = Utils.splitOptions(rlOptionsString); } setResultListener((ResultListener)Utils.forName(ResultListener.class, clName, rlOptions)); String rpName = Utils.getOption('P', options); if (rpName.length() == 0) { throw new Exception("Required: -P <ResultProducer class name>"); } // Do it first without options, so if an exception is thrown during // the option setting, listOptions will contain options for the actual // RP. //GHF -- nice idea, but it prevents you from using result producers that // have *required* parameters setResultProducer((ResultProducer)Utils.forName( ResultProducer.class, rpName, Utils.partitionOptions(options) )); //GHF //GHF if (getResultProducer() instanceof OptionHandler) { //GHF ((OptionHandler) getResultProducer()) //GHF .setOptions(Utils.partitionOptions(options)); //GHF } } /** * Gets the current settings of the experiment iterator. * * @return an array of strings suitable for passing to setOptions */ public String [] getOptions() { // Currently no way to set custompropertyiterators from the command line m_UsePropertyIterator = false; m_PropertyPath = null; m_PropertyArray = null; String [] rpOptions = new String [0]; if ((m_ResultProducer != null) && (m_ResultProducer instanceof OptionHandler)) { rpOptions = ((OptionHandler)m_ResultProducer).getOptions(); } String [] options = new String [rpOptions.length + getDatasets().size() * 2 + 11]; int current = 0; options[current++] = "-L"; options[current++] = "" + getRunLower(); options[current++] = "-U"; options[current++] = "" + getRunUpper(); if (getDatasets().size() != 0) { for (int i = 0; i < getDatasets().size(); i++) { options[current++] = "-T"; options[current++] = getDatasets().elementAt(i).toString(); } } if (getResultListener() != null) { options[current++] = "-D"; options[current++] = getResultListener().getClass().getName(); } if (getResultProducer() != null) { options[current++] = "-P"; options[current++] = getResultProducer().getClass().getName(); } if (!getNotes().equals("")) { options[current++] = "-N"; options[current++] = getNotes(); } options[current++] = "--"; System.arraycopy(rpOptions, 0, options, current, rpOptions.length); current += rpOptions.length; while (current < options.length) { options[current++] = ""; } return options; } /** * Gets a string representation of the experiment configuration. * * @return a value of type 'String' */ public String toString() { String result = "Runs from: " + m_RunLower + " to: " + m_RunUpper + '\n'; result += "Datasets:"; for (int i = 0; i < m_Datasets.size(); i ++) { result += " " + m_Datasets.elementAt(i); } result += '\n'; result += "Custom property iterator: " + (m_UsePropertyIterator ? "on" : "off") + "\n"; if (m_UsePropertyIterator) { if (m_PropertyPath == null) { throw new Error("*** null propertyPath ***"); } if (m_PropertyArray == null) { throw new Error("*** null propertyArray ***"); } if (m_PropertyPath.length > 1) { result += "Custom property path:\n"; for (int i = 0; i < m_PropertyPath.length - 1; i++) { PropertyNode pn = m_PropertyPath[i]; result += "" + (i + 1) + " " + pn.parentClass.getName() + "::" + pn.toString() + ' ' + pn.value.toString() + '\n'; } } result += "Custom property name:" + m_PropertyPath[m_PropertyPath.length - 1].toString() + '\n'; result += "Custom property values:\n"; for (int i = 0; i < Array.getLength(m_PropertyArray); i++) { Object current = Array.get(m_PropertyArray, i); result += " " + (i + 1) + " " + current.getClass().getName() + " " + current.toString() + '\n'; } } result += "ResultProducer: " + m_ResultProducer + '\n'; result += "ResultListener: " + m_ResultListener + '\n'; if (!getNotes().equals("")) { result += "Notes: " + getNotes(); } return result; } /** * Configures/Runs the Experiment from the command line. * * @param args command line arguments to the Experiment. */ public static void main(String[] args) { try { Experiment exp = null; // get options from XML? String xmlOption = Utils.getOption("xml", args); if (!xmlOption.equals("")) args = new XMLOptions(xmlOption).toArray(); String expFile = Utils.getOption('l', args); String saveFile = Utils.getOption('s', args); boolean runExp = Utils.getFlag('r', args); if (expFile.length() == 0) { exp = new Experiment(); try { exp.setOptions(args); Utils.checkForRemainingOptions(args); } catch (Exception ex) { ex.printStackTrace(); String result = "Usage:\n\n" + "-l <exp|xml file>\n" + "\tLoad experiment from file (default use cli options).\n" + "\tThe type is determined, based on the extension (" + FILE_EXTENSION + " or .xml)\n" + "-s <exp|xml file>\n" + "\tSave experiment to file after setting other options.\n" + "\tThe type is determined, based on the extension (" + FILE_EXTENSION + " or .xml)\n" + "\t(default don't save)\n" + "-r\n" + "\tRun experiment (default don't run)\n" + "-xml <filename | xml-string>\n" + "\tget options from XML-Data instead from parameters\n" + "\n"; Enumeration enm = ((OptionHandler)exp).listOptions(); while (enm.hasMoreElements()) { Option option = (Option) enm.nextElement(); result += option.synopsis() + "\n"; result += option.description() + "\n"; } throw new Exception(result + "\n" + ex.getMessage()); } } else { // KOML? if ( (KOML.isPresent()) && (expFile.toLowerCase().endsWith(KOML.FILE_EXTENSION)) ) { exp = (Experiment) KOML.read(expFile); } else // XML? if (expFile.toLowerCase().endsWith(".xml")) { XMLExperiment xml = new XMLExperiment(); exp = (Experiment) xml.read(expFile); } // binary else { FileInputStream fi = new FileInputStream(expFile); ObjectInputStream oi = new ObjectInputStream( new BufferedInputStream(fi)); exp = (Experiment)oi.readObject(); oi.close(); } // allow extra datasets to be added to pre-loaded experiment from command line String dataName; do { dataName = Utils.getOption('T', args); if (dataName.length() != 0) { File dataset = new File(dataName); exp.getDatasets().addElement(dataset); } } while (dataName.length() != 0); } System.err.println("Experiment:\n" + exp.toString()); if (saveFile.length() != 0) { // KOML? if ( (KOML.isPresent()) && (saveFile.toLowerCase().endsWith(KOML.FILE_EXTENSION)) ) { KOML.write(saveFile, exp); } else // XML? if (saveFile.toLowerCase().endsWith(".xml")) { XMLExperiment xml = new XMLExperiment(); xml.write(saveFile, exp); } // binary else { FileOutputStream fo = new FileOutputStream(saveFile); ObjectOutputStream oo = new ObjectOutputStream( new BufferedOutputStream(fo)); oo.writeObject(exp); oo.close(); } } if (runExp) { System.err.println("Initializing..."); exp.initialize(); System.err.println("Iterating..."); exp.runExperiment(); System.err.println("Postprocessing..."); exp.postProcess(); } } catch (Exception ex) { System.err.println(ex.getMessage()); } } /** * Returns the revision string. * * @return the revision */ public String getRevision() { return RevisionUtils.extract("$Revision: 1.27 $"); } } // Experiment

The table below shows all metrics for Experiment.java.

MetricValueDescription
BLOCKS129.00Number of blocks
BLOCK_COMMENT23.00Number of block comment lines
COMMENTS467.00Comment lines
COMMENT_DENSITY 0.97Comment density
COMPARISONS86.00Number of comparison operators
CYCLOMATIC120.00Cyclomatic complexity
DECL_COMMENTS64.00Comments in declarations
DOC_COMMENT419.00Number of javadoc comment lines
ELOC479.00Effective lines of code
EXEC_COMMENTS17.00Comments in executable code
EXITS102.00Procedure exits
FUNCTIONS40.00Number of function declarations
HALSTEAD_DIFFICULTY87.07Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY108.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 1.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 1.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 1.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 4.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 1.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 2.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 1.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 0.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 1.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA0145213.00JAVA0145 Tab character used in source file
JAVA0150 2.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 3.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 2.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 1.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 1.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 1.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 2.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 6.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1184.00Number of lines in the source file
LINE_COMMENT25.00Number of line comments
LOC593.00Lines of code
LOGICAL_LINES288.00Number of statements
LOOPS14.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS1219.00Number of operands
OPERATORS2421.00Number of operators
PARAMS16.00Number of formal parameter declarations
PROGRAM_LENGTH3640.00Halstead program length
PROGRAM_VOCAB424.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS92.00Number of return points from functions
SIZE34926.00Size of the file in bytes
UNIQUE_OPERANDS371.00Number of unique operands
UNIQUE_OPERATORS53.00Number of unique operators
WHITESPACE124.00Number of whitespace lines