TestInstances.java

Index Score
weka.core
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
JAVA0034JAVA0034 Missing braces in if statement
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
COMMENTSComment lines
SIZESize of the file in bytes
LOGICAL_LINESNumber of statements
LINESNumber of lines in the source file
RETURNSNumber of return points from functions
ELOCEffective lines of code
CYCLOMATICCyclomatic complexity
COMPARISONSNumber of comparison operators
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
OPERANDSNumber of operands
JAVA0177JAVA0177 Variable declaration missing initializer
LOCLines of code
EXITSProcedure exits
LOOPSNumber of loops
INTERFACE_COMPLEXITYInterface complexity
FUNCTIONSNumber of function declarations
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
WHITESPACENumber of whitespace lines
JAVA0035JAVA0035 Missing braces in for statement
EXEC_COMMENTSComments in executable code
BLOCKSNumber of blocks
JAVA0076JAVA0076 Use of magic number
JAVA0068JAVA0068 Modifiers not declared in recommended order
PARAMSNumber of formal parameter declarations
LINE_COMMENTNumber of line comments
JAVA0032JAVA0032 Switch statement missing default
UNIQUE_OPERATORSNumber of unique operators
JAVA0036JAVA0036 Missing braces in while statement
JAVA0117JAVA0117 Missing javadoc: method 'method'
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0266JAVA0266 Use of System.out
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0145JAVA0145 Tab character used in source file
/* * 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. */ /* * TestInstances.java * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand */ package weka.core; import weka.core.Capabilities.Capability; import java.io.Serializable; import java.util.Enumeration; import java.util.Random; import java.util.StringTokenizer; import java.util.Vector; /** * Generates artificial datasets for testing. In case of Multi-Instance data * the settings for the number of attributes applies to the data inside * the bag. Originally based on code from the CheckClassifier.<p/> * <!-- options-start --> * Valid options are: <p/> * * <pre> -relation &lt;name&gt; * The name of the data set.</pre> * * <pre> -seed &lt;num&gt; * The seed value.</pre> * * <pre> -num-instances &lt;num&gt; * The number of instances in the datasets (default 20).</pre> * * <pre> -class-type &lt;num&gt; * The class type, see constants in weka.core.Attribute * (default 1=nominal).</pre> * * <pre> -class-values &lt;num&gt; * The number of classes to generate (for nominal classes only) * (default 2).</pre> * * <pre> -class-index &lt;num&gt; * The class index, with -1=last, (default -1).</pre> * * <pre> -no-class * Doesn't include a class attribute in the output.</pre> * * <pre> -nominal &lt;num&gt; * The number of nominal attributes (default 1).</pre> * * <pre> -nominal-values &lt;num&gt; * The number of values for nominal attributes (default 2).</pre> * * <pre> -numeric &lt;num&gt; * The number of numeric attributes (default 0).</pre> * * <pre> -string &lt;num&gt; * The number of string attributes (default 0).</pre> * * <pre> -words &lt;comma-separated-list&gt; * The words to use in string attributes.</pre> * * <pre> -word-separators &lt;chars&gt; * The word separators to use in string attributes.</pre> * * <pre> -date &lt;num&gt; * The number of date attributes (default 0).</pre> * * <pre> -relational &lt;num&gt; * The number of relational attributes (default 0).</pre> * * <pre> -relational-nominal &lt;num&gt; * The number of nominal attributes in a rel. attribute (default 1).</pre> * * <pre> -relational-nominal-values &lt;num&gt; * The number of values for nominal attributes in a rel. attribute (default 2).</pre> * * <pre> -relational-numeric &lt;num&gt; * The number of numeric attributes in a rel. attribute (default 0).</pre> * * <pre> -relational-string &lt;num&gt; * The number of string attributes in a rel. attribute (default 0).</pre> * * <pre> -relational-date &lt;num&gt; * The number of date attributes in a rel. attribute (default 0).</pre> * * <pre> -num-instances-relational &lt;num&gt; * The number of instances in relational/bag attributes (default 10).</pre> * * <pre> -multi-instance * Generates multi-instance data.</pre> * * <pre> -W &lt;classname&gt; * The Capabilities handler to base the dataset on. * The other parameters can be used to override the ones * determined from the handler. Additional parameters for * handler can be passed on after the '--'.</pre> * <!-- options-end --> * * @author FracPete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.10 $ * @see weka.classifiers.CheckClassifier */ public class TestInstances implements Cloneable, Serializable, OptionHandler, RevisionHandler { /** for serialization */ private static final long serialVersionUID = -6263968936330390469L; /** can be used for settting the class attribute index to last * @see #setClassIndex(int) */ public final static int CLASS_IS_LAST = -1; /** can be used to avoid generating a class attribute * @see #setClassIndex(int) */ public final static int NO_CLASS = -2; /** the default list of words used in strings */ public final static String[] DEFAULT_WORDS = {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}; /** the default word separators used in strings */ public final static String DEFAULT_SEPARATORS = " "; /** for generating String attributes/classes */ protected String[] m_Words = DEFAULT_WORDS; /** for generating String attributes/classes */ protected String m_WordSeparators = DEFAULT_SEPARATORS; /** the name of the relation */ protected String m_Relation = "Testdata"; /** the seed value */ protected int m_Seed = 1; /** the random number generator */ protected Random m_Random = new Random(m_Seed); /** the number of instances */ protected int m_NumInstances = 20; /** the class type */ protected int m_ClassType = Attribute.NOMINAL; /** the number of classes (in case of NOMINAL class) */ protected int m_NumClasses = 2; /** the class index (-1 is LAST, -2 means no class) * @see #CLASS_IS_LAST * @see #NO_CLASS */ protected int m_ClassIndex = CLASS_IS_LAST; /** the number of nominal attributes */ protected int m_NumNominal = 1; /** the number of values for nominal attributes */ protected int m_NumNominalValues = 2; /** the number of numeric attributes */ protected int m_NumNumeric = 0; /** the number of string attributes */ protected int m_NumString = 0; /** the number of date attributes */ protected int m_NumDate = 0; /** the number of relational attributes */ protected int m_NumRelational = 0; /** the number of nominal attributes in a relational attribute */ protected int m_NumRelationalNominal = 1; /** the number of values for nominal attributes in relational attributes */ protected int m_NumRelationalNominalValues = 2; /** the number of numeric attributes in a relational attribute */ protected int m_NumRelationalNumeric = 0; /** the number of string attributes in a relational attribute */ protected int m_NumRelationalString = 0; /** the number of date attributes in a relational attribute */ protected int m_NumRelationalDate = 0; /** whether to generate Multi-Instance data or not */ protected boolean m_MultiInstance = false; /** the number of instances in relational attributes (applies also for bags * in multi-instance) */ protected int m_NumInstancesRelational = 10; /** the format of the multi-instance data */ protected Instances[] m_RelationalFormat = null; /** the format of the multi-instance data of the class */ protected Instances m_RelationalClassFormat = null; /** the generated data */ protected Instances m_Data = null; /** the CapabilitiesHandler to get the Capabilities from */ protected CapabilitiesHandler m_Handler = null; /** * the default constructor */ public TestInstances() { super(); setRelation("Testdata"); setSeed(1); setNumInstances(20); setClassType(Attribute.NOMINAL); setNumClasses(2); setClassIndex(CLASS_IS_LAST); setNumNominal(1); setNumNominalValues(2); setNumNumeric(0); setNumString(0); setNumDate(0); setNumRelational(0); setNumRelationalNominal(1); setNumRelationalNominalValues(2); setNumRelationalNumeric(0); setNumRelationalString(0); setNumRelationalDate(0); setNumInstancesRelational(10); setMultiInstance(false); setWords(arrayToList(DEFAULT_WORDS)); setWordSeparators(DEFAULT_SEPARATORS); } /** * creates a clone of the current object * * @return a clone of the current object */ public Object clone() { TestInstances result; result = new TestInstances(); result.assign(this); return result; } /** * updates itself with all the settings from the given TestInstances * object * * @param t the object to get the settings from */ public void assign(TestInstances t) { setRelation(t.getRelation()); setSeed(t.getSeed()); setNumInstances(t.getNumInstances()); setClassType(t.getClassType()); setNumClasses(t.getNumClasses()); setClassIndex(t.getClassIndex()); setNumNominal(t.getNumNominal()); setNumNominalValues(t.getNumNominalValues()); setNumNumeric(t.getNumNumeric()); setNumString(t.getNumString()); setNumDate(t.getNumDate()); setNumRelational(t.getNumRelational()); setNumRelationalNominal(t.getNumRelationalNominal()); setNumRelationalNominalValues(t.getNumRelationalNominalValues()); setNumRelationalNumeric(t.getNumRelationalNumeric()); setNumRelationalString(t.getNumRelationalString()); setNumRelationalDate(t.getNumRelationalDate()); setMultiInstance(t.getMultiInstance()); for (int i = 0; i < t.getNumRelational(); i++) setRelationalFormat(i, t.getRelationalFormat(i)); setRelationalClassFormat(t.getRelationalClassFormat()); setNumInstancesRelational(t.getNumInstancesRelational()); setWords(t.getWords()); setWordSeparators(t.getWordSeparators()); } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector result = new Vector(); result.addElement(new Option( "\tThe name of the data set.", "relation", 1, "-relation <name>")); result.addElement(new Option( "\tThe seed value.", "seed", 1, "-seed <num>")); result.addElement(new Option( "\tThe number of instances in the datasets (default 20).", "num-instances", 1, "-num-instances <num>")); result.addElement(new Option( "\tThe class type, see constants in weka.core.Attribute\n" + "\t(default 1=nominal).", "class-type", 1, "-class-type <num>")); result.addElement(new Option( "\tThe number of classes to generate (for nominal classes only)\n" + "\t(default 2).", "class-values", 1, "-class-values <num>")); result.addElement(new Option( "\tThe class index, with -1=last, (default -1).", "class-index", 1, "-class-index <num>")); result.addElement(new Option( "\tDoesn't include a class attribute in the output.", "no-class", 0, "-no-class")); result.addElement(new Option( "\tThe number of nominal attributes (default 1).", "nominal", 1, "-nominal <num>")); result.addElement(new Option( "\tThe number of values for nominal attributes (default 2).", "nominal-values", 1, "-nominal-values <num>")); result.addElement(new Option( "\tThe number of numeric attributes (default 0).", "numeric", 1, "-numeric <num>")); result.addElement(new Option( "\tThe number of string attributes (default 0).", "string", 1, "-string <num>")); result.addElement(new Option( "\tThe words to use in string attributes.", "words", 1, "-words <comma-separated-list>")); result.addElement(new Option( "\tThe word separators to use in string attributes.", "word-separators", 1, "-word-separators <chars>")); result.addElement(new Option( "\tThe number of date attributes (default 0).", "date", 1, "-date <num>")); result.addElement(new Option( "\tThe number of relational attributes (default 0).", "relational", 1, "-relational <num>")); result.addElement(new Option( "\tThe number of nominal attributes in a rel. attribute (default 1).", "relational-nominal", 1, "-relational-nominal <num>")); result.addElement(new Option( "\tThe number of values for nominal attributes in a rel. attribute (default 2).", "relational-nominal-values", 1, "-relational-nominal-values <num>")); result.addElement(new Option( "\tThe number of numeric attributes in a rel. attribute (default 0).", "relational-numeric", 1, "-relational-numeric <num>")); result.addElement(new Option( "\tThe number of string attributes in a rel. attribute (default 0).", "relational-string", 1, "-relational-string <num>")); result.addElement(new Option( "\tThe number of date attributes in a rel. attribute (default 0).", "relational-date", 1, "-relational-date <num>")); result.addElement(new Option( "\tThe number of instances in relational/bag attributes (default 10).", "num-instances-relational", 1, "-num-instances-relational <num>")); result.addElement(new Option( "\tGenerates multi-instance data.", "multi-instance", 0, "-multi-instance")); result.addElement(new Option( "\tThe Capabilities handler to base the dataset on.\n" + "\tThe other parameters can be used to override the ones\n" + "\tdetermined from the handler. Additional parameters for\n" + "\thandler can be passed on after the '--'.", "W", 1, "-W <classname>")); return result.elements(); } /** * Parses a given list of options. <p/> * <!-- options-start --> * Valid options are: <p/> * * <pre> -relation &lt;name&gt; * The name of the data set.</pre> * * <pre> -seed &lt;num&gt; * The seed value.</pre> * * <pre> -num-instances &lt;num&gt; * The number of instances in the datasets (default 20).</pre> * * <pre> -class-type &lt;num&gt; * The class type, see constants in weka.core.Attribute * (default 1=nominal).</pre> * * <pre> -class-values &lt;num&gt; * The number of classes to generate (for nominal classes only) * (default 2).</pre> * * <pre> -class-index &lt;num&gt; * The class index, with -1=last, (default -1).</pre> * * <pre> -no-class * Doesn't include a class attribute in the output.</pre> * * <pre> -nominal &lt;num&gt; * The number of nominal attributes (default 1).</pre> * * <pre> -nominal-values &lt;num&gt; * The number of values for nominal attributes (default 2).</pre> * * <pre> -numeric &lt;num&gt; * The number of numeric attributes (default 0).</pre> * * <pre> -string &lt;num&gt; * The number of string attributes (default 0).</pre> * * <pre> -words &lt;comma-separated-list&gt; * The words to use in string attributes.</pre> * * <pre> -word-separators &lt;chars&gt; * The word separators to use in string attributes.</pre> * * <pre> -date &lt;num&gt; * The number of date attributes (default 0).</pre> * * <pre> -relational &lt;num&gt; * The number of relational attributes (default 0).</pre> * * <pre> -relational-nominal &lt;num&gt; * The number of nominal attributes in a rel. attribute (default 1).</pre> * * <pre> -relational-nominal-values &lt;num&gt; * The number of values for nominal attributes in a rel. attribute (default 2).</pre> * * <pre> -relational-numeric &lt;num&gt; * The number of numeric attributes in a rel. attribute (default 0).</pre> * * <pre> -relational-string &lt;num&gt; * The number of string attributes in a rel. attribute (default 0).</pre> * * <pre> -relational-date &lt;num&gt; * The number of date attributes in a rel. attribute (default 0).</pre> * * <pre> -num-instances-relational &lt;num&gt; * The number of instances in relational/bag attributes (default 10).</pre> * * <pre> -multi-instance * Generates multi-instance data.</pre> * * <pre> -W &lt;classname&gt; * The Capabilities handler to base the dataset on. * The other parameters can be used to override the ones * determined from the handler. Additional parameters for * handler can be passed on after the '--'.</pre> * <!-- options-end --> * * @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 tmpStr; Class cls; CapabilitiesHandler handler; boolean initialized; initialized = false; tmpStr = Utils.getOption('W', options); if (tmpStr.length() > 0) { cls = Class.forName(tmpStr); if (ClassDiscovery.hasInterface(CapabilitiesHandler.class, cls)) { initialized = true; handler = (CapabilitiesHandler) cls.newInstance(); if (handler instanceof OptionHandler) ((OptionHandler) handler).setOptions(Utils.partitionOptions(options)); setHandler(handler); // initialize this.assign(forCapabilities(handler.getCapabilities())); } else { throw new IllegalArgumentException("Class '" + tmpStr + "' is not a CapabilitiesHandler!"); } } tmpStr = Utils.getOption("relation", options); if (tmpStr.length() != 0) setRelation(tmpStr); else if (!initialized) setRelation("Testdata"); tmpStr = Utils.getOption("seed", options); if (tmpStr.length() != 0) setSeed(Integer.parseInt(tmpStr)); else if (!initialized) setSeed(1); tmpStr = Utils.getOption("num-instances", options); if (tmpStr.length() != 0) setNumInstances(Integer.parseInt(tmpStr)); else if (!initialized) setNumInstances(20); setNoClass(Utils.getFlag("no-class", options)); if (!getNoClass()) { tmpStr = Utils.getOption("class-type", options); if (tmpStr.length() != 0) setClassType(Integer.parseInt(tmpStr)); else if (!initialized) setClassType(Attribute.NOMINAL); tmpStr = Utils.getOption("class-values", options); if (tmpStr.length() != 0) setNumClasses(Integer.parseInt(tmpStr)); else if (!initialized) setNumClasses(2); tmpStr = Utils.getOption("class-index", options); if (tmpStr.length() != 0) setClassIndex(Integer.parseInt(tmpStr)); else if (!initialized) setClassIndex(-1); } tmpStr = Utils.getOption("nominal", options); if (tmpStr.length() != 0) setNumNominal(Integer.parseInt(tmpStr)); else if (!initialized) setNumNominal(1); tmpStr = Utils.getOption("nominal-values", options); if (tmpStr.length() != 0) setNumNominalValues(Integer.parseInt(tmpStr)); else if (!initialized) setNumNominalValues(2); tmpStr = Utils.getOption("numeric", options); if (tmpStr.length() != 0) setNumNumeric(Integer.parseInt(tmpStr)); else if (!initialized) setNumNumeric(0); tmpStr = Utils.getOption("string", options); if (tmpStr.length() != 0) setNumString(Integer.parseInt(tmpStr)); else if (!initialized) setNumString(0); tmpStr = Utils.getOption("words", options); if (tmpStr.length() != 0) setWords(tmpStr); else if (!initialized) setWords(arrayToList(DEFAULT_WORDS)); if (Utils.getOptionPos("word-separators", options) > -1) { tmpStr = Utils.getOption("word-separators", options); setWordSeparators(tmpStr); } else if (!initialized) { setWordSeparators(DEFAULT_SEPARATORS); } tmpStr = Utils.getOption("date", options); if (tmpStr.length() != 0) setNumDate(Integer.parseInt(tmpStr)); else if (!initialized) setNumDate(0); tmpStr = Utils.getOption("relational", options); if (tmpStr.length() != 0) setNumRelational(Integer.parseInt(tmpStr)); else if (!initialized) setNumRelational(0); tmpStr = Utils.getOption("relational-nominal", options); if (tmpStr.length() != 0) setNumRelationalNominal(Integer.parseInt(tmpStr)); else if (!initialized) setNumRelationalNominal(1); tmpStr = Utils.getOption("relational-nominal-values", options); if (tmpStr.length() != 0) setNumRelationalNominalValues(Integer.parseInt(tmpStr)); else if (!initialized) setNumRelationalNominalValues(2); tmpStr = Utils.getOption("relational-numeric", options); if (tmpStr.length() != 0) setNumRelationalNumeric(Integer.parseInt(tmpStr)); else if (!initialized) setNumRelationalNumeric(0); tmpStr = Utils.getOption("relational-string", options); if (tmpStr.length() != 0) setNumRelationalString(Integer.parseInt(tmpStr)); else if (!initialized) setNumRelationalString(0); tmpStr = Utils.getOption("num-instances-relational", options); if (tmpStr.length() != 0) setNumInstancesRelational(Integer.parseInt(tmpStr)); else if (!initialized) setNumInstancesRelational(10); if (!initialized) setMultiInstance(Utils.getFlag("multi-instance", options)); } /** * Gets the current settings of this object. * * @return an array of strings suitable for passing to setOptions */ public String[] getOptions() { Vector result; String[] options; int i; result = new Vector(); result.add("-relation"); result.add(getRelation()); result.add("-seed"); result.add("" + getSeed()); result.add("-num-instances"); result.add("" + getNumInstances()); if (getNoClass()) { result.add("-no-class"); } else { result.add("-class-type"); result.add("" + getClassType()); result.add("-class-values"); result.add("" + getNumClasses()); result.add("-class-index"); result.add("" + getClassIndex()); } result.add("-nominal"); result.add("" + getNumNominal()); result.add("-nominal-values"); result.add("" + getNumNominalValues()); result.add("-numeric"); result.add("" + getNumNumeric()); result.add("-string"); result.add("" + getNumString()); result.add("-words"); result.add("" + getWords()); result.add("-word-separators"); result.add("" + getWordSeparators()); result.add("-date"); result.add("" + getNumDate()); result.add("-relational"); result.add("" + getNumRelational()); result.add("-relational-nominal"); result.add("" + getNumRelationalNominal()); result.add("-relational-nominal-values"); result.add("" + getNumRelationalNominalValues()); result.add("-relational-numeric"); result.add("" + getNumRelationalNumeric()); result.add("-relational-string"); result.add("" + getNumRelationalString()); result.add("-relational-date"); result.add("" + getNumRelationalDate()); result.add("-num-instances-relational"); result.add("" + getNumInstancesRelational()); if (getMultiInstance()) result.add("-multi-instance"); if (getHandler() != null) { result.add("-W"); result.add(getHandler().getClass().getName()); if (getHandler() instanceof OptionHandler) { result.add("--"); options = ((OptionHandler) getHandler()).getOptions(); for (i = 0; i < options.length; i++) result.add(options[i]); } } return (String[]) result.toArray(new String[result.size()]); } /** * sets the name of the relation * * @param value the name of the relation */ public void setRelation(String value) { m_Relation = value; } /** * returns the current name of the relation * * @return the name of the relation */ public String getRelation() { return m_Relation; } /** * sets the seed value for the random number generator * * @param value the seed */ public void setSeed(int value) { m_Seed = value; m_Random = new Random(m_Seed); } /** * returns the current seed value * * @return the seed value */ public int getSeed() { return m_Seed; } /** * sets the number of instances to produce * * @param value the number of instances */ public void setNumInstances(int value) { m_NumInstances = value; } /** * returns the current number of instances to produce * * @return the number of instances */ public int getNumInstances() { return m_NumInstances; } /** * sets the class attribute type * * @param value the class attribute type */ public void setClassType(int value) { m_ClassType = value; m_RelationalClassFormat = null; } /** * returns the current class type * * @return the class attribute type */ public int getClassType() { return m_ClassType; } /** * sets the number of classes * * @param value the number of classes */ public void setNumClasses(int value) { m_NumClasses = value; } /** * returns the current number of classes * * @return the number of classes */ public int getNumClasses() { return m_NumClasses; } /** * sets the class index (0-based) * * @param value the class index * @see #CLASS_IS_LAST * @see #NO_CLASS */ public void setClassIndex(int value) { m_ClassIndex = value; } /** * returns the current class index (0-based), -1 is last attribute * * @return the class index * @see #CLASS_IS_LAST * @see #NO_CLASS */ public int getClassIndex() { return m_ClassIndex; } /** * whether to have no class, e.g., for clusterers; otherwise the class * attribute index is set to last * * @param value whether to have no class * @see #CLASS_IS_LAST * @see #NO_CLASS */ public void setNoClass(boolean value) { if (value) setClassIndex(NO_CLASS); else setClassIndex(CLASS_IS_LAST); } /** * whether no class attribute is generated * * @return true if no class attribute is generated */ public boolean getNoClass() { return (getClassIndex() == NO_CLASS); } /** * sets the number of nominal attributes * * @param value the number of nominal attributes */ public void setNumNominal(int value) { m_NumNominal = value; } /** * returns the current number of nominal attributes * * @return the number of nominal attributes */ public int getNumNominal() { return m_NumNominal; } /** * sets the number of values for nominal attributes * * @param value the number of values */ public void setNumNominalValues(int value) { m_NumNominalValues = value; } /** * returns the current number of values for nominal attributes * * @return the number of values */ public int getNumNominalValues() { return m_NumNominalValues; } /** * sets the number of numeric attributes * * @param value the number of numeric attributes */ public void setNumNumeric(int value) { m_NumNumeric = value; } /** * returns the current number of numeric attributes * * @return the number of numeric attributes */ public int getNumNumeric() { return m_NumNumeric; } /** * sets the number of string attributes * * @param value the number of string attributes */ public void setNumString(int value) { m_NumString = value; } /** * returns the current number of string attributes * * @return the number of string attributes */ public int getNumString() { return m_NumString; } /** * turns the comma-separated list into an array * * @param value the list to process * @return the list as array */ protected static String[] listToArray(String value) { StringTokenizer tok; Vector list; list = new Vector(); tok = new StringTokenizer(value, ","); while (tok.hasMoreTokens()) list.add(tok.nextToken()); return (String[]) list.toArray(new String[list.size()]); } /** * turns the array into a comma-separated list * * @param value the array to process * @return the array as list */ protected static String arrayToList(String[] value) { String result; int i; result = ""; for (i = 0; i < value.length; i++) { if (i > 0) result += ","; result += value[i]; } return result; } /** * Sets the comma-separated list of words to use for generating strings. The * list must contain at least 2 words, otherwise an exception will be thrown. * * @param value the list of words * @throws IllegalArgumentException if not at least 2 words are provided */ public void setWords(String value) { if (listToArray(value).length < 2) throw new IllegalArgumentException("At least 2 words must be provided!"); m_Words = listToArray(value); } /** * returns the words used for assembling strings in a comma-separated list. * * @return the words as comma-separated list */ public String getWords() { return arrayToList(m_Words); } /** * sets the word separators (chars) to use for assembling strings. * * @param value the characters to use as separators */ public void setWordSeparators(String value) { m_WordSeparators = value; } /** * returns the word separators (chars) to use for assembling strings. * * @return the current separators */ public String getWordSeparators() { return m_WordSeparators; } /** * sets the number of date attributes * * @param value the number of date attributes */ public void setNumDate(int value) { m_NumDate = value; } /** * returns the current number of date attributes * * @return the number of date attributes */ public int getNumDate() { return m_NumDate; } /** * sets the number of relational attributes * * @param value the number of relational attributes */ public void setNumRelational(int value) { m_NumRelational = value; m_RelationalFormat = new Instances[value]; } /** * returns the current number of relational attributes * * @return the number of relational attributes */ public int getNumRelational() { return m_NumRelational; } /** * sets the number of nominal attributes in a relational attribute * * @param value the number of nominal attributes */ public void setNumRelationalNominal(int value) { m_NumRelationalNominal = value; } /** * returns the current number of nominal attributes in a relational attribute * * @return the number of nominal attributes */ public int getNumRelationalNominal() { return m_NumRelationalNominal; } /** * sets the number of values for nominal attributes in a relational attribute * * @param value the number of values */ public void setNumRelationalNominalValues(int value) { m_NumRelationalNominalValues = value; } /** * returns the current number of values for nominal attributes in a relational attribute * * @return the number of values */ public int getNumRelationalNominalValues() { return m_NumRelationalNominalValues; } /** * sets the number of numeric attributes in a relational attribute * * @param value the number of numeric attributes */ public void setNumRelationalNumeric(int value) { m_NumRelationalNumeric = value; } /** * returns the current number of numeric attributes in a relational attribute * * @return the number of numeric attributes */ public int getNumRelationalNumeric() { return m_NumRelationalNumeric; } /** * sets the number of string attributes in a relational attribute * * @param value the number of string attributes */ public void setNumRelationalString(int value) { m_NumRelationalString = value; } /** * returns the current number of string attributes in a relational attribute * * @return the number of string attributes */ public int getNumRelationalString() { return m_NumRelationalString; } /** * sets the number of date attributes in a relational attribute * * @param value the number of date attributes */ public void setNumRelationalDate(int value) { m_NumRelationalDate = value; } /** * returns the current number of date attributes in a relational attribute * * @return the number of date attributes */ public int getNumRelationalDate() { return m_NumRelationalDate; } /** * sets the number of instances in relational/bag attributes to produce * * @param value the number of instances */ public void setNumInstancesRelational(int value) { m_NumInstancesRelational = value; } /** * returns the current number of instances in relational/bag attributes to produce * * @return the number of instances */ public int getNumInstancesRelational() { return m_NumInstancesRelational; } /** * sets whether multi-instance data should be generated (with a fixed * data structure) * * @param value whether multi-instance data is generated */ public void setMultiInstance(boolean value) { m_MultiInstance = value; } /** * Gets whether multi-instance data (with a fixed structure) is generated * * @return true if multi-instance data is generated */ public boolean getMultiInstance() { return m_MultiInstance; } /** * sets the structure for the bags for the relational attribute * * @param index the index of the relational attribute * @param value the new structure */ public void setRelationalFormat(int index, Instances value) { if (value != null) m_RelationalFormat[index] = new Instances(value, 0); else m_RelationalFormat[index] = null; } /** * returns the format for the specified relational attribute, can be null * * @param index the index of the relational attribute * @return the current structure */ public Instances getRelationalFormat(int index) { return m_RelationalFormat[index]; } /** * sets the structure for the relational class attribute * * @param value the structure for the relational attribute */ public void setRelationalClassFormat(Instances value) { if (value != null) m_RelationalClassFormat = new Instances(value, 0); else m_RelationalClassFormat = null; } /** * returns the current strcuture of the relational class attribute, can * be null * * @return the relational structure of the class attribute */ public Instances getRelationalClassFormat() { return m_RelationalClassFormat; } /** * returns the overall number of attributes (incl. class, if that is also * generated) * * @return the overall number of attributes */ public int getNumAttributes() { int result; result = m_NumNominal + m_NumNumeric + m_NumString + m_NumDate + m_NumRelational; if (!getNoClass()) result++; return result; } /** * returns the current dataset, can be null * * @return the current dataset */ public Instances getData() { return m_Data; } /** * sets the Capabilities handler to generate the data for * * @param value the handler to generate the data for */ public void setHandler(CapabilitiesHandler value) { m_Handler = value; } /** * returns the current set CapabilitiesHandler to generate the dataset * for, can be null * * @return the handler to generate the data for */ public CapabilitiesHandler getHandler() { return m_Handler; } /** * creates a new Attribute of the given type * * @param index the index of the current attribute (0-based) * @param attType the attribute type (NUMERIC, NOMINAL, etc.) * @return the configured attribute * @throws Exception if something goes wrong, e.g., an unknown attribute type * * @see Attribute#type() * @see #CLASS_IS_LAST * @see #NO_CLASS */ protected Attribute generateAttribute(int index, int attType) throws Exception { Attribute result; String name; int valIndex; int nomCount; String prefix; result = null; // determine name and start-index if (index == CLASS_IS_LAST) { valIndex = 0; name = "Class"; prefix = "class"; nomCount = getNumClasses(); } else { valIndex = index; nomCount = getNumNominalValues(); prefix = "att" + (valIndex + 1) + "val"; switch (attType) { case Attribute.NOMINAL: name = "Nominal" + (valIndex + 1); break; case Attribute.NUMERIC: name = "Numeric" + (valIndex + 1); break; case Attribute.STRING: name = "String" + (valIndex + 1); break; case Attribute.DATE: name = "Date" + (valIndex + 1); break; case Attribute.RELATIONAL: name = "Relational" + (valIndex + 1); break; default: throw new IllegalArgumentException("Attribute type '" + attType + "' unknown!"); } } switch (attType) { case Attribute.NOMINAL: FastVector nomStrings = new FastVector(valIndex + 1); for (int j = 0; j < nomCount; j++) nomStrings.addElement(prefix + (j + 1)); result = new Attribute(name, nomStrings); break; case Attribute.NUMERIC: result = new Attribute(name); break; case Attribute.STRING: result = new Attribute(name, (FastVector) null); break; case Attribute.DATE: result = new Attribute(name, "yyyy-mm-dd"); break; case Attribute.RELATIONAL: Instances rel; if (index == CLASS_IS_LAST) rel = getRelationalClassFormat(); else rel = getRelationalFormat(index); if (rel == null) { TestInstances dataset = new TestInstances(); dataset.setNumNominal(getNumRelationalNominal()); dataset.setNumNominalValues(getNumRelationalNominalValues()); dataset.setNumNumeric(getNumRelationalNumeric()); dataset.setNumString(getNumRelationalString()); dataset.setNumDate(getNumRelationalDate()); dataset.setNumInstances(0); dataset.setClassType(Attribute.NOMINAL); // dummy to avoid endless recursion, will be deleted anyway rel = new Instances(dataset.generate()); if (!getNoClass()) { int clsIndex = rel.classIndex(); rel.setClassIndex(-1); rel.deleteAttributeAt(clsIndex); } } result = new Attribute(name, rel); break; default: throw new IllegalArgumentException("Attribute type '" + attType + "' unknown!"); } return result; } /** * Generates the class value * * @param data the dataset to work on * @return the new class value * @throws Exception if something goes wrong */ protected double generateClassValue(Instances data) throws Exception { double result = Double.NaN; switch (m_ClassType) { case Attribute.NUMERIC: result = m_Random.nextFloat() * 0.25 + Math.abs(m_Random.nextInt()) % Math.max(2, m_NumNominal); break; case Attribute.NOMINAL: result = Math.abs(m_Random.nextInt()) % data.numClasses(); break; case Attribute.STRING: String str = ""; for (int n = 0; n < m_Words.length; n++) { if ( (n > 0) && (m_WordSeparators.length() != 0) ) str += m_WordSeparators.charAt(m_Random.nextInt(m_WordSeparators.length())); str += m_Words[m_Random.nextInt(m_Words.length)]; } result = data.classAttribute().addStringValue(str); break; case Attribute.DATE: result = data.classAttribute().parseDate( (2000 + m_Random.nextInt(100)) + "-01-01"); break; case Attribute.RELATIONAL: if (getRelationalClassFormat() != null) { result = data.classAttribute().addRelation(getRelationalClassFormat()); } else { TestInstances dataset = new TestInstances(); dataset.setNumNominal(getNumRelationalNominal()); dataset.setNumNominalValues(getNumRelationalNominalValues()); dataset.setNumNumeric(getNumRelationalNumeric()); dataset.setNumString(getNumRelationalString()); dataset.setNumDate(getNumRelationalDate()); dataset.setNumInstances(getNumInstancesRelational()); dataset.setClassType(Attribute.NOMINAL); // dummy to avoid endless recursion, will be deleted anyway Instances rel = new Instances(dataset.generate()); int clsIndex = rel.classIndex(); rel.setClassIndex(-1); rel.deleteAttributeAt(clsIndex); result = data.classAttribute().addRelation(rel); } break; } return result; } /** * Generates a new value for the specified attribute. The classValue * might be used in the process. * * @param data the dataset to work on * @param index the index of the attribute * @param classVal the class value for the current instance, might be * used in the calculation * @return the new attribute value * @throws Exception if something goes wrong */ protected double generateAttributeValue(Instances data, int index, double classVal) throws Exception { double result = Double.NaN; switch (data.attribute(index).type()) { case Attribute.NUMERIC: result = classVal * 4 + m_Random.nextFloat() * 1 - 0.5; break; case Attribute.NOMINAL: if (m_Random.nextFloat() < 0.2) { result = Math.abs(m_Random.nextInt()) % data.attribute(index).numValues(); } else { result = ((int)classVal) % data.attribute(index).numValues(); } //result = m_Random.nextInt(data.attribute(index).numValues()); break; case Attribute.STRING: String str = ""; for (int n = 0; n < m_Words.length; n++) { if ( (n > 0) && (m_WordSeparators.length() != 0) ) str += m_WordSeparators.charAt(m_Random.nextInt(m_WordSeparators.length())); str += m_Words[m_Random.nextInt(m_Words.length)]; } result = data.attribute(index).addStringValue(str); break; case Attribute.DATE: result = data.attribute(index).parseDate( (2000 + m_Random.nextInt(100)) + "-01-01"); break; case Attribute.RELATIONAL: Instances rel = new Instances(data.attribute(index).relation(), 0); for (int n = 0; n < getNumInstancesRelational(); n++) { Instance inst = new Instance(rel.numAttributes()); inst.setDataset(data); for (int i = 0; i < rel.numAttributes(); i++) { inst.setValue(i, generateAttributeValue(rel, i, 0)); } rel.add(inst); } result = data.attribute(index).addRelation(rel); break; } return result; } /** * generates a new dataset. * * @return the generated data * @throws Exception if something goes wrong */ public Instances generate() throws Exception { if (getMultiInstance()) { TestInstances bag = (TestInstances) this.clone(); bag.setMultiInstance(false); bag.setNumInstances(0); bag.setSeed(m_Random.nextInt()); Instances bagFormat = bag.generate(); bagFormat.setClassIndex(-1); bagFormat.deleteAttributeAt(bagFormat.numAttributes() - 1); // generate multi-instance structure TestInstances structure = new TestInstances(); structure.setSeed(m_Random.nextInt()); structure.setNumNominal(1); structure.setNumRelational(1); structure.setRelationalFormat(0, bagFormat); structure.setClassType(getClassType()); structure.setNumClasses(getNumClasses()); structure.setRelationalClassFormat(getRelationalClassFormat()); structure.setNumInstances(getNumInstances()); m_Data = structure.generate(); // generate bags bag.setNumInstances(getNumInstancesRelational()); for (int i = 0; i < getNumInstances(); i++) { bag.setSeed(m_Random.nextInt()); Instances bagData = new Instances(bag.generate()); bagData.setClassIndex(-1); bagData.deleteAttributeAt(bagData.numAttributes() - 1); double val = m_Data.attribute(1).addRelation(bagData); m_Data.instance(i).setValue(1, val); } } else { // initialize int clsIndex = m_ClassIndex; if (clsIndex == CLASS_IS_LAST) clsIndex = getNumAttributes() - 1; // generate attributes FastVector attributes = new FastVector(getNumAttributes()); // Add Nominal attributes for (int i = 0; i < getNumNominal(); i++) attributes.addElement(generateAttribute(i, Attribute.NOMINAL)); // Add m_Numeric attributes for (int i = 0; i < getNumNumeric(); i++) attributes.addElement(generateAttribute(i, Attribute.NUMERIC)); // Add some String attributes... for (int i = 0; i < getNumString(); i++) attributes.addElement(generateAttribute(i, Attribute.STRING)); // Add some Date attributes... for (int i = 0; i < getNumDate(); i++) attributes.addElement(generateAttribute(i, Attribute.DATE)); // Add some Relational attributes... for (int i = 0; i < getNumRelational(); i++) attributes.addElement(generateAttribute(i, Attribute.RELATIONAL)); // Add class attribute if (clsIndex != NO_CLASS) attributes.insertElementAt(generateAttribute(CLASS_IS_LAST, getClassType()), clsIndex); m_Data = new Instances(getRelation(), attributes, getNumInstances()); m_Data.setClassIndex(clsIndex); // generate instances for (int i = 0; i < getNumInstances(); i++) { Instance current = new Instance(getNumAttributes()); current.setDataset(m_Data); // class double classVal; if (clsIndex != NO_CLASS) { classVal = generateClassValue(m_Data); current.setClassValue(classVal); } else { classVal = m_Random.nextFloat(); } // other attributes for (int n = 0; n < getNumAttributes(); n++) { if (clsIndex == n) continue; current.setValue(n, generateAttributeValue(m_Data, n, classVal)); } m_Data.add(current); } } if (m_Data.classIndex() == NO_CLASS) m_Data.setClassIndex(-1); return getData(); } /** * returns a TestInstances instance setup already for the the given * capabilities. * * @param c the capabilities to base the TestInstances on * @return the configured TestInstances object */ public static TestInstances forCapabilities(Capabilities c) { TestInstances result; result = new TestInstances(); // multi-instance? if (c.getOwner() instanceof MultiInstanceCapabilitiesHandler) { Capabilities multi = (Capabilities) ((MultiInstanceCapabilitiesHandler) c.getOwner()).getMultiInstanceCapabilities().clone(); multi.setOwner(null); // otherwise recursive! result = forCapabilities(multi); result.setMultiInstance(true); } else { // class if (c.handles(Capability.NO_CLASS)) result.setClassIndex(NO_CLASS); else if (c.handles(Capability.NOMINAL_CLASS)) result.setClassType(Attribute.NOMINAL); else if (c.handles(Capability.BINARY_CLASS)) result.setClassType(Attribute.NOMINAL); else if (c.handles(Capability.NUMERIC_CLASS)) result.setClassType(Attribute.NUMERIC); else if (c.handles(Capability.DATE_CLASS)) result.setClassType(Attribute.DATE); else if (c.handles(Capability.STRING_CLASS)) result.setClassType(Attribute.STRING); else if (c.handles(Capability.RELATIONAL_CLASS)) result.setClassType(Attribute.RELATIONAL); // # of classes if (c.handles(Capability.UNARY_CLASS)) result.setNumClasses(1); if (c.handles(Capability.BINARY_CLASS)) result.setNumClasses(2); if (c.handles(Capability.NOMINAL_CLASS)) result.setNumClasses(4); // attributes if (c.handles(Capability.NOMINAL_ATTRIBUTES)) { result.setNumNominal(1); result.setNumRelationalNominal(1); } else { result.setNumNominal(0); result.setNumRelationalNominal(0); } if (c.handles(Capability.NUMERIC_ATTRIBUTES)) { result.setNumNumeric(1); result.setNumRelationalNumeric(1); } else { result.setNumNumeric(0); result.setNumRelationalNumeric(0); } if (c.handles(Capability.DATE_ATTRIBUTES)) { result.setNumDate(1); result.setNumRelationalDate(1); } else { result.setNumDate(0); result.setNumRelationalDate(0); } if (c.handles(Capability.STRING_ATTRIBUTES)) { result.setNumString(1); result.setNumRelationalString(1); } else { result.setNumString(0); result.setNumRelationalString(0); } if (c.handles(Capability.RELATIONAL_ATTRIBUTES)) result.setNumRelational(1); else result.setNumRelational(0); } return result; } /** * returns a string representation of the object * * @return a string representation of the object */ public String toString() { String result; result = ""; result += "Relation: " + getRelation() + "\n"; result += "Seed: " + getSeed() + "\n"; result += "# Instances: " + getNumInstances() + "\n"; result += "ClassType: " + getClassType() + "\n"; result += "# Classes: " + getNumClasses() + "\n"; result += "Class index: " + getClassIndex() + "\n"; result += "# Nominal: " + getNumNominal() + "\n"; result += "# Nominal values: " + getNumNominalValues() + "\n"; result += "# Numeric: " + getNumNumeric() + "\n"; result += "# String: " + getNumString() + "\n"; result += "# Date: " + getNumDate() + "\n"; result += "# Relational: " + getNumRelational() + "\n"; result += " - # Nominal: " + getNumRelationalNominal() + "\n"; result += " - # Nominal values: " + getNumRelationalNominalValues() + "\n"; result += " - # Numeric: " + getNumRelationalNumeric() + "\n"; result += " - # String: " + getNumRelationalString() + "\n"; result += " - # Date: " + getNumRelationalDate() + "\n"; result += " - # Instances: " + getNumInstancesRelational() + "\n"; result += "Multi-Instance: " + getMultiInstance() + "\n"; result += "Words: " + getWords() + "\n"; result += "Word separators: " + getWordSeparators() + "\n"; return result; } /** * Returns the revision string. * * @return the revision */ public String getRevision() { return RevisionUtils.extract("$Revision: 1.10 $"); } /** * for running the class from commandline, prints the generated data * to stdout * * @param args the commandline parameters * @throws Exception if something goes wrong */ public static void main(String[] args) throws Exception { TestInstances inst; inst = new TestInstances(); // help requested? if (Utils.getFlag("h", args) || Utils.getFlag("help", args)) { StringBuffer result = new StringBuffer(); result.append("\nTest data generator options:\n\n"); result.append("-h|-help\n\tprints this help\n"); Enumeration enm = inst.listOptions(); while (enm.hasMoreElements()) { Option option = (Option) enm.nextElement(); result.append(option.synopsis() + "\n" + option.description() + "\n"); } System.out.println(result); System.exit(0); } // generate data inst.setOptions(args); System.out.println(inst.generate()); } }

The table below shows all metrics for TestInstances.java.

MetricValueDescription
BLOCKS110.00Number of blocks
BLOCK_COMMENT19.00Number of block comment lines
COMMENTS621.00Comment lines
COMMENT_DENSITY 0.78Comment density
COMPARISONS138.00Number of comparison operators
CYCLOMATIC195.00Cyclomatic complexity
DECL_COMMENTS102.00Comments in declarations
DOC_COMMENT580.00Number of javadoc comment lines
ELOC801.00Effective lines of code
EXEC_COMMENTS22.00Comments in executable code
EXITS124.00Procedure exits
FUNCTIONS68.00Number of function declarations
HALSTEAD_DIFFICULTY129.13Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY173.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 0.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 2.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003468.00JAVA0034 Missing braces in if statement
JAVA0035 8.00JAVA0035 Missing braces in for statement
JAVA0036 1.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 0.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 1.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 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 4.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
JAVA007610.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 0.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 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 1.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
JAVA0145170.00JAVA0145 Tab character used in source file
JAVA0150 0.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 0.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 1.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA017723.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.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 1.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 0.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 0.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 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 2.00JAVA0266 Use of System.out
JAVA0267 0.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
LINES1784.00Number of lines in the source file
LINE_COMMENT22.00Number of line comments
LOC915.00Lines of code
LOGICAL_LINES562.00Number of statements
LOOPS18.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS2193.00Number of operands
OPERATORS4031.00Number of operators
PARAMS39.00Number of formal parameter declarations
PROGRAM_LENGTH6224.00Halstead program length
PROGRAM_VOCAB541.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS134.00Number of return points from functions
SIZE52696.00Size of the file in bytes
UNIQUE_OPERANDS484.00Number of unique operands
UNIQUE_OPERATORS57.00Number of unique operators
WHITESPACE248.00Number of whitespace lines