FindWithCapabilities.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
JAVA0177JAVA0177 Variable declaration missing initializer
COMPARISONSNumber of comparison operators
CYCLOMATICCyclomatic complexity
JAVA0266JAVA0266 Use of System.out
DOC_COMMENTNumber of javadoc comment lines
DECL_COMMENTSComments in declarations
ELOCEffective lines of code
SIZESize of the file in bytes
OPERANDSNumber of operands
LINESNumber of lines in the source file
PROGRAM_LENGTHHalstead program length
LOGICAL_LINESNumber of statements
RETURNSNumber of return points from functions
OPERATORSNumber of operators
COMMENTSComment lines
LOCLines of code
EXITSProcedure exits
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
EXEC_COMMENTSComments in executable code
JAVA0035JAVA0035 Missing braces in for statement
INTERFACE_COMPLEXITYInterface complexity
LOOPSNumber of loops
JAVA0036JAVA0036 Missing braces in while statement
JAVA0166JAVA0166 Generic exception caught
BLOCKSNumber of blocks
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
JAVA0259JAVA0259 Return of collection/array field
JAVA0117JAVA0117 Missing javadoc: method 'method'
LINE_COMMENTNumber of line comments
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
UNIQUE_OPERATORSNumber of unique operators
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0265JAVA0265 Use of Throwable.printStackTrace()
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
WHITESPACENumber of whitespace lines
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0267JAVA0267 Use of System.err
/* * 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. */ /* * FindWithCapabilities.java * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand */ package weka.core; import weka.core.Capabilities.Capability; import weka.gui.GenericPropertiesCreator; import java.io.BufferedReader; import java.io.FileReader; import java.util.Enumeration; import java.util.Iterator; import java.util.Properties; import java.util.StringTokenizer; import java.util.Vector; /** * Locates all classes with certain capabilities. One should keep in mind, * that works only with the default capabilities of a scheme and doesn't * take dependencies into account. E.g., a meta-classifier that could have * a base classifier handling numeric classes, but by default uses one with * a nominal class, will never show up in a search for schemes that handle * numeric classes.<p/> * <!-- options-start --> * Valid options are: <p/> * * <pre> All class and attribute options can be prefixed with 'not', * e.g., '-not-numeric-class'. This makes sure that the returned * schemes 'cannot' handle numeric classes. * </pre> * * <pre> -num-instances &lt;num&gt; * The minimum number of instances (default 1).</pre> * * <pre> -unary-class * Must handle unray classes.</pre> * * <pre> -binary-class * Must handle binary classes.</pre> * * <pre> -nominal-class * Must handle nominal classes.</pre> * * <pre> -numeric-class * Must handle numeric classes.</pre> * * <pre> -string-class * Must handle string classes.</pre> * * <pre> -date-class * Must handle date classes.</pre> * * <pre> -relational-class * Must handle relational classes.</pre> * * <pre> -missing-class-values * Must handle missing class values.</pre> * * <pre> -no-class * Doesn't need a class.</pre> * * <pre> -unary-atts * Must handle unary attributes.</pre> * * <pre> -binary-atts * Must handle binary attributes.</pre> * * <pre> -nominal-atts * Must handle nominal attributes.</pre> * * <pre> -numeric-atts * Must handle numeric attributes.</pre> * * <pre> -string-atts * Must handle string attributes.</pre> * * <pre> -date-atts * Must handle date attributes.</pre> * * <pre> -relational-atts * Must handle relational attributes.</pre> * * <pre> -missing-att-values * Must handle missing attribute values.</pre> * * <pre> -only-multiinstance * Must handle multi-instance data.</pre> * * <pre> -W &lt;classname&gt; * The Capabilities handler to base the handling 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 '--'. * Either '-W' or '-t' can be used.</pre> * * <pre> -t &lt;file&gt; * The dataset to base the capabilities on. * The other parameters can be used to override the ones * determined from the handler. * Either '-t' or '-W' can be used.</pre> * * <pre> -c &lt;num&gt; * The index of the class attribute, -1 for none. * 'first' and 'last' are also valid. * Only in conjunction with option '-t'.</pre> * * <pre> -superclass * Superclass to look for in the packages. * </pre> * * <pre> -packages * Comma-separated list of packages to search in.</pre> * * <pre> -generic * Retrieves the package list from the GenericPropertiesCreator * for the given superclass. (overrides -packages &lt;list&gt;).</pre> * * <pre> -misses * Also prints the classname that didn't match the criteria.</pre> * <!-- options-end --> * * @author fracpete (fracpete at waikato dot ac dot nz) * @version $Revision: 1.5 $ * @see Capabilities * @see Capabilities.Capability * @see GenericPropertiesCreator */ public class FindWithCapabilities implements OptionHandler, CapabilitiesHandler, RevisionHandler { /** the capabilities to look for. */ protected Capabilities m_Capabilities = new Capabilities(this); /** the capabilities to look for to "not have". */ protected Capabilities m_NotCapabilities = new Capabilities(this); /** the packages to search in. */ protected Vector m_Packages = new Vector(); /** a capabilities handler to retrieve the capabilities from. */ protected CapabilitiesHandler m_Handler = null; /** a file the capabilities can be based on. */ protected String m_Filename = ""; /** the class index, in case the capabilities are based on a file. */ protected SingleIndex m_ClassIndex = new SingleIndex(); /** the superclass from the GenericPropertiesCreator to retrieve the packages from. */ protected String m_Superclass = ""; /** whether to use the GenericPropertiesCreator with the superclass. */ protected boolean m_GenericPropertiesCreator = false; /** the classes that matched. */ protected Vector m_Matches = new Vector(); /** the class that didn't match. */ protected Vector m_Misses = new Vector(); /** * 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( "", "", 0, "All class and attribute options can be prefixed with 'not',\n" + "e.g., '-not-numeric-class'. This makes sure that the returned\n" + "schemes 'cannot' handle numeric classes.")); result.addElement(new Option( "\tThe minimum number of instances (default 1).", "num-instances", 1, "-num-instances <num>")); result.addElement(new Option( "\tMust handle unray classes.", "unary-class", 0, "-unary-class")); result.addElement(new Option( "\tMust handle binary classes.", "binary-class", 0, "-binary-class")); result.addElement(new Option( "\tMust handle nominal classes.", "nominal-class", 0, "-nominal-class")); result.addElement(new Option( "\tMust handle numeric classes.", "numeric-class", 0, "-numeric-class")); result.addElement(new Option( "\tMust handle string classes.", "string-class", 0, "-string-class")); result.addElement(new Option( "\tMust handle date classes.", "date-class", 0, "-date-class")); result.addElement(new Option( "\tMust handle relational classes.", "relational-class", 0, "-relational-class")); result.addElement(new Option( "\tMust handle missing class values.", "missing-class-values", 0, "-missing-class-values")); result.addElement(new Option( "\tDoesn't need a class.", "no-class", 0, "-no-class")); result.addElement(new Option( "\tMust handle unary attributes.", "unary-atts", 0, "-unary-atts")); result.addElement(new Option( "\tMust handle binary attributes.", "binary-atts", 0, "-binary-atts")); result.addElement(new Option( "\tMust handle nominal attributes.", "nominal-atts", 0, "-nominal-atts")); result.addElement(new Option( "\tMust handle numeric attributes.", "numeric-atts", 0, "-numeric-atts")); result.addElement(new Option( "\tMust handle string attributes.", "string-atts", 0, "-string-atts")); result.addElement(new Option( "\tMust handle date attributes.", "date-atts", 0, "-date-atts")); result.addElement(new Option( "\tMust handle relational attributes.", "relational-atts", 0, "-relational-atts")); result.addElement(new Option( "\tMust handle missing attribute values.", "missing-att-values", 0, "-missing-att-values")); result.addElement(new Option( "\tMust handle multi-instance data.", "only-multiinstance", 0, "-only-multiinstance")); result.addElement(new Option( "\tThe Capabilities handler to base the handling 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 '--'.\n" + "\tEither '-W' or '-t' can be used.", "W", 1, "-W <classname>")); result.addElement(new Option( "\tThe dataset to base the capabilities on.\n" + "\tThe other parameters can be used to override the ones\n" + "\tdetermined from the handler.\n" + "\tEither '-t' or '-W' can be used.", "t", 1, "-t <file>")); result.addElement(new Option( "\tThe index of the class attribute, -1 for none.\n" + "\t'first' and 'last' are also valid.\n" + "\tOnly in conjunction with option '-t'.", "c", 1, "-c <num>")); result.addElement(new Option( "\tSuperclass to look for in the packages.\n", "superclass", 1, "-superclass")); result.addElement(new Option( "\tComma-separated list of packages to search in.", "packages", 1, "-packages")); result.addElement(new Option( "\tRetrieves the package list from the GenericPropertiesCreator\n" + "\tfor the given superclass. (overrides -packages <list>).", "generic", 1, "-generic")); result.addElement(new Option( "\tAlso prints the classname that didn't match the criteria.", "misses", 0, "-misses")); return result.elements(); } /** * Parses a given list of options. * * @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; StringTokenizer tok; GenericPropertiesCreator creator; Properties props; m_Capabilities = new Capabilities(this); 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); } else { throw new IllegalArgumentException("Class '" + tmpStr + "' is not a CapabilitiesHandler!"); } } else { tmpStr = Utils.getOption('c', options); if (tmpStr.length() != 0) setClassIndex(tmpStr); else setClassIndex("last"); tmpStr = Utils.getOption('t', options); setFilename(tmpStr); } tmpStr = Utils.getOption("num-instances", options); if (tmpStr.length() != 0) m_Capabilities.setMinimumNumberInstances(Integer.parseInt(tmpStr)); else if (!initialized) m_Capabilities.setMinimumNumberInstances(1); // allowed if (Utils.getFlag("no-class", options)) enable(Capability.NO_CLASS); // not allowed if (Utils.getFlag("not-no-class", options)) enableNot(Capability.NO_CLASS); if (!m_Capabilities.handles(Capability.NO_CLASS)) { // allowed if (Utils.getFlag("nominal-class", options)) { enable(Capability.NOMINAL_CLASS); disable(Capability.BINARY_CLASS); } if (Utils.getFlag("binary-class", options)) { enable(Capability.BINARY_CLASS); disable(Capability.UNARY_CLASS); } if (Utils.getFlag("unary-class", options)) enable(Capability.UNARY_CLASS); if (Utils.getFlag("numeric-class", options)) enable(Capability.NUMERIC_CLASS); if (Utils.getFlag("string-class", options)) enable(Capability.STRING_CLASS); if (Utils.getFlag("date-class", options)) enable(Capability.DATE_CLASS); if (Utils.getFlag("relational-class", options)) enable(Capability.RELATIONAL_CLASS); if (Utils.getFlag("missing-class-values", options)) enable(Capability.MISSING_CLASS_VALUES); } // not allowed if (Utils.getFlag("not-nominal-class", options)) { enableNot(Capability.NOMINAL_CLASS); disableNot(Capability.BINARY_CLASS); } if (Utils.getFlag("not-binary-class", options)) { enableNot(Capability.BINARY_CLASS); disableNot(Capability.UNARY_CLASS); } if (Utils.getFlag("not-unary-class", options)) enableNot(Capability.UNARY_CLASS); if (Utils.getFlag("not-numeric-class", options)) enableNot(Capability.NUMERIC_CLASS); if (Utils.getFlag("not-string-class", options)) enableNot(Capability.STRING_CLASS); if (Utils.getFlag("not-date-class", options)) enableNot(Capability.DATE_CLASS); if (Utils.getFlag("not-relational-class", options)) enableNot(Capability.RELATIONAL_CLASS); if (Utils.getFlag("not-relational-class", options)) enableNot(Capability.RELATIONAL_CLASS); if (Utils.getFlag("not-missing-class-values", options)) enableNot(Capability.MISSING_CLASS_VALUES); // allowed if (Utils.getFlag("nominal-atts", options)) { enable(Capability.NOMINAL_ATTRIBUTES); disable(Capability.BINARY_ATTRIBUTES); } if (Utils.getFlag("binary-atts", options)) { enable(Capability.BINARY_ATTRIBUTES); disable(Capability.UNARY_ATTRIBUTES); } if (Utils.getFlag("unary-atts", options)) enable(Capability.UNARY_ATTRIBUTES); if (Utils.getFlag("numeric-atts", options)) enable(Capability.NUMERIC_ATTRIBUTES); if (Utils.getFlag("string-atts", options)) enable(Capability.STRING_ATTRIBUTES); if (Utils.getFlag("date-atts", options)) enable(Capability.DATE_ATTRIBUTES); if (Utils.getFlag("relational-atts", options)) enable(Capability.RELATIONAL_ATTRIBUTES); if (Utils.getFlag("missing-att-values", options)) enable(Capability.MISSING_VALUES); // not allowed if (Utils.getFlag("not-nominal-atts", options)) { enableNot(Capability.NOMINAL_ATTRIBUTES); disableNot(Capability.BINARY_ATTRIBUTES); } if (Utils.getFlag("not-binary-atts", options)) { enableNot(Capability.BINARY_ATTRIBUTES); disableNot(Capability.UNARY_ATTRIBUTES); } if (Utils.getFlag("not-unary-atts", options)) enableNot(Capability.UNARY_ATTRIBUTES); if (Utils.getFlag("not-numeric-atts", options)) enableNot(Capability.NUMERIC_ATTRIBUTES); if (Utils.getFlag("not-string-atts", options)) enableNot(Capability.STRING_ATTRIBUTES); if (Utils.getFlag("not-date-atts", options)) enableNot(Capability.DATE_ATTRIBUTES); if (Utils.getFlag("not-relational-atts", options)) enableNot(Capability.RELATIONAL_ATTRIBUTES); if (Utils.getFlag("not-missing-att-values", options)) enableNot(Capability.MISSING_VALUES); if (Utils.getFlag("only-multiinstance", options)) enable(Capability.ONLY_MULTIINSTANCE); tmpStr = Utils.getOption("superclass", options); if (tmpStr.length() != 0) m_Superclass = tmpStr; else throw new IllegalArgumentException("A superclass has to be specified!"); tmpStr = Utils.getOption("packages", options); if (tmpStr.length() != 0) { tok = new StringTokenizer(tmpStr, ","); m_Packages = new Vector(); while (tok.hasMoreTokens()) m_Packages.add(tok.nextToken()); } if (Utils.getFlag("generic", options)) { creator = new GenericPropertiesCreator(); creator.execute(false); props = creator.getInputProperties(); tok = new StringTokenizer(props.getProperty(m_Superclass), ","); m_Packages = new Vector(); while (tok.hasMoreTokens()) m_Packages.add(tok.nextToken()); } } /** * 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("-num-instances"); result.add("" + m_Capabilities.getMinimumNumberInstances()); if (isEnabled(Capability.NO_CLASS)) { result.add("-no-class"); } else { if (isEnabled(Capability.UNARY_CLASS)) result.add("-unary-class"); if (isEnabled(Capability.BINARY_CLASS)) result.add("-binary-class"); if (isEnabled(Capability.NOMINAL_CLASS)) result.add("-nominal-class"); if (isEnabled(Capability.NUMERIC_CLASS)) result.add("-numeric-class"); if (isEnabled(Capability.STRING_CLASS)) result.add("-string-class"); if (isEnabled(Capability.DATE_CLASS)) result.add("-date-class"); if (isEnabled(Capability.RELATIONAL_CLASS)) result.add("-relational-class"); if (isEnabled(Capability.MISSING_CLASS_VALUES)) result.add("-missing-class-values"); } if (isEnabled(Capability.UNARY_ATTRIBUTES)) result.add("-unary-atts"); if (isEnabled(Capability.BINARY_ATTRIBUTES)) result.add("-binary-atts"); if (isEnabled(Capability.NOMINAL_ATTRIBUTES)) result.add("-nominal-atts"); if (isEnabled(Capability.NUMERIC_ATTRIBUTES)) result.add("-numeric-atts"); if (isEnabled(Capability.STRING_ATTRIBUTES)) result.add("-string-atts"); if (isEnabled(Capability.DATE_ATTRIBUTES)) result.add("-date-atts"); if (isEnabled(Capability.RELATIONAL_ATTRIBUTES)) result.add("-relational-atts"); if (isEnabled(Capability.MISSING_VALUES)) result.add("-missing-att-values"); // not allowed if (isEnabledNot(Capability.NO_CLASS)) result.add("-not-no-class"); if (isEnabledNot(Capability.UNARY_CLASS)) result.add("-not-unary-class"); if (isEnabledNot(Capability.BINARY_CLASS)) result.add("-not-binary-class"); if (isEnabledNot(Capability.NOMINAL_CLASS)) result.add("-not-nominal-class"); if (isEnabledNot(Capability.NUMERIC_CLASS)) result.add("-not-numeric-class"); if (isEnabledNot(Capability.STRING_CLASS)) result.add("-not-string-class"); if (isEnabledNot(Capability.DATE_CLASS)) result.add("-not-date-class"); if (isEnabledNot(Capability.RELATIONAL_CLASS)) result.add("-not-relational-class"); if (isEnabledNot(Capability.MISSING_CLASS_VALUES)) result.add("-not-missing-class-values"); if (isEnabledNot(Capability.UNARY_ATTRIBUTES)) result.add("-not-unary-atts"); if (isEnabledNot(Capability.BINARY_ATTRIBUTES)) result.add("-not-binary-atts"); if (isEnabledNot(Capability.NOMINAL_ATTRIBUTES)) result.add("-not-nominal-atts"); if (isEnabledNot(Capability.NUMERIC_ATTRIBUTES)) result.add("-not-numeric-atts"); if (isEnabledNot(Capability.STRING_ATTRIBUTES)) result.add("-not-string-atts"); if (isEnabledNot(Capability.DATE_ATTRIBUTES)) result.add("-not-date-atts"); if (isEnabledNot(Capability.RELATIONAL_ATTRIBUTES)) result.add("-not-relational-atts"); if (isEnabledNot(Capability.MISSING_VALUES)) result.add("-not-missing-att-values"); if (isEnabled(Capability.ONLY_MULTIINSTANCE)) result.add("-only-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]); } } else if (getFilename().length() != 0) { result.add("-t"); result.add(getFilename()); result.add("-c"); result.add(m_ClassIndex.getSingleIndex()); } if (m_Superclass.length() != 0) { result.add("-superclass"); result.add(m_Superclass); } else { result.add("-packages"); result.add(m_Packages.toString().replaceAll("\\[", "").replaceAll("\\]", "")); } return (String[]) result.toArray(new String[result.size()]); } /** * sets the Capabilities handler to generate the data for. * * @param value the handler */ public void setHandler(CapabilitiesHandler value) { m_Handler = value; setCapabilities(m_Handler.getCapabilities()); } /** * returns the current set CapabilitiesHandler to generate the dataset * for, can be null. * * @return the handler */ public CapabilitiesHandler getHandler() { return m_Handler; } /** * Sets the dataset filename to base the capabilities on. It immediately * loads the dataset and retrieves the capabilities from it. * * @param value the filename of the dataset */ public void setFilename(String value) { Instances insts; m_Filename = value; if (m_Filename.length() != 0) { try { insts = new Instances(new BufferedReader(new FileReader(m_Filename))); m_ClassIndex.setUpper(insts.numAttributes()); insts.setClassIndex(Integer.parseInt(getClassIndex()) - 1); setCapabilities(Capabilities.forInstances(insts)); } catch (Exception e) { e.printStackTrace(); } } } /** * returns the current filename for the dataset to base the capabilities on. * * @return the filename of the dataset */ public String getFilename() { return m_Filename; } /** * sets the class index, -1 for none, first and last are also valid. * * @param value the class index */ public void setClassIndex(String value) { if (value.equals("-1")) m_ClassIndex = null; else m_ClassIndex = new SingleIndex(value); } /** * returns the current current class index, -1 if no class attribute. * * @return the class index */ public String getClassIndex() { if (m_ClassIndex == null) return "-1"; else return "" + m_ClassIndex.getIndex(); } /** * enables the given capability. * * @param c the capability to enable */ public void enable(Capability c) { m_Capabilities.enable(c); } /** * whether the given capability is enabled. * * @param c the capability to enable * @return true if the capability is enabled */ public boolean isEnabled(Capability c) { return m_Capabilities.handles(c); } /** * disables the given capability. * * @param c the capability to disable */ public void disable(Capability c) { m_Capabilities.disable(c); } /** * enables the given "not to have" capability. * * @param c the capability to enable */ public void enableNot(Capability c) { m_NotCapabilities.enable(c); } /** * whether the given "not to have" capability is enabled. * * @param c the capability to enable * @return true if the capability is enabled */ public boolean isEnabledNot(Capability c) { return m_NotCapabilities.handles(c); } /** * disables the given "not to have" capability. * * @param c the capability to disable */ public void disableNot(Capability c) { m_NotCapabilities.disable(c); } /** * returns true if the given capability can be handled. * * @param c the capability to check * @return true if the capability can be handled */ public boolean handles(Capability c) { return m_Capabilities.handles(c); } /** * The capabilities to search for. * * @return the capabilities to search for * @see Capabilities */ public Capabilities getCapabilities() { return m_Capabilities; } /** * Uses the given Capabilities for the search. * * @param c the capabilities to use for the search */ public void setCapabilities(Capabilities c) { m_Capabilities = (Capabilities) c.clone(); } /** * The "not to have" capabilities to search for. * * @return the capabilities to search for * @see Capabilities */ public Capabilities getNotCapabilities() { return m_NotCapabilities; } /** * Uses the given "not to have" Capabilities for the search. * * @param c the capabilities to use for the search */ public void setNotCapabilities(Capabilities c) { m_NotCapabilities = (Capabilities) c.clone(); } /** * returns the matches from the last find call. * * @return the matching classname from the last find run */ public Vector getMatches() { return m_Matches; } /** * returns the misses from the last find call. * * @return the classnames that didn't match from the last find run */ public Vector getMisses() { return m_Misses; } /** * returns a list with all the classnames that fit the criteria. * * @return contains all classnames that fit the criteria */ public Vector find() { Vector list; int i; Class cls; Object obj; CapabilitiesHandler handler; boolean fits; Capabilities caps; m_Matches = new Vector(); m_Misses = new Vector(); list = ClassDiscovery.find(m_Superclass, (String[]) m_Packages.toArray(new String[m_Packages.size()])); for (i = 0; i < list.size(); i++) { try { cls = Class.forName((String) list.get(i)); obj = cls.newInstance(); // exclude itself if (cls == this.getClass()) continue; // really a CapabilitiesHandler? if (!(obj instanceof CapabilitiesHandler)) continue; // check capabilities enumeration handler = (CapabilitiesHandler) obj; caps = handler.getCapabilities(); fits = true; for (Capability cap: Capability.values()) { if (m_Capabilities.handles(cap)) { if (!(caps.handles(cap))) { fits = false; break; } } } if (!fits) { m_Misses.add(list.get(i)); continue; } // check "not" list for (Capability cap: Capability.values()) { if (m_NotCapabilities.handles(cap)) { if ((caps.handles(cap))) { fits = false; break; } } } if (!fits) { m_Misses.add(list.get(i)); continue; } // other stuff if (caps.getMinimumNumberInstances() > m_Capabilities.getMinimumNumberInstances()) { m_Misses.add(list.get(i)); continue; } // matches all criteria! m_Matches.add(list.get(i)); } catch (Exception e) { // ignore } } return m_Matches; } /** * Returns the revision string. * * @return the revision */ public String getRevision() { return RevisionUtils.extract("$Revision: 1.5 $"); } /** * Executes the location of classes with parameters from the commandline. * * @param args the commandline parameters */ public static void main(String[] args) { FindWithCapabilities find; Vector list; String result; int i; boolean printMisses; Iterator iter; boolean first; printMisses = false; try { find = new FindWithCapabilities(); try { printMisses = Utils.getFlag("misses", args); find.setOptions(args); Utils.checkForRemainingOptions(args); } catch (Exception ex) { result = ex.getMessage() + "\n\n" + find.getClass().getName().replaceAll(".*\\.", "") + " Options:\n\n"; Enumeration enm = find.listOptions(); while (enm.hasMoreElements()) { Option option = (Option) enm.nextElement(); result += option.synopsis() + "\n" + option.description() + "\n"; } throw new Exception(result); } System.out.println("\nSearching for the following Capabilities:"); // allowed System.out.print("- allowed: "); iter = find.getCapabilities().capabilities(); first = true; while (iter.hasNext()) { if (!first) System.out.print(", "); first = false; System.out.print(iter.next()); } System.out.println(); // not allowed System.out.print("- not allowed: "); iter = find.getNotCapabilities().capabilities(); first = true; if (iter.hasNext()) { while (iter.hasNext()) { if (!first) System.out.print(", "); first = false; System.out.print(iter.next()); } System.out.println(); } else { System.out.println("-"); } find.find(); // matches list = find.getMatches(); if (list.size() == 1) System.out.println("\nFound " + list.size() + " class that matched the criteria:\n"); else System.out.println("\nFound " + list.size() + " classes that matched the criteria:\n"); for (i = 0; i < list.size(); i++) System.out.println(list.get(i)); // misses if (printMisses) { list = find.getMisses(); if (list.size() == 1) System.out.println("\nFound " + list.size() + " class that didn't match the criteria:\n"); else System.out.println("\nFound " + list.size() + " classes that didn't match the criteria:\n"); for (i = 0; i < list.size(); i++) System.out.println(list.get(i)); } System.out.println(); } catch (Exception ex) { System.err.println(ex.getMessage()); } } }

The table below shows all metrics for FindWithCapabilities.java.

MetricValueDescription
BLOCKS72.00Number of blocks
BLOCK_COMMENT19.00Number of block comment lines
COMMENTS293.00Comment lines
COMMENT_DENSITY 0.57Comment density
COMPARISONS114.00Number of comparison operators
CYCLOMATIC141.00Cyclomatic complexity
DECL_COMMENTS38.00Comments in declarations
DOC_COMMENT256.00Number of javadoc comment lines
ELOC513.00Effective lines of code
EXEC_COMMENTS18.00Comments in executable code
EXITS81.00Procedure exits
FUNCTIONS25.00Number of function declarations
HALSTEAD_DIFFICULTY94.59Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY91.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 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003481.00JAVA0034 Missing braces in if statement
JAVA0035 3.00JAVA0035 Missing braces in for statement
JAVA0036 2.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 2.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 0.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 0.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 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
JAVA0145278.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 4.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
JAVA017725.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 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 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 3.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 1.00JAVA0265 Use of Throwable.printStackTrace()
JAVA026617.00JAVA0266 Use of System.out
JAVA0267 1.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
LINES988.00Number of lines in the source file
LINE_COMMENT18.00Number of line comments
LOC586.00Lines of code
LOGICAL_LINES295.00Number of statements
LOOPS 9.00Number of loops
NEST_DEPTH 6.00Maximum nesting depth
OPERANDS1437.00Number of operands
OPERATORS2513.00Number of operators
PARAMS14.00Number of formal parameter declarations
PROGRAM_LENGTH3950.00Halstead program length
PROGRAM_VOCAB404.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS77.00Number of return points from functions
SIZE28888.00Size of the file in bytes
UNIQUE_OPERANDS357.00Number of unique operands
UNIQUE_OPERATORS47.00Number of unique operators
WHITESPACE109.00Number of whitespace lines