ScrollableMenu.java

Index Score
util.ui
TV-Browser

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
CYCLOMATICCyclomatic complexity
DECL_COMMENTSComments in declarations
JAVA0076JAVA0076 Use of magic number
BLOCKSNumber of blocks
FUNCTIONSNumber of function declarations
SIZESize of the file in bytes
EXITSProcedure exits
RETURNSNumber of return points from functions
OPERATORSNumber of operators
LOGICAL_LINESNumber of statements
PROGRAM_LENGTHHalstead program length
INTERFACE_COMPLEXITYInterface complexity
LINESNumber of lines in the source file
DOC_COMMENTNumber of javadoc comment lines
LOOPSNumber of loops
OPERANDSNumber of operands
ELOCEffective lines of code
LOCLines of code
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
COMPARISONSNumber of comparison operators
COMMENTSComment lines
LINE_COMMENTNumber of line comments
PARAMSNumber of formal parameter declarations
JAVA0285JAVA0285 Dereference of potentially null variable
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
WHITESPACENumber of whitespace lines
JAVA0034JAVA0034 Missing braces in if statement
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
UNIQUE_OPERATORSNumber of unique operators
JAVA0128JAVA0128 Public constructor in non-public class
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0132JAVA0132 Method overload with compatible signature
JAVA0173JAVA0173 Unused method parameter
JAVA0067JAVA0067 Array descriptor on identifier name
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0075JAVA0075 Method parameter hides field
NEST_DEPTHMaximum nesting depth
JAVA0145JAVA0145 Tab character used in source file
/** * This class was found in the Thread * http://forum.java.sun.com/thread.jspa?forumID=57&threadID=123183 * * I tried to contact the Author, without any luck. If you are the Author and * don't like the Usage of your Code in this Project or want to be named, please * mail us! */ package util.ui; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; import java.awt.Polygon; import java.awt.Rectangle; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Iterator; import java.util.Vector; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.ActionMap; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JSeparator; import javax.swing.MenuElement; import javax.swing.MenuSelectionManager; import javax.swing.Timer; import javax.swing.UIManager; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; import javax.swing.plaf.basic.BasicPopupMenuUI; // This class implements a scrollable JMenu // This class was hacked out in a couple of hours, // You can change maxItemsToDisplay to whatever you want, I used 25 and reduced // it to fit into the screen // I have NOT tested this class very much to see if it loses items, etc, ***USE // AT YOUR OWN RISK*** // Feel free to use and modify (Please add bug fixes here). // // This class should only be used until SUN makes a real scrollable JMenu /** * An implementation of a scrollable menu -- a popup window containing * <code>JMenuItem</code>s that is displayed when the user selects an item on * the <code>JMenuBar</code>. In addition to <code>JMenuItem</code>s, a * <code>JMenu</code> can also contain <code>JSeparator</code>s. * <p> * In essence, a menu is a button with an associated <code>JPopupMenu</code>. * When the "button" is pressed, the <code>JPopupMenu</code> appears. If the * "button" is on the <code>JMenuBar</code>, the menu is a top-level window. * If the "button" is another menu item, then the <code>JPopupMenu</code> is * "pull-right" menu. * * If the menu contains more items than displayable on the screen the menu * becomes scrollable by hiding some of the items and adding an add and a down * arrow at both ends of the menu to scroll the menu with this arrows. * * description: A popup window containing menu items displayed in a menu bar. * * @see JPopupMenu */ public class ScrollableMenu extends JMenu { private int maxItemsToDisplay = 1; private static boolean DOWN = true; private static boolean UP = false; static { // put a wrapper action between up and down selection action to scroll up or // down JPopupMenu dummy = new JPopupMenu(); BasicPopupMenuUI ui = (BasicPopupMenuUI) BasicPopupMenuUI.createUI(dummy); ui.installUI(dummy); // create action map ActionMap map = (ActionMap) UIManager.getLookAndFeelDefaults().get("PopupMenu.actionMap"); if (map != null) { Action downAction = map.get("selectNext"); Action upAction = map.get("selectPrevious"); map.put("selectNext", new SelectNextItemAction(DOWN, downAction)); map.put("selectPrevious", new SelectNextItemAction(UP, upAction)); } } private void setMaxItemToDisplay() { // set max items count visible on screen Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); maxItemsToDisplay = (dim.height / maxHeight) - 1; } private static class SelectNextItemAction extends AbstractAction { private boolean direction; private Action wrappedAction; SelectNextItemAction(boolean direction, Action wrappedAction) { this.direction = direction; this.wrappedAction = wrappedAction; } public void actionPerformed(ActionEvent e) { MenuSelectionManager msm = MenuSelectionManager.defaultManager(); MenuElement path[] = msm.getSelectedPath(); int len = path.length; if (len > 2 && path[len - 3] instanceof ScrollableMenu && path[len - 2] instanceof JPopupMenu) { ScrollableMenu menu = (ScrollableMenu) path[len - 3]; MenuElement selected = path[len - 1]; Component component = null; component = menu.getFirstVisibleAndEnabledComponent(); if (direction == UP && (component == null || selected == component)) { if (menu.scrollUp.enableScroll) { // scroll up do { menu.scrollUpClicked(); component = menu.getFirstVisibleComponent(); } while (component != null && (!(component instanceof MenuElement)) && (component instanceof JSeparator) && menu.scrollUp.enableScroll); if (!component.isEnabled() || (!(component instanceof MenuElement))) { return; } } else { // very first - scroll to end for (int index = 0; index < menu.getMenuComponentCount(); index++) { menu.scrollDownClicked(); } } } else if (direction == DOWN && (((component = menu.getLastVisibleAndEnabledComponent()) == null) || selected == component)) { if (menu.scrollDown.enableScroll) { // scroll down do { menu.scrollDownClicked(); component = menu.getLastVisibleComponent(); } while (component != null && (!(component instanceof MenuElement)) && (component instanceof JSeparator) && menu.scrollDown.enableScroll); if (!component.isEnabled() || (!(component instanceof MenuElement))) { return; } } else { // very last - scroll to begin for (int index = 0; index < menu.getMenuComponentCount(); index++) { menu.scrollUpClicked(); } } } } wrappedAction.actionPerformed(e); } } private ScrollUpOrDownButtonItem scrollUp = new ScrollUpOrDownButtonItem(UP); private ScrollUpOrDownButtonItem scrollDown = new ScrollUpOrDownButtonItem(DOWN); private JSeparator upSeperator = new JSeparator(); private JSeparator downSeperator = new JSeparator(); private Vector<Component> scrollableItems = new Vector<Component>(); private int beginIndex = 0; private int maxWidth = 10; private int maxHeight = 1; /** * Constructs a new <code>JMenu</code> with no text. */ public ScrollableMenu() { this(""); } /** * Constructs a new <code>JMenu</code> whose properties are taken from the * <code>Action</code> supplied. * * @param a an <code>Action</code> * * @since 1.3 */ public ScrollableMenu(Action a) { this(""); setAction(a); } /** * Constructs a new <code>JMenu</code> with the supplied string as its text * and specified as a tear-off menu or not. * * @param s the text for the menu label * @param b can the menu be torn off (not yet implemented) */ public ScrollableMenu(String s, boolean b) { this(s); } /** * Constructs a new <code>JMenu</code> with the supplied string as its text. * * @param menuTitle the text for the menu label */ public ScrollableMenu(String menuTitle) { super(menuTitle); super.add(scrollUp); super.add(upSeperator); super.add(downSeperator); super.add(scrollDown); getPopupMenu().addPopupMenuListener(new PopupMenuListener() { public void popupMenuCanceled(PopupMenuEvent e) {} public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} public void popupMenuWillBecomeVisible(PopupMenuEvent e) { getPopupMenu().setPreferredSize(new Dimension(maxWidth, getPopupMenu().getPreferredSize().height)); } }); } /** * Appends a menu item to the end of this menu. Returns the menu item added. * * @param menuItem the <code>JMenuitem</code> to be added * @return the <code>JMenuItem</code> added */ public JMenuItem add(JMenuItem menuItem) { addScrollableComponent(menuItem); return menuItem; } /** * Appends a component to the end of this menu. Returns the component added. * * @param component the <code>Component</code> to add * @return the <code>Component</code> added */ public Component add(Component component) { addScrollableComponent(component); return component; } /** * Adds the specified component to this container at the given position. If * <code>index</code> equals -1, the component will be appended to the end. * * @param component the <code>Component</code> to add * @param index the position at which to insert the component * @return the <code>Component</code> added * @see #remove(Component) * @see java.awt.Container#add(Component, int) */ public Component add(Component component, int index) { addScrollableComponent(component, index); return component; } public void insert(String s, int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } insert(new JMenuItem(s), pos); } /** * Inserts the specified <code>JMenuitem</code> at a given position. * * @param menuItem the <code>JMenuitem</code> to add * @param pos an integer specifying the position at which to add the new * <code>JMenuitem</code> * @return the new menu item * @exception IllegalArgumentException if the value of <code>pos</code> < 0 */ public JMenuItem insert(JMenuItem menuItem, int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } addScrollableComponent(menuItem, pos); return menuItem; } /** * Inserts a new menu item attached to the specified <code>Action</code> * object at a given position. * * @param a the <code>Action</code> object for the menu item to add * @param pos an integer specifying the position at which to add the new menu * item * @exception IllegalArgumentException if the value of <code>pos</code> < 0 */ public JMenuItem insert(Action a, int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } JMenuItem menuItem = new JMenuItem((String) a.getValue(Action.NAME), (Icon) a.getValue(Action.SMALL_ICON)); menuItem.setHorizontalTextPosition(JButton.TRAILING); menuItem.setVerticalTextPosition(JButton.CENTER); menuItem.setEnabled(a.isEnabled()); menuItem.setAction(a); insert(menuItem, pos); return menuItem; } /** * Returns the <code>JMenuItem</code> at the specified position. If the * component at <code>pos</code> is not a menu item, <code>null</code> is * returned. This method is included for AWT compatibility. * * @param pos an integer specifying the position * @exception IllegalArgumentException if the value of <code>pos</code> < 0 * @return the menu item at the specified position; or <code>null</code> if * the item as the specified position is not a menu item */ public JMenuItem getItem(int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } JMenuItem menuItem = null; Component component = getMenuComponent(pos); if (component instanceof JMenuItem) { menuItem = (JMenuItem) component; } return menuItem; } /** * Returns the number of items on the menu, including separators. This method * is included for AWT compatibility. * * @return an integer equal to the number of items on the menu * @see #getMenuComponentCount */ public int getItemCount() { return getMenuComponentCount(); } /** * Removes the specified menu item from this menu. If there is no popup menu, * this method will have no effect. * * @param menuItem the <code>JMenuItem</code> to be removed from the menu */ public void remove(JMenuItem menuItem) { removeScrollableComponent(menuItem); } /** * Removes the menu item at the specified index from this menu. * * @param pos the position of the item to be removed * @exception IllegalArgumentException if the value of <code>pos</code> < 0, * or if <code>pos</code> is greater than the number of menu * items */ public void remove(int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } if (pos > getItemCount()) { throw new IllegalArgumentException("index greater than the number of items."); } removeScrollableComponent(scrollableItems.elementAt(pos)); } /** * Removes the component <code>c</code> from this menu. * * @param component the component to be removed */ public void remove(Component component) { removeScrollableComponent(component); } /** * Removes all menu items from this menu. */ public void removeAll() { while (getMenuComponentCount() > 0) { remove(0); } maxWidth = 10; maxHeight = 0; } /** * Returns the number of components on the menu. * * @return an integer containing the number of components on the menu */ public int getMenuComponentCount() { return scrollableItems.size(); } /** * Returns the component at position <code>n</code>. * * @param n the position of the component to be returned * @return the component requested, or <code>null</code> if there is no * popup menu * */ public Component getMenuComponent(int n) { if (n >= 0 && n < scrollableItems.size()) { return scrollableItems.elementAt(n); } return null; } /** * Returns an array of <code>Component</code>s of the menu's subcomponents. * Note that this returns all <code>Component</code>s in the popup menu, * including separators. * * @return an array of <code>Component</code>s or an empty array if there * is no popup menu */ public Component[] getMenuComponents() { Component[] components = new Component[getMenuComponentCount()]; Iterator<Component> iterator = scrollableItems.iterator(); int index = 0; while (iterator.hasNext()) { components[index++] = iterator.next(); } return components; } /** * Returns true if the specified component exists in the submenu hierarchy. * * @param component the <code>Component</code> to be tested * @return true if the <code>Component</code> exists, false otherwise */ public boolean isMenuComponent(Component component) { return scrollableItems.contains(component); } /** * Appends a new separator to the end of the menu. */ public void addSeparator() { add(new JPopupMenu.Separator()); } /** * Add the specified component to this scrollable menu * * @param component the <code>Component</code> to add * @param pos an integer specifying the position at which to add the new * component */ protected void addScrollableComponent(Component component, int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } scrollableItems.insertElementAt(component, pos); setPreferedSizeForMenuItems(component); if (pos >= beginIndex && pos < beginIndex + maxItemsToDisplay) { super.add(component, pos - beginIndex + 2); } while(super.getMenuComponentCount() > maxItemsToDisplay + 4) { super.remove(super.getMenuComponentCount() - 3); } updateScrollingComponentsVisibility(); } /** * Add the specified component at the end of this scrollable menu * * @param component the <code>Component</code> to add */ protected void addScrollableComponent(Component component) { addScrollableComponent(component, scrollableItems.size()); } /** * Remove the specified component from this scrollable menu * * @param component the <code>Component</code> to remove */ protected void removeScrollableComponent(Component component) { scrollableItems.remove(component); super.remove(component); if (scrollableItems.size() > maxItemsToDisplay && super.getMenuComponentCount() - 4 < maxItemsToDisplay) { if (beginIndex + maxItemsToDisplay <= scrollableItems.size()) { int end = beginIndex + maxItemsToDisplay - 1; Component addComponent = scrollableItems.elementAt(end); super.add(addComponent, maxItemsToDisplay + 1); } else if (beginIndex > 0 && beginIndex <= scrollableItems.size()) { Component addComponent = scrollableItems.elementAt(--beginIndex); super.add(addComponent, 2); } } else if (beginIndex > 0 && beginIndex + maxItemsToDisplay > scrollableItems.size()) { beginIndex--; } updateScrollingComponentsVisibility(); } private Component getFirstVisibleAndEnabledComponent() { if (super.getMenuComponentCount() > 4) { for (int index = 2; index < super.getMenuComponentCount() - 2; index++) { Component component = super.getMenuComponent(index); if (component instanceof MenuElement && component.isEnabled()) return component; } } return null; } private Component getLastVisibleAndEnabledComponent() { if (super.getMenuComponentCount() > 4) { for (int index = super.getMenuComponentCount() - 3; index > 1; index--) { Component component = super.getMenuComponent(index); if (component instanceof MenuElement && component.isEnabled()) return component; } } return null; } private Component getFirstVisibleComponent() { if (super.getMenuComponentCount() > 4) { return super.getMenuComponent(2); } return null; } private Component getLastVisibleComponent() { if (super.getMenuComponentCount() > 4) { return super.getMenuComponent(super.getMenuComponentCount() - 3); } return null; } private void updateScrollingComponentsVisibility() { boolean visible = scrollableItems.size() > maxItemsToDisplay; scrollDown.setVisible(visible); scrollUp.setVisible(visible); upSeperator.setVisible(visible); downSeperator.setVisible(visible); if (visible) { scrollUp.enableScroll(beginIndex > 0); scrollDown.enableScroll(beginIndex + maxItemsToDisplay < scrollableItems.size()); } getPopupMenu().validate(); getPopupMenu().repaint(); } private void setPreferedSizeForMenuItems(Component component) { if (component instanceof JComponent && !(component instanceof JPopupMenu.Separator)) { JComponent jcomp = (JComponent) component; int width = jcomp.getPreferredSize().width; int height = jcomp.getPreferredSize().height; if (jcomp.getBorder() != null) { Insets insets = jcomp.getBorder().getBorderInsets(component); width += insets.left + insets.right; } if (width > maxWidth || height > maxHeight) { if (width > maxWidth) maxWidth = width; if (height > maxHeight) { maxHeight = height; setMaxItemToDisplay(); } Iterator<Component> iterator = scrollableItems.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); if (object instanceof JComponent && !(object instanceof JPopupMenu.Separator)) { JComponent jComponent = (JComponent) object; jComponent.setPreferredSize(new Dimension(maxWidth, maxHeight)); } } } else jcomp.setPreferredSize(new Dimension(maxWidth, maxHeight)); } } private void scrollUpClicked() { if (scrollableItems.size() <= maxItemsToDisplay || beginIndex == 0) { // no // need // to // scroll return; } super.remove(maxItemsToDisplay + 1); super.add(scrollableItems.elementAt(--beginIndex), 2); updateScrollingComponentsVisibility(); if (getLastVisibleComponent() instanceof JSeparator) { scrollUpClicked(); } } private void scrollDownClicked() { if (scrollableItems.size() <= maxItemsToDisplay || beginIndex + maxItemsToDisplay == scrollableItems.size()) { // no // need // to // scroll return; } super.remove(2); super.add(scrollableItems.elementAt(beginIndex + maxItemsToDisplay), maxItemsToDisplay + 1); beginIndex++; updateScrollingComponentsVisibility(); if (getFirstVisibleComponent() instanceof JSeparator) { scrollDownClicked(); } } private class ScrollUpOrDownButtonItem extends JPanel { private boolean direction = UP; private Polygon arrow = null; private boolean isMouseOver = false; private boolean enableScroll = false; private MyMouseListener mouseListener; private MyActionListener actionListener; private int initialDelay = 300; private int repeatDelay = 50; private Timer timer = null; public ScrollUpOrDownButtonItem(boolean direction) { // direction can be UP // or DOWN this.direction = direction; setVisible(false); setPreferredSize(new Dimension(10, 10)); setSize(new Dimension(10, 10)); setMinimumSize(new Dimension(10, 10)); mouseListener = new MyMouseListener(); addMouseListener(mouseListener); actionListener = new MyActionListener(); timer = new Timer(repeatDelay, actionListener); timer.setInitialDelay(initialDelay); } public void enableScroll(boolean enableScroll) { this.enableScroll = enableScroll; repaint(); } public void paintComponent(Graphics g) { Color oldColor = g.getColor(); g.setColor(ScrollableMenu.this.getBackground()); Rectangle rect = g.getClipBounds(); g.fillRect(rect.x, rect.y, rect.width, rect.height); if (isMouseOver && enableScroll) { g.setColor(Color.blue); } else if (!enableScroll) { g.setColor(Color.gray); } else { g.setColor(ScrollableMenu.this.getForeground()); } g.fillPolygon(getArrow()); g.setColor(oldColor); } private Polygon getArrow() { if (arrow == null) { arrow = new Polygon(); if (direction == UP) { arrow.addPoint((int) (getSize().width / 2.0 - 6.0 + 0.5), (int) (getSize().height / 2.0 + 3.0 + 0.5)); arrow.addPoint((int) (getSize().width / 2.0 + 6.0 + 0.5), (int) (getSize().height / 2.0 + 3.0 + 0.5)); arrow.addPoint((int) (getSize().width / 2.0 + 0.5), (int) (getSize().height / 2.0 - 4.0 + 0.5)); } else { arrow.addPoint((int) (getSize().width / 2.0 - 6.0 + 0.5), (int) (getSize().height / 2.0 - 3.0 + 0.5)); arrow.addPoint((int) (getSize().width / 2.0 + 6.0 + 0.5), (int) (getSize().height / 2.0 - 3.0 + 0.5)); arrow.addPoint((int) (getSize().width / 2.0 + 0.5), (int) (getSize().height / 2.0 + 4.0 + 0.5)); } } return arrow; } private void scroll() { if (direction == UP) { scrollUpClicked(); } else { scrollDownClicked(); } } private void startScrollTimer() { if (enableScroll) { timer.start(); } else { timer.stop(); } } /** * action for timer */ private class MyActionListener implements ActionListener { public void actionPerformed(ActionEvent actionevent) { scroll(); } } private class MyMouseListener extends MouseAdapter { public void mouseClicked(MouseEvent me) { scroll(); } public void mouseEntered(MouseEvent me) { isMouseOver = true; repaint(); startScrollTimer(); } public void mouseExited(MouseEvent me) { isMouseOver = false; timer.stop(); repaint(); } public void mousePressed(MouseEvent mouseEvent) { startScrollTimer(); } public void mouseReleased(MouseEvent mouseevent) { timer.stop(); } } } }

The table below shows all metrics for ScrollableMenu.java.

MetricValueDescription
BLOCKS109.00Number of blocks
BLOCK_COMMENT 0.00Number of block comment lines
COMMENTS203.00Comment lines
COMMENT_DENSITY 0.56Comment density
COMPARISONS59.00Number of comparison operators
CYCLOMATIC130.00Cyclomatic complexity
DECL_COMMENTS35.00Comments in declarations
DOC_COMMENT180.00Number of javadoc comment lines
ELOC364.00Effective lines of code
EXEC_COMMENTS 9.00Comments in executable code
EXITS77.00Procedure exits
FUNCTIONS50.00Number of function declarations
HALSTEAD_DIFFICULTY90.36Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY107.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 0.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
JAVA0034 4.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 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 1.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 1.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 1.00JAVA0075 Method parameter hides field
JAVA007624.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 2.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 1.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 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.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 2.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 1.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 2.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
JAVA0145 0.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 1.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 0.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 3.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 1.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 2.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 2.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
LINES799.00Number of lines in the source file
LINE_COMMENT23.00Number of line comments
LOC462.00Lines of code
LOGICAL_LINES249.00Number of statements
LOOPS10.00Number of loops
NEST_DEPTH 5.00Maximum nesting depth
OPERANDS1056.00Number of operands
OPERATORS2183.00Number of operators
PARAMS40.00Number of formal parameter declarations
PROGRAM_LENGTH3239.00Halstead program length
PROGRAM_VOCAB349.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS67.00Number of return points from functions
SIZE24331.00Size of the file in bytes
UNIQUE_OPERANDS298.00Number of unique operands
UNIQUE_OPERATORS51.00Number of unique operators
WHITESPACE134.00Number of whitespace lines