AttributeVisualizationPanel.java

Index Score
weka.gui
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
LINE_COMMENTNumber of line comments
EXEC_COMMENTSComments in executable code
COMPARISONSNumber of comparison operators
JAVA0034JAVA0034 Missing braces in if statement
SIZESize of the file in bytes
LOOPSNumber of loops
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
COMMENTSComment lines
OPERANDSNumber of operands
JAVA0076JAVA0076 Use of magic number
LINESNumber of lines in the source file
CYCLOMATICCyclomatic complexity
ELOCEffective lines of code
JAVA0177JAVA0177 Variable declaration missing initializer
LOCLines of code
LOGICAL_LINESNumber of statements
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
DOC_COMMENTNumber of javadoc comment lines
DECL_COMMENTSComments in declarations
JAVA0084JAVA0084 Should use compound assignment operator
JAVA0067JAVA0067 Array descriptor on identifier name
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0081JAVA0081 Boolean literal in comparison
JAVA0035JAVA0035 Missing braces in for statement
BLOCKSNumber of blocks
EXITSProcedure exits
PROGRAM_VOCABHalstead program vocabulary
UNIQUE_OPERANDSNumber of unique operands
JAVA0171JAVA0171 Unused local variable
JAVA0266JAVA0266 Use of System.out
UNIQUE_OPERATORSNumber of unique operators
JAVA0174JAVA0174 Assigned local variable never used
JAVA0265JAVA0265 Use of Throwable.printStackTrace()
JAVA0031JAVA0031 Case statement not properly closed
NEST_DEPTHMaximum nesting depth
JAVA0079JAVA0079 Use of instance to reference static member
WHITESPACENumber of whitespace lines
JAVA0117JAVA0117 Missing javadoc: method 'method'
PROGRAM_VOLUMEHalstead program volume
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
PARAMSNumber of formal parameter declarations
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
INTERFACE_COMPLEXITYInterface complexity
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. */ /* * AttributeVisualizationPanel.java * Copyright (C) 2003 University of Waikato, Hamilton, New Zealand * */ package weka.gui; import weka.core.Attribute; import weka.core.AttributeStats; import weka.core.FastVector; import weka.core.Instances; import weka.core.Utils; import weka.gui.visualize.PrintableComponent; import weka.gui.visualize.PrintablePanel; import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseEvent; import java.io.FileReader; import javax.swing.JComboBox; import javax.swing.JFrame; /** * Creates a panel that shows a visualization of an * attribute in a dataset. For nominal attribute it * shows a bar plot, with each bar corresponding to * each nominal value of the attribute with its height * equal to the frequecy that value appears in the * dataset. For numeric attributes, it displays a * histogram. The width of an interval in the * histogram is calculated using Scott's(1979) * method: <br> * intervalWidth = Max(1, 3.49*Std.Dev*numInstances^(1/3)) * Then the number of intervals is calculated by: <br> * intervals = max(1, Math.round(Range/intervalWidth); * * @author Ashraf M. Kibriya (amk14@cs.waikato.ac.nz) * @version $Revision: 1.27 $ */ public class AttributeVisualizationPanel extends PrintablePanel { /** for serialization */ private static final long serialVersionUID = -8650490488825371193L; /** This holds the current set of instances */ protected Instances m_data; /** * This holds the attribute stats of the current attribute on display. It is * calculated in setAttribute(int idx) when it is called to set a new * attribute index. */ protected AttributeStats m_as; /** This holds the index of the current attribute on display and should be * set through setAttribute(int idx). */ protected int m_attribIndex; /** * This holds the max value of the current attribute. In case of nominal * attribute it is the highest count that a nominal value has in the * attribute (given by m_as.nominalCounts[i]), otherwise in case of numeric * attribute it is simply the maximum value present in the attribute (given by * m_as.numericStats.max). It is used to calculate the ratio of the height of * the bars with respect to the height of the display area. */ protected int m_maxValue; /** * This array holds the count (or height) for the each of the bars in a * barplot or a histogram. In case of barplots (and current attribute being * nominal) its length (and the number of bars) is equal to the number of * nominal values in the current attribute, with each field of the array being * equal to the count of each nominal that it represents (the count of ith * nominal value of an attribute is given by m_as.nominalCounts[i]). Whereas, * in case of histograms (and current attribute being numeric) the width of * its intervals is calculated by Scott's(1979) method: <br> * intervalWidth = Max(1, 3.49*Std.Dev*numInstances^(1/3)) * And the number of intervals by: <br> * intervals = max(1, Math.round(Range/intervalWidth); * Then each field of this array contains the number of values of the current * attribute that fall in the histogram interval that it represents. <br> * NOTE: The values of this array are only calculated if the class attribute * is not set or if it is numeric. */ protected int m_histBarCounts[]; /** * This array holds the per class count (or per class height) of the each of * the bars in a barplot or a histogram. * For nominal attributes the format is: <br> * m_histBarClassCounts[nominalValue][classValue+1]. * For numeric attributes the format is: <br> * m_histBarClassCounts[interval][classValues+1], <br> * where the number of intervals is calculated by the Scott's method as * mentioned above. * The array is initialized to have 1+numClasses to accomodate for instances * with missing class value. The ones with missing class value are displayed * as a black sub par in a histogram or a barplot. * * NOTE: The values of this array are only calculated if the class attribute * is set and it is nominal. */ int m_histBarClassCounts[][]; /** * Contains the range of each bar in a histogram. It is used to work out the * range of bar the mouse pointer is on in getToolTipText(). */ protected double m_barRange; /** Contains the current class index. */ protected int m_classIndex; /** This stores the BarCalc or HistCalc thread while a new barplot or * histogram is being calculated. */ private Thread m_hc; /** True if the thread m_hc above is running. */ private boolean m_threadRun=false; /** This stores and lets the user select a class attribute. It also has * an entry "No Class" if the user does not want to set a class attribute * for colouring. */ protected JComboBox m_colorAttrib; /** * Fontmetrics used to get the font size which is required for calculating * displayable area size, bar height ratio and width of strings that are * displayed on top of bars indicating their count. */ private FontMetrics m_fm; /** * Lock variable to synchronize the different threads running currently in * this class. There are two to three threads in this class, AWT paint thread * which is handled differently in paintComponent() which checks on * m_threadRun to determine if it can perform full paint or not, the second * thread is the main execution thread and the third is the one represented by * m_hc which we start when we want to calculate the internal fields for a bar * plot or a histogram. */ private Integer m_locker = new Integer(1); //Image img; /** Contains discrete colours for colouring of subbars of histograms and * bar plots when the class attribute is set and is nominal */ private FastVector m_colorList = new FastVector(); /** default colour list */ private static final Color [] m_defaultColors = {Color.blue, Color.red, Color.cyan, new Color(75, 123, 130), Color.pink, Color.green, Color.orange, new Color(255, 0, 255), new Color(255, 0, 0), new Color(0, 255, 0), }; /** * Constructor - If used then the class will not show the class selection * combo box. */ public AttributeVisualizationPanel() { this(false); } /** * Constructor. * @param showColouringOption - should be true if the class selection combo * box is to be displayed with the histogram/barplot, or false otherwise. * P.S: the combo box is always created it just won't be shown if * showColouringOption is false. */ public AttributeVisualizationPanel(boolean showColouringOption) { this.setFont( new Font("Default", Font.PLAIN, 9) ); m_fm = this.getFontMetrics( this.getFont() ); this.setToolTipText(""); FlowLayout fl= new FlowLayout(FlowLayout.LEFT); this.setLayout(fl); this.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent ce) { if(m_data!=null) calcGraph(); } }); m_colorAttrib = new JComboBox(); m_colorAttrib.addItemListener( new ItemListener() { public void itemStateChanged(ItemEvent ie) { if(ie.getStateChange()==ItemEvent.SELECTED) { m_classIndex = m_colorAttrib.getSelectedIndex() - 1; if (m_as != null) { setAttribute(m_attribIndex); } } } }); if(showColouringOption) { //m_colorAttrib.setVisible(false); this.add(m_colorAttrib); validate(); } } /** * Sets the instances for use * * @param newins a set of Instances */ public void setInstances(Instances newins) { m_attribIndex = 0; m_as = null; m_data = newins; if(m_colorAttrib!=null) { m_colorAttrib.removeAllItems(); m_colorAttrib.addItem("No class"); for(int i=0; i<m_data.numAttributes(); i++) { String type = ""; switch (m_data.attribute(i).type()) { case Attribute.NOMINAL: type = "(Nom) "; break; case Attribute.NUMERIC: type = "(Num) "; break; case Attribute.STRING: type = "(Str) "; break; case Attribute.DATE: type = "(Dat) "; break; case Attribute.RELATIONAL: type = "(Rel) "; break; default: type = "(???) "; } m_colorAttrib.addItem(new String("Class: "+m_data.attribute(i).name()+ " " + type)); } if (m_data.classIndex() >= 0) { m_colorAttrib.setSelectedIndex(m_data.classIndex() + 1); } else { m_colorAttrib.setSelectedIndex(m_data.numAttributes()); } //if (m_data.classIndex() >= 0) { // m_colorAttrib.setSelectedIndex(m_data.classIndex()); //} } if (m_data.classIndex() >= 0) { m_classIndex = m_data.classIndex(); } else { m_classIndex = m_data.numAttributes()-1; } } /** * Returns the class selection combo box if the parent component wants to * place it in itself or in some component other than this component. */ public JComboBox getColorBox() { return m_colorAttrib; } /** * Get the coloring (class) index for the plot * * @return an <code>int</code> value */ public int getColoringIndex() { return m_classIndex; //m_colorAttrib.getSelectedIndex(); } /** * Set the coloring (class) index for the plot * * @param ci an <code>int</code> value */ public void setColoringIndex(int ci) { m_classIndex = ci; if(m_colorAttrib!=null) m_colorAttrib.setSelectedIndex(ci + 1); else setAttribute(m_attribIndex); } /** * Tells the panel which attribute to visualize. * * @param index The index of the attribute */ public void setAttribute(int index) { synchronized (m_locker) { m_threadRun = true; //if(m_hc!=null && m_hc.isAlive()) m_hc.stop(); m_attribIndex = index; m_as = m_data.attributeStats(m_attribIndex); //m_classIndex = m_colorAttrib.getSelectedIndex(); } calcGraph(); } /** * Recalculates the barplot or histogram to display, required usually when the * attribute is changed or the component is resized. */ public void calcGraph() { synchronized (m_locker) { m_threadRun = true; if(m_as.nominalCounts!=null) { m_hc = new BarCalc(); m_hc.setPriority(m_hc.MIN_PRIORITY); m_hc.start(); } else if(m_as.numericStats!=null) { m_hc = new HistCalc(); m_hc.setPriority(m_hc.MIN_PRIORITY); m_hc.start(); } else { m_histBarCounts = null; m_histBarClassCounts = null; this.repaint(); m_threadRun = false; } } } /** * Internal class that calculates the barplot to display, in a separate * thread. In particular it initializes some of the crucial internal fields * required by paintComponent() to display the histogram for the current * attribute. These include: m_histBarCounts or m_histBarClassCounts, * m_maxValue and m_colorList. */ private class BarCalc extends Thread { public void run() { synchronized (m_locker) { if((m_classIndex >= 0) && (m_data.attribute(m_classIndex).isNominal())) { int histClassCounts[][]; histClassCounts=new int[m_data.attribute(m_attribIndex).numValues()] [m_data.attribute(m_classIndex).numValues()+1]; if (m_as.nominalCounts.length > 0) { m_maxValue = m_as.nominalCounts[0]; for(int i=0; i<m_data.attribute(m_attribIndex).numValues(); i++) { if(m_as.nominalCounts[i]>m_maxValue) m_maxValue = m_as.nominalCounts[i]; } } else { m_maxValue = 0; } if(m_colorList.size()==0) m_colorList.addElement(Color.black); for(int i=m_colorList.size(); i < m_data.attribute(m_classIndex).numValues()+1; i++) { Color pc = m_defaultColors[(i-1) % 10]; int ija = (i-1) / 10; ija *= 2; for (int j=0;j<ija;j++) { pc = pc.darker(); } m_colorList.addElement(pc); } for(int k=0; k<m_data.numInstances(); k++) { //System.out.println("attrib: "+ // m_data.instance(k).value(m_attribIndex)+ // " class: "+ // m_data.instance(k).value(m_classIndex)); if(!m_data.instance(k).isMissing(m_attribIndex)) if(m_data.instance(k).isMissing(m_classIndex)) histClassCounts[(int)m_data.instance(k).value(m_attribIndex)] [0]++; else histClassCounts[(int)m_data.instance(k).value(m_attribIndex)] [(int)m_data.instance(k).value(m_classIndex)+1]++; } //for(int i=0; i<histClassCounts.length; i++) { //int sum=0; //for(int j=0; j<histClassCounts[i].length; j++) { // sum = sum+histClassCounts[i][j]; //} //System.out.println("histCount: "+sum+" Actual: "+ // m_as.nominalCounts[i]); //} m_threadRun=false; m_histBarClassCounts = histClassCounts; //Image tmpImg = new BufferedImage(getWidth(), getHeight(), // BufferedImage.TYPE_INT_RGB); //drawGraph( tmpImg.getGraphics() ); //img = tmpImg; AttributeVisualizationPanel.this.repaint(); } else { int histCounts[]; histCounts = new int[m_data.attribute(m_attribIndex).numValues()]; if (m_as.nominalCounts.length > 0) { m_maxValue = m_as.nominalCounts[0]; for(int i=0; i<m_data.attribute(m_attribIndex).numValues(); i++) { if(m_as.nominalCounts[i]>m_maxValue) m_maxValue = m_as.nominalCounts[i]; } } else { m_maxValue = 0; } for(int k=0; k<m_data.numInstances(); k++) { if(!m_data.instance(k).isMissing(m_attribIndex)) histCounts[(int)m_data.instance(k).value(m_attribIndex)]++; } m_threadRun=false; m_histBarCounts = histCounts; //Image tmpImg = new BufferedImage(getWidth(), getHeight(), // BufferedImage.TYPE_INT_RGB); //drawGraph( tmpImg.getGraphics() ); //img = tmpImg; AttributeVisualizationPanel.this.repaint(); } } //end synchronized } //end run() } /** * Internal class that calculates the histogram to display, in a separate * thread. In particular it initializes some of the crucial internal fields * required by paintComponent() to display the histogram for the current * attribute. These include: m_histBarCounts or m_histBarClassCounts, * m_maxValue and m_colorList. */ private class HistCalc extends Thread { public void run() { synchronized (m_locker) { if((m_classIndex >= 0) && (m_data.attribute(m_classIndex).isNominal())) { int intervals; double intervalWidth=0.0; //This uses the M.P.Wand's method to calculate the histogram's //interval width. See "Data-Based Choice of Histogram Bin Width", in //The American Statistician, Vol. 51, No. 1, Feb., 1997, pp. 59-64. //intervalWidth = Math.pow(6D/( -psi(2, g21())*m_data.numInstances()), // 1/3D ); //This uses the Scott's method to calculate the histogram's interval //width. See "On optimal and data-based histograms". // See Biometrika, 66, 605-610 OR see the same paper mentioned above. intervalWidth = 3.49 * m_as.numericStats.stdDev * Math.pow(m_data.numInstances(), -1/3D); //The Math.max is introduced to remove the possibility of //intervals=0 and =NAN that can happen if respectively all the numeric //values are the same or the interval width is evaluated to zero. intervals = Math.max(1, (int)Math.round( (m_as.numericStats.max - m_as.numericStats.min) / intervalWidth) ); //System.out.println("Max: "+m_as.numericStats.max+ // " Min: "+m_as.numericStats.min+ // " stdDev: "+m_as.numericStats.stdDev+ // "intervalWidth: "+intervalWidth); //The number 4 below actually represents a padding of 3 pixels on //each side of the histogram, and is also reflected in other parts of //the code in the shape of numerical constants like "6" here. if(intervals > AttributeVisualizationPanel.this.getWidth()) { intervals = AttributeVisualizationPanel.this.getWidth()-6; if(intervals<1)//if width is too small then use 1 and forget padding intervals = 1; } int histClassCounts[][] = new int[intervals] [m_data.attribute(m_classIndex).numValues()+1]; double barRange = (m_as.numericStats.max - m_as.numericStats.min) / (double)histClassCounts.length; m_maxValue = 0; if(m_colorList.size()==0) m_colorList.addElement(Color.black); for(int i = m_colorList.size(); i < m_data.attribute(m_classIndex).numValues()+1; i++) { Color pc = m_defaultColors[(i-1) % 10]; int ija = (i-1) / 10; ija *= 2; for (int j=0;j<ija;j++) { pc = pc.darker(); } m_colorList.addElement(pc); } for(int k=0; k<m_data.numInstances(); k++) { int t=0; //This holds the interval that the attibute value of the //new instance belongs to. try { if(!m_data.instance(k).isMissing(m_attribIndex)) { //1. see footnote at the end of this file t = (int)Math.ceil( (float)( (m_data.instance(k).value(m_attribIndex)-m_as.numericStats.min) / barRange) ); if(t==0) { if(m_data.instance(k).isMissing(m_classIndex)) histClassCounts[t][0]++; else histClassCounts[t][(int)m_data.instance(k).value(m_classIndex)+1]++; //if(histCounts[t]>m_maxValue) // m_maxValue = histCounts[t]; } else { if(m_data.instance(k).isMissing(m_classIndex)) histClassCounts[t-1][0]++; else histClassCounts[t-1][(int)m_data.instance(k).value(m_classIndex)+1]++; //if(histCounts[t-1]>m_maxValue) // m_maxValue = histCounts[t-1]; } } } catch(ArrayIndexOutOfBoundsException ae) { System.out.println("t:"+(t)+ " barRange:"+barRange+ " histLength:"+histClassCounts.length+ " value:"+m_data.instance(k).value(m_attribIndex)+ " min:"+m_as.numericStats.min+ " sumResult:"+ (m_data.instance(k).value(m_attribIndex) - m_as.numericStats.min)+ " divideResult:"+ (float)((m_data.instance(k).value(m_attribIndex) - m_as.numericStats.min) / barRange)+ " finalResult:"+ Math.ceil((float)((m_data.instance(k).value(m_attribIndex)- m_as.numericStats.min) / barRange)) ); } } for(int i=0; i<histClassCounts.length; i++) { int sum=0; for(int j=0; j<histClassCounts[i].length; j++) sum = sum+histClassCounts[i][j]; if(m_maxValue<sum) m_maxValue = sum; } m_histBarClassCounts = histClassCounts; m_barRange = barRange; } else { //else if the class attribute is numeric or the class is not set int intervals; double intervalWidth; //At the time of this coding the //possibility of datasets with zero instances //was being dealt with in the //PreProcessPanel of weka Explorer. //old method of calculating number of intervals //intervals = m_as.totalCount>10 ? // (int)(m_as.totalCount*0.1):(int)m_as.totalCount; //This uses the M.P.Wand's method to calculate the histogram's //interval width. See "Data-Based Choice of Histogram Bin Width", in //The American Statistician, Vol. 51, No. 1, Feb., 1997, pp. 59-64. //intervalWidth = Math.pow(6D/(-psi(2, g21())*m_data.numInstances() ), // 1/3D ); //This uses the Scott's method to calculate the histogram's interval //width. See "On optimal and data-based histograms". // See Biometrika, 66, 605-610 OR see the same paper mentioned above. intervalWidth = 3.49 * m_as.numericStats.stdDev * Math.pow(m_data.numInstances(), -1/3D); //The Math.max is introduced to remove the possibility of //intervals=0 and =NAN that can happen if respectively all the numeric //values are the same or the interval width is evaluated to zero. intervals = Math.max(1, (int)Math.round( (m_as.numericStats.max - m_as.numericStats.min) / intervalWidth) ); //The number 4 below actually represents a padding of 3 pixels on //each side of the histogram, and is also reflected in other parts of //the code in the shape of numerical constants like "6" here. if(intervals > AttributeVisualizationPanel.this.getWidth()) { intervals = AttributeVisualizationPanel.this.getWidth()-6; if(intervals<1) intervals = 1; } int histCounts[] = new int[intervals]; double barRange = (m_as.numericStats.max - m_as.numericStats.min) / (double)histCounts.length; m_maxValue = 0; for(int k=0; k<m_data.numInstances(); k++) { int t=0; //This holds the interval to which the current attribute's //value of this particular instance k belongs to. if(m_data.instance(k).isMissing(m_attribIndex)) continue; //ignore missing values try { //1. see footnote at the end of this file t =(int) Math.ceil((float)( (m_data.instance(k).value(m_attribIndex)-m_as.numericStats.min) / barRange)); if(t==0) { histCounts[t]++; if(histCounts[t]>m_maxValue) m_maxValue = histCounts[t]; } else { histCounts[t-1]++; if(histCounts[t-1]>m_maxValue) m_maxValue = histCounts[t-1]; } } catch(ArrayIndexOutOfBoundsException ae) { ae.printStackTrace(); System.out.println("t:"+(t)+ " barRange:"+barRange+ " histLength:"+histCounts.length+ " value:"+m_data.instance(k).value(m_attribIndex)+ " min:"+m_as.numericStats.min+ " sumResult:"+ (m_data.instance(k).value(m_attribIndex)-m_as.numericStats.min)+ " divideResult:"+ (float)((m_data.instance(k).value(m_attribIndex) - m_as.numericStats.min)/barRange)+ " finalResult:"+ Math.ceil( (float)((m_data.instance(k).value(m_attribIndex) - m_as.numericStats.min) / barRange)) ); } } m_histBarCounts = histCounts; m_barRange = barRange; } m_threadRun=false; //Image tmpImg = new BufferedImage(getWidth(), getHeight(), // BufferedImage.TYPE_INT_RGB); //drawGraph( tmpImg.getGraphics() ); //img = tmpImg; AttributeVisualizationPanel.this.repaint(); } } /****Code for M.P.Wand's method of histogram bin width selection. * There is some problem with it. It always comes up -ve value * which is raised to the power 1/3 and gives an NAN. * private static final int M=400; * private double psi(int r, double g) { * double val; * * double sum=0.0; * for(int i=0; i<M; i++) { * double valCjKj=0.0; * for(int j=0; j<M; j++) { * valCjKj += c(j) * k(r, j-i, g); * } * sum += valCjKj*c(i); * } * * val = Math.pow(m_data.numInstances(), -2) * sum; * //System.out.println("psi returns: "+val); * return val; * } * private double g21() { * double val; * * val = Math.pow(2 / ( Math.sqrt(2D*Math.PI)*psi(4, g22()) * * m_data.numInstances() ), 1/5D) * * Math.sqrt(2) * m_as.numericStats.stdDev; * //System.out.println("g21 returns: "+val); * return val; * } * private double g22() { * double val; * * val = Math.pow( 2D/(5*m_data.numInstances()), 1/7D) * * Math.sqrt(2) * m_as.numericStats.stdDev; * //System.out.println("g22 returns: "+val); * return val; * } * private double c(int j) { * double val=0.0; * double sigma = (m_as.numericStats.max - m_as.numericStats.min)/(M-1); * * //System.out.println("In c before doing the sum we have"); * //System.out.println("max: " +m_as.numericStats.max+" min: "+ * // m_as.numericStats.min+" sigma: "+sigma); * * for(int i=0; i<m_data.numInstances(); i++) { * if(!m_data.instance(i).isMissing(m_attribIndex)) * val += Math.max( 0, * ( 1 - Math.abs( Math.pow(sigma, -1)*(m_data.instance(i).value(m_attribIndex) - j) ) ) * ); * } * //System.out.println("c returns: "+val); * return val; * } * private double k(int r, int j, double g) { * double val; * double sigma = (m_as.numericStats.max - m_as.numericStats.min)/(M-1); * //System.out.println("Before calling L we have"); * //System.out.println("Max: "+m_as.numericStats.max+" Min: "+m_as.numericStats.min+"\n"+ * // "r: "+r+" j: "+j+" g: "+g); * val = Math.pow( g, -r-1) * L(sigma*j/g); * //System.out.println("k returns: "+val); * return val; * } * private double L(double x) { * double val; * * val = Math.pow( 2*Math.PI, -1/2D ) * Math.exp( -(x*x)/2D ); * //System.out.println("L returns: "+val); * return val; * } *******End of Wand's method */ } /** * Returns "&lt;nominal value&gt; [&lt;nominal value count&gt;]" * if displaying a bar plot and mouse is on some bar. * If displaying histogram then it * <li>returns "count &lt;br&gt; [&lt;bars Range&gt;]" if mouse is * on the first bar. </li> * <li>returns "count &lt;br&gt; (&lt;bar's Range&gt;]" if mouse is * on some bar other than the first one. </li> * Otherwise it returns "" * * @param ev The mouse event */ public String getToolTipText(MouseEvent ev) { if(m_as!=null && m_as.nominalCounts!=null) { //if current attrib is nominal float intervalWidth = this.getWidth() / (float)m_as.nominalCounts.length; float heightRatio; int barWidth, x=0, y=0; //if intervalWidth is at least six then bar width is 80% of intervalwidth if(intervalWidth>5) //the rest is padding barWidth = (int)Math.floor(intervalWidth*0.8F); else barWidth = 1; //Otherwise barwidth is 1 & padding would be at least 1. //initializing x to maximum of 1 or 10% of interval width (i.e. half of //the padding which is 20% of interval width, as there is 10% on each //side of the bar) so that it points to the start of the 1st bar x = x + (int)( (Math.floor(intervalWidth*0.1F))<1 ? 1:(Math.floor(intervalWidth*0.1F)) ); //Adding to x the appropriate value so that it points to the 1st bar of //our "centered" barplot. If subtracting barplots width from panel width //gives <=2 then the barplot is not centered. if(this.getWidth() - (m_as.nominalCounts.length*barWidth+ (int)( (Math.floor(intervalWidth*0.2F))<1 ? 1:(Math.floor(intervalWidth*0.2F)) ) * m_as.nominalCounts.length) > 2 ) { //The following amounts to adding to x the half of the area left after //subtracting from the components width the width of the whole barplot //(i.e. width of all the bars plus the width of all the bar paddings, //thereby equaling to the whole barplot), since our barplot is centered. x += ( this.getWidth() - (m_as.nominalCounts.length*barWidth + (int)( (Math.floor(intervalWidth*0.2F))<1 ? 1:(Math.floor(intervalWidth*0.2F)) ) * m_as.nominalCounts.length) ) / 2; } for(int i=0; i<m_as.nominalCounts.length; i++) { heightRatio = (this.getHeight()-(float)m_fm.getHeight())/m_maxValue; //initializing y to point to (from top) the start of the bar y = this.getHeight()-Math.round(m_as.nominalCounts[i]*heightRatio); //if our mouse is on a bar then return the count of this bar in our //barplot if(ev.getX() >= x && ev.getX()<=x+barWidth && ev.getY() >= this.getHeight() - Math.round(m_as.nominalCounts[i]*heightRatio) ) return(m_data.attribute(m_attribIndex).value(i)+ " ["+m_as.nominalCounts[i]+"]"); //otherwise advance x to next bar and check that. Add barwidth to x //and padding which is max(1, 20% of interval width) x = x+barWidth+(int)( (Math.floor(intervalWidth*0.2F))<1 ? 1:(Math.floor(intervalWidth*0.2F)) ); } } else if(m_threadRun==false && //if attrib is numeric (m_histBarCounts!=null || m_histBarClassCounts!=null)) { float heightRatio, intervalWidth; int x=0, y=0, barWidth; double bar = m_as.numericStats.min; //if the class attribute is set and it is nominal if((m_classIndex >= 0) && (m_data.attribute(m_classIndex).isNominal())) { //there is 3 pixels of padding on each side of the histogram //the barwidth is 1 if after removing the padding its width is less //then the displayable width barWidth = ((this.getWidth()-6)/m_histBarClassCounts.length)<1 ? 1:((this.getWidth()-6)/m_histBarClassCounts.length); //initializing x to 3 adding appropriate value to make it point to the //start of the 1st bar of our "centered" histogram. x = 3; if( (this.getWidth() - (x + m_histBarClassCounts.length*barWidth)) > 5 ) x += (this.getWidth() - (x + m_histBarClassCounts.length*barWidth))/2; heightRatio = (this.getHeight()-(float)m_fm.getHeight())/m_maxValue; if( ev.getX()-x >= 0) { //The temp holds the index of the current interval that we are looking //at int temp = (int)((ev.getX()-x)/(barWidth+0.0000000001)); if(temp == 0){ //handle the special case temp==0. see footnote 1 int sum=0; for(int k=0; k<m_histBarClassCounts[0].length; k++) sum += m_histBarClassCounts[0][k]; //return the count of the interval mouse is pointing to plus //the range of values that fall into this interval return ("<html><center><font face=Dialog size=-1>"+sum+"<br>"+ "["+Utils.doubleToString(bar+m_barRange*temp,3)+ ", "+Utils.doubleToString((bar+m_barRange*(temp+1)),3)+ "]"+"</font></center></html>"); } else if( temp < m_histBarClassCounts.length ) { //handle case temp!=0 int sum=0; for(int k=0; k<m_histBarClassCounts[temp].length; k++) sum+=m_histBarClassCounts[temp][k]; //return the count of the interval mouse is pointing to plus //the range of values that fall into this interval return ("<html><center><font face=Dialog size=-1>"+sum+"<br>("+ Utils.doubleToString(bar+m_barRange*temp,3)+", "+ Utils.doubleToString((bar+m_barRange*(temp+1)),3)+ "]</font></center></html>"); } } } else { //else if the class attribute is not set or is numeric barWidth = ((this.getWidth()-6)/m_histBarCounts.length) < 1 ? 1 : ((this.getWidth()-6)/m_histBarCounts.length); //initializing x to 3 adding appropriate value to make it point to the //start of the 1st bar of our "centered" histogram. x = 3; if( (this.getWidth() - (x + m_histBarCounts.length*barWidth)) > 5 ) x += (this.getWidth() - (x + m_histBarCounts.length*barWidth))/2; heightRatio = (this.getHeight()-(float)m_fm.getHeight())/m_maxValue; if( ev.getX()-x >= 0) { //Temp holds the index of the current bar we are looking at. int temp = (int)((ev.getX()-x)/(barWidth+0.0000000001)); //return interval count as well as its range if(temp == 0) //handle special case temp==0. see footnote 1. return ("<html><center><font face=Dialog size=-1>"+ m_histBarCounts[0]+"<br>"+ "["+Utils.doubleToString(bar+m_barRange*temp,3)+", "+ Utils.doubleToString((bar+m_barRange*(temp+1)),3)+ "]"+ "</font></center></html>"); else if(temp < m_histBarCounts.length) //handle case temp!=0 return ("<html><center><font face=Dialog size=-1>"+ m_histBarCounts[temp]+"<br>"+ "("+Utils.doubleToString(bar+m_barRange*temp,3)+", "+ Utils.doubleToString((bar+m_barRange*(temp+1)),3)+ "]"+ "</font></center></html>"); } } } return PrintableComponent.getToolTipText(m_Printer); } /** * Paints this component * * @param g The graphics object for this component */ public void paintComponent(Graphics g) { g.clearRect(0,0,this.getWidth(), this.getHeight()); if(m_as!=null) { //If calculations have been done and histogram/barplot if(m_threadRun==false) { //calculation thread is not running int buttonHeight=0; if(m_colorAttrib!=null) buttonHeight =m_colorAttrib.getHeight()+m_colorAttrib.getLocation().y; //if current attribute is nominal then draw barplot. if(m_as.nominalCounts != null && (m_histBarClassCounts!=null || m_histBarCounts!=null) ) { float heightRatio, intervalWidth; int x=0, y=0, barHeight, barWidth; //if the class attribute is set and is nominal then draw coloured //subbars for each bar if((m_classIndex >= 0) && (m_data.attribute(m_classIndex).isNominal())) { intervalWidth=(this.getWidth()/(float)m_histBarClassCounts.length); //Barwidth is 80% of interval width.The remaining 20% is padding, //10% on each side of the bar. If interval width is less then 5 the //20% of that value is less than 1, in that case we use bar width of //1 and padding of 1 pixel on each side of the bar. if(intervalWidth>5) barWidth = (int)Math.floor(intervalWidth*0.8F); else barWidth = 1; //initializing x to 10% of interval width or to 1 if 10% is <1. This //is essentially the LHS padding of the 1st bar. x = x + (int)( (Math.floor(intervalWidth*0.1F))<1 ? 1 : (Math.floor(intervalWidth*0.1F)) ); //Add appropriate value to x so that it starts at the 1st bar of //a "centered" barplot. if(this.getWidth() - (m_histBarClassCounts.length*barWidth + (int)( (Math.floor(intervalWidth*0.2F))<1 ? 1 :(Math.floor(intervalWidth*0.2F)) ) * m_histBarClassCounts.length) > 2 ) { //We take the width of all the bars and all the paddings (20% //of interval width), and subtract it from the width of the panel //to get the extra space that would be left after drawing. We //divide that space by 2 to get its mid-point and add that to our //x, thus making the whole bar plot drawn centered in our //component. x += (this.getWidth()-(m_histBarClassCounts.length*barWidth+ (int)( (Math.floor(intervalWidth*0.2F))<1 ? 1 : (Math.floor(intervalWidth*0.2F)) ) * m_histBarClassCounts.length))/2; } //this holds the count of the bar and will be calculated by adding //up the counts of individual subbars. It is displayed at the top //of each bar. int sum=0; for(int i=0; i<m_histBarClassCounts.length; i++) { //calculating the proportion of the components height compared to //the maxvalue in our attribute, also taking into account the //height of font to display bars count and the height of the class //ComboBox. heightRatio = ( this.getHeight()-(float)m_fm.getHeight() - buttonHeight ) / m_maxValue; y=this.getHeight(); for(int j=0; j<m_histBarClassCounts[i].length; j++) { sum = sum + m_histBarClassCounts[i][j]; y = y-Math.round(m_histBarClassCounts[i][j]*heightRatio); //selecting the colour corresponding to the current class. g.setColor( (Color)m_colorList.elementAt(j) ); g.fillRect(x, y, barWidth, Math.round(m_histBarClassCounts[i][j]*heightRatio)); g.setColor(Color.black); } //drawing the bar count at the top of the bar if it is less than //interval width. draw it 1px up to avoid touching the bar. if(m_fm.stringWidth(Integer.toString(sum))<intervalWidth) g.drawString(Integer.toString(sum), x, y-1); //advancing x to the next bar by adding bar width and padding //of both the bars (i.e. RHS padding of the bar just drawn and LHS //padding of the new bar). x = x+barWidth+(int)( (Math.floor(intervalWidth*0.2F))<1 ? 1:(Math.floor(intervalWidth*0.2F)) ); //reseting sum for the next bar. sum=0; } } //else if class attribute is numeric or not set then draw black bars. else { intervalWidth = (this.getWidth()/(float)m_histBarCounts.length); //same as in the case of nominal class (see inside of if stmt //corresponding to the current else above). if(intervalWidth>5) barWidth = (int)Math.floor(intervalWidth*0.8F); else barWidth = 1; //same as in the case of nominal class (see inside of if stmt //corresponding to the current else above). x = x + (int)( (Math.floor(intervalWidth*0.1F))<1 ? 1:(Math.floor(intervalWidth*0.1F)) ); //same as in the case of nominal class if( this.getWidth() - (m_histBarCounts.length*barWidth+ (int)( (Math.floor(intervalWidth*0.2F))<1 ? 1:(Math.floor(intervalWidth*0.2F)) ) * m_histBarCounts.length) > 2 ) { x += (this.getWidth() -(m_histBarCounts.length*barWidth + (int)((Math.floor(intervalWidth*0.2F))<1 ? 1:(Math.floor(intervalWidth*0.2F)))* m_histBarCounts.length))/2; } for(int i=0; i<m_histBarCounts.length; i++) { //calculating the proportion of the height of the component //compared to the maxValue in our attribute. heightRatio = (this.getHeight()-(float)m_fm.getHeight() - buttonHeight) / m_maxValue; y = this.getHeight()-Math.round(m_histBarCounts[i]*heightRatio); g.fillRect(x, y, barWidth, Math.round(m_histBarCounts[i]*heightRatio)); //draw the bar count if it's width is smaller than intervalWidth. //draw it 1px above to avoid touching the bar. if(m_fm.stringWidth(Integer.toString(m_histBarCounts[i])) < intervalWidth) g.drawString(Integer.toString(m_histBarCounts[i]), x, y-1); //Advance x to the next bar by adding bar-width and padding //of the bars (RHS padding of current bar & LHS padding of next //bar). x = x+barWidth+(int)( (Math.floor(intervalWidth*0.2F))<1 ? 1:(Math.floor(intervalWidth*0.2F)) ); } } } //<--end if m_as.nominalCount!=null //if the current attribute is numeric then draw a histogram. else if(m_as.numericStats != null && (m_histBarClassCounts!=null || m_histBarCounts!=null)) { float heightRatio, intervalWidth; int x=0, y=0, barWidth; //If the class attribute is set and is not numeric then draw coloured //subbars for the histogram bars if((m_classIndex >=0) && (m_data.attribute(m_classIndex).isNominal())) { //There is a padding of 3px on each side of the histogram. barWidth = ((this.getWidth()-6)/m_histBarClassCounts.length)<1 ? 1 : ((this.getWidth()-6)/m_histBarClassCounts.length); //initializing x to start at the start of the 1st bar after padding. x = 3; //Adding appropriate value to x to account for a "centered" //histogram if( (this.getWidth() - (x + m_histBarClassCounts.length*barWidth)) > 5 ) { //We take the current value of x (histogram's RHS padding) and add //the barWidths of all the bars to it to us the size of //our histogram. We subtract that from the width of the panel //giving us the extra space that would be left if the histogram is //drawn and divide that by 2 to get the midpoint of that extra //space. That space is then added to our x, hence making the //histogram centered. x += ( this.getWidth() - (x + m_histBarClassCounts.length*barWidth) ) / 2; } for(int i=0; i<m_histBarClassCounts.length; i++) { //Calculating height ratio. Leave space of 19 for an axis line at //the bottom heightRatio = (this.getHeight()-(float)m_fm.getHeight() - buttonHeight-19) / m_maxValue; y = this.getHeight()-19; //This would hold the count of the bar (sum of sub-bars). int sum = 0; for(int j=0; j<m_histBarClassCounts[i].length; j++) { y = y-Math.round(m_histBarClassCounts[i][j]*heightRatio); //System.out.println("Filling x:"+x+" y:"+y+" width:"+barWidth+ // " height:"+ // (m_histBarClassCounts[i][j]*heightRatio)); //selecting the color corresponding to our class g.setColor( (Color)m_colorList.elementAt(j) ); //drawing the bar if its width is greater than 1 if(barWidth>1) g.fillRect(x, y, barWidth, Math.round(m_histBarClassCounts[i][j]*heightRatio)); //otherwise drawing a line else if((m_histBarClassCounts[i][j]*heightRatio)>0) g.drawLine(x, y, x, y+Math.round(m_histBarClassCounts[i][j]*heightRatio)); g.setColor(Color.black); sum = sum + m_histBarClassCounts[i][j]; } //Drawing bar count on the top of the bar if it is < barWidth if(m_fm.stringWidth(" "+Integer.toString(sum))<barWidth) g.drawString(" "+Integer.toString(sum), x, y-1); //Moving x to the next bar x = x+barWidth; } //Now drawing the axis line at the bottom of the histogram //initializing x again to the start of the plot x = 3; if( (this.getWidth() - (x + m_histBarClassCounts.length*barWidth)) > 5 ) x += (this.getWidth() - (x + m_histBarClassCounts.length*barWidth))/2; g.drawLine(x, this.getHeight()-17, (barWidth==1)?x+barWidth*m_histBarClassCounts.length-1 : x+barWidth*m_histBarClassCounts.length, this.getHeight()-17); //axis line -- see footnote 2. g.drawLine(x, this.getHeight()-16, x, this.getHeight()-12); //minimum line g.drawString(Utils.doubleToString(m_as.numericStats.min, 2), x, this.getHeight()-12+m_fm.getHeight()); //minimum value g.drawLine(x+(barWidth*m_histBarClassCounts.length)/2, this.getHeight()-16, x+(barWidth*m_histBarClassCounts.length)/2, this.getHeight()-12); //median line //Drawing median value. X position for drawing the value is: from //start of the plot take the mid point and subtract from it half //of the width of the value to draw. g.drawString(Utils.doubleToString(m_as.numericStats.max/2+m_as.numericStats.min/2, 2), x+(barWidth*m_histBarClassCounts.length)/2 - m_fm.stringWidth(Utils.doubleToString(m_as.numericStats.max/2+m_as.numericStats.min/2, 2))/2, this.getHeight()-12+m_fm.getHeight()); //median value g.drawLine((barWidth==1) ? x+barWidth*m_histBarClassCounts.length-1: x+barWidth*m_histBarClassCounts.length, this.getHeight()-16, (barWidth==1) ? x+barWidth*m_histBarClassCounts.length-1: x+barWidth*m_histBarClassCounts.length, this.getHeight()-12); //maximum line g.drawString(Utils.doubleToString(m_as.numericStats.max, 2), (barWidth==1) ? x+barWidth*m_histBarClassCounts.length-m_fm.stringWidth(Utils.doubleToString(m_as.numericStats.max, 2))-1: x+barWidth*m_histBarClassCounts.length-m_fm.stringWidth(Utils.doubleToString(m_as.numericStats.max, 2)), this.getHeight()-12+m_fm.getHeight()); //maximum value -- see 2. } else { //if class attribute is numeric //There is a padding of 3px on each side of the histogram. barWidth = ((this.getWidth()-6)/m_histBarCounts.length) < 1 ? 1:((this.getWidth()-6)/m_histBarCounts.length); //Same as above. Pls inside of the if stmt. x = 3; if( (this.getWidth() - (x + m_histBarCounts.length*barWidth)) > 5 ) x += (this.getWidth() - (x + m_histBarCounts.length*barWidth))/2; //Same as above for(int i=0; i<m_histBarCounts.length; i++) { //calculating the ration of the component's height compared to //the maxValue in our current attribute. Leaving 19 pixels to //draw the axis at the bottom of the histogram. heightRatio = (this.getHeight()-(float)m_fm.getHeight() - buttonHeight-19) / m_maxValue; y = this.getHeight() - Math.round(m_histBarCounts[i]*heightRatio)-19; //System.out.println("Filling x:"+x+" y:"+y+" width:"+barWidth+ // " height:"+(m_histBarCounts[i]*heightRatio)); //same as in the if stmt above if(barWidth>1) g.drawRect(x, y, barWidth, Math.round(m_histBarCounts[i]*heightRatio)); else if((m_histBarCounts[i]*heightRatio)>0) g.drawLine(x, y, x, y+Math.round(m_histBarCounts[i]*heightRatio)); if(m_fm.stringWidth(" "+Integer.toString(m_histBarCounts[i])) < barWidth) g.drawString(" "+Integer.toString(m_histBarCounts[i]), x, y-1); x = x+barWidth; } //Now drawing the axis at the bottom of the histogram x = 3; if( (this.getWidth() - (x + m_histBarCounts.length*barWidth)) > 5 ) x += (this.getWidth() - (x + m_histBarCounts.length*barWidth))/2; //This is exact the same as in the if stmt above. See the inside of //the stmt for details g.drawLine(x, this.getHeight()-17, (barWidth==1) ? x+barWidth*m_histBarCounts.length-1 : x+barWidth*m_histBarCounts.length, this.getHeight()-17); //axis line g.drawLine(x, this.getHeight()-16, x, this.getHeight()-12); //minimum line g.drawString(Utils.doubleToString(m_as.numericStats.min, 2), x, this.getHeight()-12+m_fm.getHeight()); //minimum value g.drawLine(x+(barWidth*m_histBarCounts.length)/2, this.getHeight()-16, x+(barWidth*m_histBarCounts.length)/2, this.getHeight()-12); //median line g.drawString(Utils.doubleToString(m_as.numericStats.max/2+m_as.numericStats.min/2, 2), x+(barWidth*m_histBarCounts.length)/2 - m_fm.stringWidth(Utils.doubleToString(m_as.numericStats.max/2+m_as.numericStats.min/2, 2))/2, this.getHeight()-12+m_fm.getHeight()); //median value g.drawLine((barWidth==1) ? x+barWidth*m_histBarCounts.length-1 : x+barWidth*m_histBarCounts.length, this.getHeight()-16, (barWidth==1) ? x+barWidth*m_histBarCounts.length-1 : x+barWidth*m_histBarCounts.length, this.getHeight()-12); //maximum line g.drawString(Utils.doubleToString(m_as.numericStats.max, 2), (barWidth==1) ? x+barWidth*m_histBarCounts.length-m_fm.stringWidth(Utils.doubleToString(m_as.numericStats.max, 2))-1 : x+barWidth*m_histBarCounts.length-m_fm.stringWidth(Utils.doubleToString(m_as.numericStats.max, 2)), this.getHeight()-12+m_fm.getHeight()); //maximum value } //System.out.println("barWidth:"+barWidth+ // " histBarCount:"+m_histBarCounts.length); } else { g.clearRect(0, 0, this.getWidth(), this.getHeight()); g.drawString("Attribute is neither numeric nor nominal.", this.getWidth()/2 - m_fm. stringWidth("Attribute is neither numeric nor nominal.")/2, this.getHeight()/2-m_fm.getHeight()/2); } } //<--end if of calculation thread else { //if still calculation thread is running plot g.clearRect(0, 0, this.getWidth(), this.getHeight()); g.drawString("Calculating. Please Wait...", this.getWidth()/2 - m_fm.stringWidth("Calculating. Please Wait...")/2, this.getHeight()/2-m_fm.getHeight()/2); } } //<--end if(m_as==null) this means } /** * Main method to test this class from command line * * @param args The arff file and the index of the attribute to use */ public static void main(String [] args) { if(args.length!=3) { final JFrame jf = new JFrame("AttribVisualization"); AttributeVisualizationPanel ap = new AttributeVisualizationPanel(); try { Instances ins = new Instances( new FileReader(args[0]) ); ap.setInstances(ins); System.out.println("Loaded: "+args[0]+ "\nRelation: "+ap.m_data.relationName()+ "\nAttributes: "+ap.m_data.numAttributes()); ap.setAttribute( Integer.parseInt(args[1]) ); } catch(Exception ex) { ex.printStackTrace(); System.exit(-1); } System.out.println("The attributes are: "); for(int i=0; i<ap.m_data.numAttributes(); i++) System.out.println(ap.m_data.attribute(i).name()); jf.setSize(500, 300); jf.getContentPane().setLayout( new BorderLayout() ); jf.getContentPane().add(ap, BorderLayout.CENTER ); jf.setDefaultCloseOperation( jf.EXIT_ON_CLOSE ); jf.setVisible(true); } else System.out.println("Usage: java AttributeVisualizationPanel"+ " [arff file] [index of attribute]"); } } /* * t =(int) Math.ceil((float)( * (m_data.instance(k).value(m_attribIndex)-m_as.numericStats.min) * / barRange)); * 1. * This equation gives a value between (i-1)+smallfraction and i if the * attribute m_attribIndex for the current instances lies in the ith * interval. We then increment the value of our i-1th field of our * histogram/barplot array. * If, for example, barRange=3 then, apart from the 1st * interval, each interval i has values in the range * (minValue+3*i-1, minValue+3*i]. The 1st interval has range * [minValue, minValue+i]. Hence it can be seen in the code we specifically * handle t=0 separately. * */ /** * (barWidth==1)?x+barWidth*m_histBarClassCounts.length-1 : * x+barWidth*m_histBarClassCounts.length * 2. * In the case barWidth==1 we subtract 1 otherwise the line become one pixel * longer than the actual size of the histogram */

The table below shows all metrics for AttributeVisualizationPanel.java.

MetricValueDescription
BLOCKS93.00Number of blocks
BLOCK_COMMENT36.00Number of block comment lines
COMMENTS487.00Comment lines
COMMENT_DENSITY 0.78Comment density
COMPARISONS279.00Number of comparison operators
CYCLOMATIC157.00Cyclomatic complexity
DECL_COMMENTS36.00Comments in declarations
DOC_COMMENT253.00Number of javadoc comment lines
ELOC628.00Effective lines of code
EXEC_COMMENTS84.00Comments in executable code
EXITS69.00Procedure exits
FUNCTIONS15.00Number of function declarations
HALSTEAD_DIFFICULTY220.47Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY29.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 1.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003445.00JAVA0034 Missing braces in if statement
JAVA0035 4.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA004910.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 6.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
JAVA007671.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 3.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 2.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA008413.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 1.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 2.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 0.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
JAVA014525.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 1.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 4.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 2.00JAVA0174 Assigned local variable never used
JAVA0175 1.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA017717.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 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 2.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 6.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 5.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 1.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
LINES1327.00Number of lines in the source file
LINE_COMMENT198.00Number of line comments
LOC715.00Lines of code
LOGICAL_LINES341.00Number of statements
LOOPS23.00Number of loops
NEST_DEPTH 7.00Maximum nesting depth
OPERANDS2277.00Number of operands
OPERATORS4311.00Number of operators
PARAMS 9.00Number of formal parameter declarations
PROGRAM_LENGTH6588.00Halstead program length
PROGRAM_VOCAB376.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS20.00Number of return points from functions
SIZE57596.00Size of the file in bytes
UNIQUE_OPERANDS315.00Number of unique operands
UNIQUE_OPERATORS61.00Number of unique operators
WHITESPACE125.00Number of whitespace lines