ConstrainedProperty.java

Index Score
org.codehaus.groovy.grails.validation
Grails

View: Reasons, Metrics, Source Code

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

MetricDescription
DECL_COMMENTSComments in declarations
SIZESize of the file in bytes
CYCLOMATICCyclomatic complexity
JAVA0144JAVA0144 Line exceeds maximum M characters
OPERATORSNumber of operators
BLOCKSNumber of blocks
PROGRAM_LENGTHHalstead program length
LOGICAL_LINESNumber of statements
JAVA0034JAVA0034 Missing braces in if statement
RETURNSNumber of return points from functions
OPERANDSNumber of operands
COMPARISONSNumber of comparison operators
ELOCEffective lines of code
LOCLines of code
FUNCTIONSNumber of function declarations
LINESNumber of lines in the source file
INTERFACE_COMPLEXITYInterface complexity
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
JAVA0116JAVA0116 Missing javadoc: field 'field'
DOC_COMMENTNumber of javadoc comment lines
JAVA0117JAVA0117 Missing javadoc: method 'method'
COMMENTSComment lines
PARAMSNumber of formal parameter declarations
EXITSProcedure exits
WHITESPACENumber of whitespace lines
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0166JAVA0166 Generic exception caught
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
EXEC_COMMENTSComments in executable code
UNIQUE_OPERATORSNumber of unique operators
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
LINE_COMMENTNumber of line comments
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0130JAVA0130 Non-static method does not use instance fields
LOOPSNumber of loops
JAVA0145JAVA0145 Tab character used in source file
/* Copyright 2004-2005 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.codehaus.groovy.grails.validation; import groovy.lang.MissingPropertyException; import groovy.lang.Range; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.codehaus.groovy.grails.validation.exceptions.ConstraintException; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import org.springframework.context.MessageSource; import org.springframework.validation.Errors; import java.util.*; /** * Provides the ability to set contraints against a properties of a class. Constraints can either be * set via the property setters or via the <pre>applyConstraint(String constraintName, Object constrainingValue)</pre> * in combination with a constraint constant. Example: * * <code> * ... * * ConstrainedProperty cp = new ConstrainedProperty(owningClass, propertyName, propertyType); * if(cp.supportsConstraint( ConstrainedProperty.EMAIL_CONSTRAINT ) ) { * cp.applyConstraint( ConstrainedProperty.EMAIL_CONSTRAINT, new Boolean(true) ); * } * </code> * * Alternatively constraints can be applied directly using the java bean getters/setters if a static (as oposed to dynamic) * approach to constraint creation is possible: * * <code> * cp.setEmail(true) * </code> * @author Graeme Rocher * @since 07-Nov-2005 */ public class ConstrainedProperty { static final String DEFAULT_NULL_MESSAGE_CODE = "default.null.message"; static final String DEFAULT_INVALID_MIN_SIZE_MESSAGE_CODE = "default.invalid.min.size.message"; static final String DEFAULT_INVALID_MAX_SIZE_MESSAGE_CODE = "default.invalid.max.size.message"; static final String DEFAULT_NOT_EQUAL_MESSAGE_CODE = "default.not.equal.message"; static final String DEFAULT_INVALID_MIN_MESSAGE_CODE = "default.invalid.min.message"; static final String DEFAULT_INVALID_MAX_MESSAGE_CODE = "default.invalid.max.message"; static final String DEFAULT_INVALID_SIZE_MESSAGE_CODE = "default.invalid.size.message"; static final String DEFAULT_NOT_INLIST_MESSAGE_CODE = "default.not.inlist.message"; static final String DEFAULT_INVALID_RANGE_MESSAGE_CODE = "default.invalid.range.message"; static final String DEFAULT_INVALID_EMAIL_MESSAGE_CODE = "default.invalid.email.message"; static final String DEFAULT_INVALID_CREDIT_CARD_MESSAGE_CODE = "default.invalid.creditCard.message"; static final String DEFAULT_INVALID_URL_MESSAGE_CODE = "default.invalid.url.message"; static final String DEFAULT_INVALID_VALIDATOR_MESSAGE_CODE = "default.invalid.validator.message"; static final String DEFAULT_DOESNT_MATCH_MESSAGE_CODE = "default.doesnt.match.message"; static final String DEFAULT_BLANK_MESSAGE_CODE = "default.blank.message"; protected static final ResourceBundle bundle = ResourceBundle.getBundle( "org.codehaus.groovy.grails.validation.DefaultErrorMessages" ); private static final String DEFAULT_BLANK_MESSAGE = bundle.getString( DEFAULT_BLANK_MESSAGE_CODE ); private static final String DEFAULT_DOESNT_MATCH_MESSAGE = bundle.getString( DEFAULT_DOESNT_MATCH_MESSAGE_CODE ); private static final String DEFAULT_INVALID_URL_MESSAGE = bundle.getString( DEFAULT_INVALID_URL_MESSAGE_CODE ); private static final String DEFAULT_INVALID_CREDIT_CARD_MESSAGE = bundle.getString( DEFAULT_INVALID_CREDIT_CARD_MESSAGE_CODE ); private static final String DEFAULT_INVALID_EMAIL_MESSAGE = bundle.getString( DEFAULT_INVALID_EMAIL_MESSAGE_CODE ); private static final String DEFAULT_INVALID_RANGE_MESSAGE = bundle.getString( DEFAULT_INVALID_RANGE_MESSAGE_CODE ); private static final String DEFAULT_NOT_IN_LIST_MESSAGE = bundle.getString( DEFAULT_NOT_INLIST_MESSAGE_CODE ); private static final String DEFAULT_INVALID_SIZE_MESSAGE = bundle.getString( DEFAULT_INVALID_SIZE_MESSAGE_CODE ); private static final String DEFAULT_INVALID_MAX_MESSAGE = bundle.getString( DEFAULT_INVALID_MAX_MESSAGE_CODE ); private static final String DEFAULT_INVALID_MIN_MESSAGE = bundle.getString( DEFAULT_INVALID_MIN_MESSAGE_CODE ); private static final String DEFAULT_NOT_EQUAL_MESSAGE = bundle.getString( DEFAULT_NOT_EQUAL_MESSAGE_CODE ); private static final String DEFAULT_INVALID_MAX_SIZE_MESSAGE = bundle.getString( DEFAULT_INVALID_MAX_SIZE_MESSAGE_CODE ); private static final String DEFAULT_INVALID_MIN_SIZE_MESSAGE = bundle.getString( DEFAULT_INVALID_MIN_SIZE_MESSAGE_CODE ); private static final String DEFAULT_NULL_MESSAGE = bundle.getString( DEFAULT_NULL_MESSAGE_CODE ); private static final String DEFAULT_INVALID_VALIDATOR_MESSAGE = bundle.getString( DEFAULT_INVALID_VALIDATOR_MESSAGE_CODE ); public static final String CREDIT_CARD_CONSTRAINT = "creditCard"; public static final String EMAIL_CONSTRAINT = "email"; public static final String BLANK_CONSTRAINT = "blank"; public static final String RANGE_CONSTRAINT = "range"; public static final String IN_LIST_CONSTRAINT = "inList"; public static final String URL_CONSTRAINT = "url"; public static final String MATCHES_CONSTRAINT = "matches"; public static final String SIZE_CONSTRAINT = "size"; public static final String MIN_CONSTRAINT = "min"; public static final String MAX_CONSTRAINT = "max"; public static final String MAX_SIZE_CONSTRAINT = "maxSize"; public static final String MIN_SIZE_CONSTRAINT = "minSize"; public static final String SCALE_CONSTRAINT = "scale"; public static final String NOT_EQUAL_CONSTRAINT = "notEqual"; public static final String NULLABLE_CONSTRAINT = "nullable"; public static final String VALIDATOR_CONSTRAINT = "validator"; protected static final String INVALID_SUFFIX = ".invalid"; protected static final String EXCEEDED_SUFFIX = ".exceeded"; protected static final String NOTMET_SUFFIX = ".notmet"; protected static final String NOT_PREFIX = "not."; protected static final String TOOBIG_SUFFIX = ".toobig"; protected static final String TOOLONG_SUFFIX = ".toolong"; protected static final String TOOSMALL_SUFFIX = ".toosmall"; protected static final String TOOSHORT_SUFFIX = ".tooshort"; protected static Map constraints = new HashMap(); protected static final Map DEFAULT_MESSAGES = new HashMap(); static { DEFAULT_MESSAGES.put(DEFAULT_BLANK_MESSAGE_CODE,DEFAULT_BLANK_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_DOESNT_MATCH_MESSAGE_CODE,DEFAULT_DOESNT_MATCH_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_CREDIT_CARD_MESSAGE_CODE,DEFAULT_INVALID_CREDIT_CARD_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_EMAIL_MESSAGE_CODE,DEFAULT_INVALID_EMAIL_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_MAX_MESSAGE_CODE,DEFAULT_INVALID_MAX_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_MAX_SIZE_MESSAGE_CODE,DEFAULT_INVALID_MAX_SIZE_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_MIN_MESSAGE_CODE,DEFAULT_INVALID_MIN_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_MIN_SIZE_MESSAGE_CODE,DEFAULT_INVALID_MIN_SIZE_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_RANGE_MESSAGE_CODE,DEFAULT_INVALID_RANGE_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_SIZE_MESSAGE_CODE,DEFAULT_INVALID_SIZE_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_URL_MESSAGE_CODE,DEFAULT_INVALID_URL_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_NOT_EQUAL_MESSAGE_CODE,DEFAULT_NOT_EQUAL_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_NOT_INLIST_MESSAGE_CODE,DEFAULT_NOT_IN_LIST_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_NULL_MESSAGE_CODE,DEFAULT_NULL_MESSAGE); DEFAULT_MESSAGES.put(DEFAULT_INVALID_VALIDATOR_MESSAGE_CODE, DEFAULT_INVALID_VALIDATOR_MESSAGE ); constraints.put( CREDIT_CARD_CONSTRAINT, CreditCardConstraint.class ); constraints.put( EMAIL_CONSTRAINT, EmailConstraint.class ); constraints.put( BLANK_CONSTRAINT, BlankConstraint.class ); constraints.put( RANGE_CONSTRAINT, RangeConstraint.class ); constraints.put( IN_LIST_CONSTRAINT, InListConstraint.class ); constraints.put( URL_CONSTRAINT, UrlConstraint.class ); constraints.put( SIZE_CONSTRAINT, SizeConstraint.class ); constraints.put( MATCHES_CONSTRAINT, MatchesConstraint.class ); constraints.put( MIN_CONSTRAINT, MinConstraint.class ); constraints.put( MAX_CONSTRAINT, MaxConstraint.class ); constraints.put( MAX_SIZE_CONSTRAINT, MaxSizeConstraint.class ); constraints.put( MIN_SIZE_CONSTRAINT, MinSizeConstraint.class ); constraints.put( SCALE_CONSTRAINT, ScaleConstraint.class ); constraints.put( NULLABLE_CONSTRAINT, NullableConstraint.class ); constraints.put( NOT_EQUAL_CONSTRAINT, NotEqualConstraint.class ); constraints.put( VALIDATOR_CONSTRAINT, ValidatorConstraint.class ); } protected static final Log LOG = LogFactory.getLog(ConstrainedProperty.class); // move these to subclass protected String propertyName; protected Class propertyType; protected Map appliedConstraints = new LinkedHashMap(); protected Class owningClass; private BeanWrapper bean; // simple constraints private boolean display = true; // whether the property should be displayed private boolean editable = true; // whether the property is editable //private boolean file; // whether the property is a file private int order; // what order to property appears in private String format; // the format of the property (for example a date pattern) private String widget; // the widget to use to render the property private boolean password; // whether the property is a password private Map attributes = Collections.EMPTY_MAP; // a map of attributes of property protected MessageSource messageSource; private Map metaConstraints = new HashMap(); /** * Constructs a new ConstrainedProperty for the given arguments * * @param clazz The owning class * @param propertyName The name of the property * @param propertyType The property type */ public ConstrainedProperty(Class clazz,String propertyName, Class propertyType) { super(); this.owningClass = clazz; this.propertyName = propertyName; this.propertyType = propertyType; this.bean = new BeanWrapperImpl(this); } public static void registerNewConstraint(String name, Class constraintClass) { if(StringUtils.isBlank(name)) throw new IllegalArgumentException("Argument [name] cannot be null"); if(constraintClass == null || !Constraint.class.isAssignableFrom(constraintClass)) throw new IllegalArgumentException("Argument [constraintClass] with value ["+constraintClass+"] is not a valid constraint"); constraints.put(name, constraintClass); } public static void registerNewConstraint(String name, ConstraintFactory factory) { if(StringUtils.isBlank(name)) throw new IllegalArgumentException("Argument [name] cannot be null"); if(factory == null) throw new IllegalArgumentException("Argument [constraintClass] with value ["+factory+"] is not a valid constraint"); constraints.put(name, factory); } public static boolean hasRegisteredConstraint( String constraintName ) { return constraints.containsKey( constraintName ); } /** * @return Returns the appliedConstraints. */ public Collection getAppliedConstraints() { return appliedConstraints.values(); } /** * Obtains an applied constraint by name * @param name The name of the constraint * @return The applied constraint */ public Constraint getAppliedConstraint(String name) { return (Constraint)appliedConstraints.get(name); } /** * @return Returns true if the specified constraint name is being applied to this property * @param constraintName The name of the constraint to check */ public boolean hasAppliedConstraint(String constraintName) { return appliedConstraints.containsKey(constraintName); } /** * @return Returns the propertyType. */ public Class getPropertyType() { return propertyType; } /** * @return Returns the max. */ public Comparable getMax() { Comparable maxValue = null; MaxConstraint maxConstraint = (MaxConstraint)this.appliedConstraints.get(MAX_CONSTRAINT); RangeConstraint rangeConstraint = (RangeConstraint)this.appliedConstraints.get(RANGE_CONSTRAINT); if ((maxConstraint != null) || (rangeConstraint != null)) { Comparable maxConstraintValue = maxConstraint != null ? maxConstraint.getMaxValue() : null; Comparable rangeConstraintHighValue = rangeConstraint != null ? rangeConstraint.getRange().getTo() : null; if ((maxConstraintValue != null) && (rangeConstraintHighValue != null)) { maxValue = (maxConstraintValue.compareTo(rangeConstraintHighValue) < 0) ? maxConstraintValue : rangeConstraintHighValue; } else if ((maxConstraintValue == null) && (rangeConstraintHighValue != null)) { maxValue = rangeConstraintHighValue; } else if ((maxConstraintValue != null) && (rangeConstraintHighValue == null)) { maxValue = maxConstraintValue; } } return maxValue; } /** * @param max The max to set. */ public void setMax(Comparable max) { if(max == null) { this.appliedConstraints.remove( MAX_CONSTRAINT ); return; } if(!propertyType.equals( max.getClass() )) { throw new MissingPropertyException(MAX_CONSTRAINT,propertyType); } Range r = getRange(); if(r != null) { LOG.warn("Range constraint already set ignoring constraint ["+MAX_CONSTRAINT+"] for value ["+max+"]"); return; } Constraint c = (MaxConstraint)this.appliedConstraints.get( MAX_CONSTRAINT ); if(c != null) { c.setParameter(max); } else { c = new MaxConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(max); this.appliedConstraints.put( MAX_CONSTRAINT, c ); } } /** * @return Returns the min. */ public Comparable getMin() { Comparable minValue = null; MinConstraint minConstraint = (MinConstraint)this.appliedConstraints.get(MIN_CONSTRAINT); RangeConstraint rangeConstraint = (RangeConstraint)this.appliedConstraints.get(RANGE_CONSTRAINT); if ((minConstraint != null) || (rangeConstraint != null)) { Comparable minConstraintValue = minConstraint != null ? minConstraint.getMinValue() : null; Comparable rangeConstraintLowValue = rangeConstraint != null ? rangeConstraint.getRange().getFrom() : null; if ((minConstraintValue != null) && (rangeConstraintLowValue != null)) { minValue = (minConstraintValue.compareTo(rangeConstraintLowValue) > 0) ? minConstraintValue : rangeConstraintLowValue; } else if ((minConstraintValue == null) && (rangeConstraintLowValue != null)) { minValue = rangeConstraintLowValue; } else if ((minConstraintValue != null) && (rangeConstraintLowValue == null)) { minValue = minConstraintValue; } } return minValue; } /** * @param min The min to set. */ public void setMin(Comparable min) { if(min == null) { this.appliedConstraints.remove( MIN_CONSTRAINT ); return; } if(!propertyType.equals( min.getClass() )) { throw new MissingPropertyException(MIN_CONSTRAINT,propertyType); } Range r = getRange(); if(r != null) { LOG.warn("Range constraint already set ignoring constraint ["+MIN_CONSTRAINT+"] for value ["+min+"]"); return; } Constraint c = (MinConstraint)this.appliedConstraints.get( MIN_CONSTRAINT ); if(c != null) { c.setParameter(min); } else { c = new MinConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(min); this.appliedConstraints.put( MIN_CONSTRAINT, c ); } } /** * @return Returns the inList. */ public List getInList() { InListConstraint c = (InListConstraint)this.appliedConstraints.get( IN_LIST_CONSTRAINT ); if(c == null) return null; return c.getList(); } /** * @param inList The inList to set. */ public void setInList(List inList) { Constraint c = (Constraint)this.appliedConstraints.get( IN_LIST_CONSTRAINT ); if(inList == null) { this.appliedConstraints.remove( IN_LIST_CONSTRAINT ); } else { if(c != null) { c.setParameter(inList); } else { c = new InListConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(inList); this.appliedConstraints.put( IN_LIST_CONSTRAINT, c ); } } } /** * @return Returns the range. */ public Range getRange() { RangeConstraint c = (RangeConstraint)this.appliedConstraints.get( RANGE_CONSTRAINT ); if(c == null) return null; return c.getRange(); } /** * @param range The range to set. */ public void setRange(Range range) { if(this.appliedConstraints.containsKey( MAX_CONSTRAINT )) { LOG.warn("Setting range constraint on property ["+propertyName+"] of class ["+owningClass+"] forced removal of max constraint"); this.appliedConstraints.remove( MAX_CONSTRAINT ); } if(this.appliedConstraints.containsKey( MIN_CONSTRAINT )) { LOG.warn("Setting range constraint on property ["+propertyName+"] of class ["+owningClass+"] forced removal of min constraint"); this.appliedConstraints.remove( MIN_CONSTRAINT ); } if(range == null) { this.appliedConstraints.remove( RANGE_CONSTRAINT ); } else { Constraint c = (Constraint)this.appliedConstraints.get(RANGE_CONSTRAINT); if(c != null) { c.setParameter(range); } else { c = new RangeConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(range); this.appliedConstraints.put( RANGE_CONSTRAINT,c); } } } /** * @return The scale, if defined for this property; null, otherwise */ public Integer getScale() { Integer scale = null; ScaleConstraint scaleConstraint = (ScaleConstraint)this.appliedConstraints.get(SCALE_CONSTRAINT); if (scaleConstraint != null) { scale = new Integer(scaleConstraint.getScale()); } return scale; } /** * @return Returns the size. */ public Range getSize() { SizeConstraint c = (SizeConstraint)this.appliedConstraints.get( SIZE_CONSTRAINT ); if(c == null) return null; return c.getRange(); } /** * @param size The size to set. */ public void setSize(Range size) { Constraint c = (Constraint)this.appliedConstraints.get( SIZE_CONSTRAINT ); if(size == null) { this.appliedConstraints.remove( SIZE_CONSTRAINT ); } else { if(c != null) { c.setParameter(size); } else { c = new SizeConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(size); this.appliedConstraints.put( SIZE_CONSTRAINT, c ); } } } /** * @return Returns the blank. */ public boolean isBlank() { Object cons = this.appliedConstraints.get(BLANK_CONSTRAINT); return cons == null || ((Boolean) ((BlankConstraint) cons).getParameter()).booleanValue(); } /** * @param blank The blank to set. */ public void setBlank(boolean blank) { if(!String.class.isInstance( propertyType )) { throw new MissingPropertyException("Blank constraint can only be applied to a String property",BLANK_CONSTRAINT,owningClass); } if(!blank) { this.appliedConstraints.remove(BLANK_CONSTRAINT); } else { Constraint c = (Constraint)this.appliedConstraints.get( BLANK_CONSTRAINT ); if(c != null) { c.setParameter(Boolean.valueOf(blank) ); } else { c = new BlankConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(Boolean.valueOf(blank)); this.appliedConstraints.put( BLANK_CONSTRAINT,c ); } } } /** * @return Returns the email. */ public boolean isEmail() { if(!String.class.isInstance( propertyType )) { throw new MissingPropertyException("Email constraint only applies to a String property",EMAIL_CONSTRAINT,owningClass); } return this.appliedConstraints.containsKey( EMAIL_CONSTRAINT ); } /** * @param email The email to set. */ public void setEmail(boolean email) { if(!String.class.isInstance( propertyType )) { throw new MissingPropertyException("Email constraint can only be applied to a String property",EMAIL_CONSTRAINT,owningClass); } Constraint c = (Constraint)this.appliedConstraints.get( EMAIL_CONSTRAINT ); if(email) { if(c != null) { c.setParameter(Boolean.valueOf(email) ); } else { c = new EmailConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(Boolean.valueOf(email)); this.appliedConstraints.put( EMAIL_CONSTRAINT,c ); } } else { if(c != null) { this.appliedConstraints.remove( EMAIL_CONSTRAINT ); } } } /** * @return Returns the creditCard. */ public boolean isCreditCard() { if(!String.class.isInstance( propertyType )) { throw new MissingPropertyException("CreditCard constraint only applies to a String property",CREDIT_CARD_CONSTRAINT,owningClass); } return this.appliedConstraints.containsKey( CREDIT_CARD_CONSTRAINT ); } /** * @param creditCard The creditCard to set. */ public void setCreditCard(boolean creditCard) { if(!String.class.isInstance( propertyType )) { throw new MissingPropertyException("CreditCard constraint only applies to a String property",CREDIT_CARD_CONSTRAINT,owningClass); } Constraint c = (Constraint)this.appliedConstraints.get( CREDIT_CARD_CONSTRAINT ); if(creditCard) { if(c != null) { c.setParameter(Boolean.valueOf(creditCard) ); } else { c = new CreditCardConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(Boolean.valueOf(creditCard)); this.appliedConstraints.put( CREDIT_CARD_CONSTRAINT,c ); } } else { if(c != null) { this.appliedConstraints.remove( CREDIT_CARD_CONSTRAINT ); } } } /** * @return Returns the matches. */ public String getMatches() { if(!String.class.isInstance( propertyType )) { throw new MissingPropertyException("Matches constraint only applies to a String property",MATCHES_CONSTRAINT,owningClass); } MatchesConstraint c = (MatchesConstraint)this.appliedConstraints.get( MATCHES_CONSTRAINT ); if(c == null) return null; return c.getRegex(); } /** * @param regex The matches to set. */ public void setMatches(String regex) { if(!String.class.isInstance( regex )) { throw new MissingPropertyException("Matches constraint can only be applied to a String property",MATCHES_CONSTRAINT,owningClass); } Constraint c = (Constraint)this.appliedConstraints.get( MATCHES_CONSTRAINT ); if(regex == null) { this.appliedConstraints.remove( MATCHES_CONSTRAINT ); } else { if(c != null) { c.setParameter( regex ); } else { c = new MatchesConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(regex); this.appliedConstraints.put( MATCHES_CONSTRAINT,c ); } } } /** * @return Returns the notEqual. */ public Object getNotEqual() { NotEqualConstraint c = (NotEqualConstraint)this.appliedConstraints.get( NOT_EQUAL_CONSTRAINT ); if(c == null) return null; return c.getNotEqualTo(); } /** * @return Returns the maxSize. */ public Integer getMaxSize() { Integer maxSize = null; MaxSizeConstraint maxSizeConstraint = ( MaxSizeConstraint )this.appliedConstraints.get(MAX_SIZE_CONSTRAINT); SizeConstraint sizeConstraint = (SizeConstraint)this.appliedConstraints.get(SIZE_CONSTRAINT); if ((maxSizeConstraint != null) || (sizeConstraint != null)) { int maxSizeConstraintValue = maxSizeConstraint != null ? maxSizeConstraint.getMaxSize() : Integer.MAX_VALUE; int sizeConstraintHighValue = sizeConstraint != null ? sizeConstraint.getRange().getToInt() : Integer.MAX_VALUE; maxSize = new Integer(Math.min(maxSizeConstraintValue, sizeConstraintHighValue)); } return maxSize; } /** * @param maxSize The maxSize to set. */ public void setMaxSize(Integer maxSize) { Constraint c = ( MaxSizeConstraint )this.appliedConstraints.get( MAX_SIZE_CONSTRAINT ); if( c != null) { c.setParameter(maxSize); } else { c = new MaxSizeConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(maxSize); this.appliedConstraints.put( MAX_SIZE_CONSTRAINT,c ); } } /** * @return Returns the minSize. */ public Integer getMinSize() { Integer minSize = null; MinSizeConstraint minSizeConstraint = (MinSizeConstraint)this.appliedConstraints.get(MIN_SIZE_CONSTRAINT); SizeConstraint sizeConstraint = (SizeConstraint)this.appliedConstraints.get(SIZE_CONSTRAINT); if ((minSizeConstraint != null) || (sizeConstraint != null)) { int minSizeConstraintValue = minSizeConstraint != null ? minSizeConstraint.getMinSize() : Integer.MIN_VALUE; int sizeConstraintLowValue = sizeConstraint != null ? sizeConstraint.getRange().getFromInt() : Integer.MIN_VALUE; minSize = new Integer(Math.max(minSizeConstraintValue, sizeConstraintLowValue)); } return minSize; } /** * @param minSize The minLength to set. */ public void setMinSize(Integer minSize) { Constraint c = (MinSizeConstraint)this.appliedConstraints.get( MIN_SIZE_CONSTRAINT ); if( c != null) { c.setParameter(minSize); } else { c = new MinSizeConstraint(); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter(minSize); this.appliedConstraints.put( MIN_SIZE_CONSTRAINT,c ); } } /** * @param notEqual The notEqual to set. */ public void setNotEqual(Object notEqual) { if(notEqual == null) { this.appliedConstraints.remove( NOT_EQUAL_CONSTRAINT ); } else { Constraint c = new NotEqualConstraint(); c.setOwningClass(owningClass); c.setPropertyName(propertyName); c.setParameter(notEqual); this.appliedConstraints.put( NOT_EQUAL_CONSTRAINT, c ); } } /** * @return Returns the nullable. */ public boolean isNullable() { if(this.appliedConstraints.containsKey(NULLABLE_CONSTRAINT)) { NullableConstraint nc = (NullableConstraint)this.appliedConstraints.get(NULLABLE_CONSTRAINT); return nc.isNullable(); } else { return false; } } /** * @param nullable The nullable to set. */ public void setNullable(boolean nullable) { NullableConstraint nc = (NullableConstraint)this.appliedConstraints.get(NULLABLE_CONSTRAINT); if(nc == null) { nc = new NullableConstraint(); nc.setOwningClass(owningClass); nc.setPropertyName(propertyName); this.appliedConstraints.put( NULLABLE_CONSTRAINT, nc ); } nc.setParameter(Boolean.valueOf(nullable)); } /** * @return Returns the propertyName. */ public String getPropertyName() { return propertyName; } /** * @param propertyName The propertyName to set. */ public void setPropertyName(String propertyName) { this.propertyName = propertyName; } /** * @return Returns the url. */ public boolean isUrl() { if(!String.class.isInstance( propertyType )) { throw new MissingPropertyException("URL constraint can only be applied to a String property",URL_CONSTRAINT,owningClass); } return this.appliedConstraints.containsKey( URL_CONSTRAINT ); } /** * @param url The url to set. */ public void setUrl(boolean url) { if(!String.class.isInstance( propertyType )) { throw new MissingPropertyException("URL constraint can only be applied to a String property",URL_CONSTRAINT,owningClass); } Constraint c = (Constraint)this.appliedConstraints.get( URL_CONSTRAINT ); if(url) { if(c != null) { c.setParameter(Boolean.valueOf(url)); } else { c = new UrlConstraint(); c.setOwningClass(owningClass); c.setPropertyName(propertyName); c.setParameter(Boolean.valueOf(url)); this.appliedConstraints.put( URL_CONSTRAINT, c ); } } else { if(c != null) { this.appliedConstraints.remove( URL_CONSTRAINT ); } } } /** * @return Returns the display. */ public boolean isDisplay() { return display; } /** * @param display The display to set. */ public void setDisplay(boolean display) { this.display = display; } /** * @return Returns the editable. */ public boolean isEditable() { return editable; } /** * @param editable The editable to set. */ public void setEditable(boolean editable) { this.editable = editable; } /** * @return Returns the order. */ public int getOrder() { return order; } /** * @param order The order to set. */ public void setOrder(int order) { this.order = order; } public String getFormat() { return format; } public void setFormat(String format) { this.format = format; } public boolean isPassword() { return password; } public void setPassword(boolean password) { this.password = password; } public Map getAttributes() { return attributes; } public void setAttributes(Map attributes) { this.attributes = attributes; } public String getWidget() { return widget; } public void setWidget(String widget) { this.widget = widget; } /** * The message source used to evaluate error messages * @param source The MessageSource instance to use to resolve messages */ public void setMessageSource(MessageSource source) { this.messageSource = source; } /** * Validate this constrainted property against specified property value * * @param target The target object to validate * @param propertyValue The value of the property to validate * @param errors The Errors instances to report errors to */ public void validate(Object target, Object propertyValue, Errors errors) { List delayedConstraints = new ArrayList(); // validate only vetoing constraints first, putting non-vetoing into delayedConstraints for(Iterator i = this.appliedConstraints.values().iterator(); i.hasNext();) { Constraint c = (Constraint) i.next(); if(c instanceof VetoingConstraint) { c.setMessageSource(this.messageSource); // stop validation process when constraint vetoes if(((VetoingConstraint)c).validateWithVetoing(target, propertyValue, errors)) return; } else { delayedConstraints.add(c); } } // process non-vetoing constraints for(Iterator i = delayedConstraints.iterator(); i.hasNext();) { Constraint c = (Constraint) i.next(); c.setMessageSource(this.messageSource); c.validate(target, propertyValue, errors); } } /** * Checks with this ConstraintedProperty instance supports applying the specified constraint * * @param constraintName The name of the constraint * @return True if the constraint is supported */ public boolean supportsContraint(String constraintName) { if(!constraints.containsKey(constraintName)) { return this.bean.isWritableProperty(constraintName); } try { Constraint c = instantiateConstraint(constraintName); return c.supports(propertyType); } catch (Exception e) { LOG.error("Exception thrown instantiating constraint ["+constraintName+"] to class ["+owningClass+"]", e); throw new ConstraintException("Exception thrown instantiating constraint ["+constraintName+"] to class ["+owningClass+"]"); } } /** * Applies a constraint for the specified name and consraint value * * @param constraintName The name of the constraint * @param constrainingValue The constraining value * * @throws ConstraintException Thrown when the specified constraint is not supported by this ConstrainedProperty. Use <code>supportsContraint(String constraintName)</code> to check before calling */ public void applyConstraint(String constraintName, Object constrainingValue) { if(constraints.containsKey(constraintName)) { if(constrainingValue == null) { this.appliedConstraints.remove(constraintName); } else { try { Constraint c = instantiateConstraint(constraintName); c.setOwningClass(this.owningClass); c.setPropertyName(this.propertyName); c.setParameter( constrainingValue ); this.appliedConstraints.put( constraintName, c ); } catch (Exception e) { LOG.error("Exception thrown applying constraint ["+constraintName+"] to class ["+owningClass+"] for value ["+constrainingValue+"]: " + e.getMessage()); throw new ConstraintException("Exception thrown applying constraint ["+constraintName+"] to class ["+owningClass+"] for value ["+constrainingValue+"]: " + e.getMessage()); } } } else if(this.bean.isWritableProperty(constraintName)) { this.bean.setPropertyValue( constraintName, constrainingValue ); } else { throw new ConstraintException("Constraint ["+constraintName+"] is not supported for property ["+propertyName+"] of class ["+owningClass+"] with type ["+propertyType+"]"); } } private Constraint instantiateConstraint(String constraintName) throws InstantiationException, IllegalAccessException { Object constraintFactory = constraints.get(constraintName); Constraint c; if(constraintFactory instanceof ConstraintFactory) c = ((ConstraintFactory)constraintFactory).newInstance(); else c = (Constraint)((Class)constraintFactory).newInstance(); return c; } /* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { return new ToStringBuilder(this) .append( this.owningClass ) .append( this.propertyName ) .append( this.propertyType ) .append( this.appliedConstraints ) .toString(); } /** * Adds a meta constraints which is a non-validating informational constraint * * @param name The name of the constraint * @param value The value */ public void addMetaConstraint(String name, Object value) { this.metaConstraints.put(name, value); } /** * Obtains the value of the named meta constraint * @param name The name of the constraint * @return The value */ public Object getMetaConstraintValue(String name) { return this.metaConstraints.get(name); } }

The table below shows all metrics for ConstrainedProperty.java.

MetricValueDescription
BLOCKS152.00Number of blocks
BLOCK_COMMENT17.00Number of block comment lines
COMMENTS215.00Comment lines
COMMENT_DENSITY 0.40Comment density
COMPARISONS99.00Number of comparison operators
CYCLOMATIC157.00Cyclomatic complexity
DECL_COMMENTS54.00Comments in declarations
DOC_COMMENT192.00Number of javadoc comment lines
ELOC537.00Effective lines of code
EXEC_COMMENTS 3.00Comments in executable code
EXITS63.00Procedure exits
FUNCTIONS61.00Number of function declarations
HALSTEAD_DIFFICULTY84.01Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY136.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003412.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 1.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA011616.00JAVA0116 Missing javadoc: field 'field'
JAVA011711.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 1.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA014419.00JAVA0144 Line exceeds maximum M characters
JAVA0145 3.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 2.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 1.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 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 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
LINES1054.00Number of lines in the source file
LINE_COMMENT 6.00Number of line comments
LOC687.00Lines of code
LOGICAL_LINES372.00Number of statements
LOOPS 2.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS1613.00Number of operands
OPERATORS3290.00Number of operators
PARAMS43.00Number of formal parameter declarations
PROGRAM_LENGTH4903.00Halstead program length
PROGRAM_VOCAB477.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS93.00Number of return points from functions
SIZE39418.00Size of the file in bytes
UNIQUE_OPERANDS432.00Number of unique operands
UNIQUE_OPERATORS45.00Number of unique operators
WHITESPACE152.00Number of whitespace lines