Perl5Util.java

Index Score
org.apache.oro.text.perl
Jakarta ORO

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
DOC_COMMENTNumber of javadoc comment lines
COMMENTSComment lines
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0034JAVA0034 Missing braces in if statement
JAVA0143JAVA0143 Synchronized method
SIZESize of the file in bytes
LINESNumber of lines in the source file
JAVA0126JAVA0126 Method declares unchecked exception in throws
DECL_COMMENTSComments in declarations
LINE_COMMENTNumber of line comments
JAVA0020JAVA0020 Field name does not have required form
CYCLOMATICCyclomatic complexity
RETURNSNumber of return points from functions
EXEC_COMMENTSComments in executable code
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
LOGICAL_LINESNumber of statements
INTERFACE_COMPLEXITYInterface complexity
ELOCEffective lines of code
LOCLines of code
OPERANDSNumber of operands
PROGRAM_LENGTHHalstead program length
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
OPERATORSNumber of operators
JAVA0039JAVA0039 Break statement with label
WHITESPACENumber of whitespace lines
JAVA0077JAVA0077 Private field not used in declaring class
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
UNIQUE_OPERATORSNumber of unique operators
PROGRAM_VOCABHalstead program vocabulary
COMPARISONSNumber of comparison operators
EXITSProcedure exits
UNIQUE_OPERANDSNumber of unique operands
PARAMSNumber of formal parameter declarations
LOOPSNumber of loops
FUNCTIONSNumber of function declarations
JAVA0117JAVA0117 Missing javadoc: method 'method'
BLOCKSNumber of blocks
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0018JAVA0018 Method name does not have required form
JAVA0043JAVA0043 Inner class does not use outer class
JAVA0067JAVA0067 Array descriptor on identifier name
JAVA0022JAVA0022 Static final field name does not have required form
JAVA0003JAVA0003 Minimize use of on-demand (.*) imports
JAVA0145JAVA0145 Tab character used in source file
/* * $Id: Perl5Util.java 390702 2006-04-01 17:31:03Z dfs $ * * Copyright 2000-2005 The Apache Software Foundation * * 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.apache.oro.text.perl; import java.util.*; import org.apache.oro.text.*; import org.apache.oro.text.regex.*; import org.apache.oro.util.*; /** * This is a utility class implementing the 3 most common Perl5 operations * involving regular expressions: * <ul> * <li> [m]/pattern/[i][m][s][x], * <li> s/pattern/replacement/[g][i][m][o][s][x], * <li> and split(). * </ul> * As with Perl, any non-alphanumeric character can be used in lieu of * the slashes. * <p> * The objective of the class is to minimize the amount of code a Java * programmer using Jakarta-ORO * has to write to achieve the same results as Perl by * transparently handling regular expression compilation, caching, and * matching. A second objective is to use the same Perl pattern matching * syntax to ease the task of Perl programmers transitioning to Java * (this also reduces the number of parameters to a method). * All the state affecting methods are synchronized to avoid * the maintenance of explicit locks in multithreaded programs. This * philosophy differs from the * {@link org.apache.oro.text.regex} package, where * you are expected to either maintain explicit locks, or more preferably * create separate compiler and matcher instances for each thread. * <p> * To use this class, first create an instance using the default constructor * or initialize the instance with a PatternCache of your choosing using * the alternate constructor. The default cache used by Perl5Util is a * PatternCacheLRU of capacity GenericPatternCache.DEFAULT_CAPACITY. You may * want to create a cache with a different capacity, a different * cache replacement policy, or even devise your own PatternCache * implementation. The PatternCacheLRU is probably the best general purpose * pattern cache, but your specific application may be better served by * a different cache replacement policy. You should remember that you can * front-load a cache with all the patterns you will be using before * initializing a Perl5Util instance, or you can just let Perl5Util * fill the cache as you use it. * <p> * You might use the class as follows: * <pre> * Perl5Util util = new Perl5Util(); * String line; * DataInputStream input; * PrintStream output; * * // Initialization of input and output omitted * while((line = input.readLine()) != null) { * // First find the line with the string we want to substitute because * // it is cheaper than blindly substituting each line. * if(util.match("/HREF=\"description1.html\"/", line)) { * line = util.substitute("s/description1\\.html/about1.html/", line); * } * output.println(line); * } * </pre> * <p> * A couple of things to remember when using this class are that the * {@link #match match()} methods have the same meaning as * {@link org.apache.oro.text.regex.Perl5Matcher#contains * Perl5Matcher.contains()} * and <code>=~ m/pattern/</code> in Perl. The methods are named match * to more closely associate them with Perl and to differentiate them * from {@link org.apache.oro.text.regex.Perl5Matcher#matches * Perl5Matcher.matches()}. * A further thing to keep in mind is that the * {@link MalformedPerl5PatternException} class is derived from * RuntimeException which means you DON'T have to catch it. The reasoning * behind this is that you will detect your regular expression mistakes * as you write and debug your program when a MalformedPerl5PatternException * is thrown during a test run. However, we STRONGLY recommend that you * ALWAYS catch MalformedPerl5PatternException whenever you deal with a * DYNAMICALLY created pattern. Relying on a fatal * MalformedPerl5PatternException being thrown to detect errors while * debugging is only useful for dealing with static patterns, that is, actual * pregenerated strings present in your program. Patterns created from user * input or some other dynamic method CANNOT be relied upon to be correct * and MUST be handled by catching MalformedPerl5PatternException for your * programs to be robust. * <p> * Finally, as a convenience Perl5Util implements * the {@link org.apache.oro.text.regex.MatchResult MatchResult} interface. * The methods are merely wrappers which call the corresponding method of * the last {@link org.apache.oro.text.regex.MatchResult MatchResult} * found (which can be accessed with {@link #getMatch()}) by a match or * substitution (or even a split, but this isn't particularly useful). * The * {@link org.apache.oro.text.regex.MatchResult MatchResult} returned * by {@link #getMatch()} is stored in a thread-local variable. Therefore * concurrent calls to {@link #getMatch()} will produce the last match * found by the calling thread. * * @version @version@ * @since 1.0 * @see MalformedPerl5PatternException * @see org.apache.oro.text.PatternCache * @see org.apache.oro.text.PatternCacheLRU * @see org.apache.oro.text.regex.MatchResult */ public final class Perl5Util implements MatchResult { /** The regular expression to use to parse match expression. */ private static final String __matchExpression = "m?(\\W)(.*)\\1([imsx]*)"; /** The pattern cache to compile and store patterns */ private PatternCache __patternCache; /** The hashtable to cache higher-level expressions */ private Cache __expressionCache; /** The pattern matcher to perform matching operations. */ private Perl5Matcher __matcher; /** The compiled match expression parsing regular expression. */ private Pattern __matchPattern; class ThreadState { /** The last match from a successful call to a matching method. */ MatchResult lastMatch = null; /** * Keeps track of the original input (for postMatch() and preMatch()) * methods. This will be discarded if the preMatch() and postMatch() * methods are moved into the MatchResult interface. */ Object originalInput = null; /** * Keeps track of the begin and end offsets of the original input for * the postMatch() and preMatch() methods. */ private int inputBeginOffset = 0, inputEndOffset = 0; } private ThreadLocal __threadState; /** * A container for temporarily holding the results of a split before * deleting trailing empty fields. */ private ArrayList __splitList; /** Used for default return value of post and pre Match() */ private static final String __nullString = ""; /** * A constant passed to the {@link #split split()} methods indicating * that all occurrences of a pattern should be used to split a string. */ public static final int SPLIT_ALL = Util.SPLIT_ALL; /** * A secondary constructor for Perl5Util. It initializes the Perl5Matcher * used by the class to perform matching operations, but requires the * programmer to provide a PatternCache instance for the class * to use to compile and store regular expressions. You would want to * use this constructor if you want to change the capacity or policy * of the cache used. Example uses might be: * <pre> * // We know we're going to use close to 50 expressions a whole lot, so * // we create a cache of the proper size. * util = new Perl5Util(new PatternCacheLRU(50)); * </pre> * or * <pre> * // We're only going to use a few expressions and know that second-chance * // fifo is best suited to the order in which we are using the patterns. * util = new Perl5Util(new PatternCacheFIFO2(10)); * </pre> */ public Perl5Util(PatternCache cache) { __splitList = new ArrayList(); __matcher = new Perl5Matcher(); __threadState = new ThreadLocal() { protected synchronized Object initialValue() { return new ThreadState(); } }; __patternCache = cache; __expressionCache = new CacheLRU(cache.capacity()); __compilePatterns(); } /** * Default constructor for Perl5Util. This initializes the Perl5Matcher * used by the class to perform matching operations and creates a * default PatternCacheLRU instance to use to compile and cache regular * expressions. The size of this cache is * GenericPatternCache.DEFAULT_CAPACITY. */ public Perl5Util() { this(new PatternCacheLRU()); } /** * A convenience method to take care of typecasting. Wouldn't be * necessary if we we could use Java Generics. **/ private ThreadState __getState() { return (ThreadState)__threadState.get(); } /** * Compiles the patterns (currently only the match expression) used to * parse Perl5 expressions. Right now it initializes __matchPattern. */ private void __compilePatterns() { Perl5Compiler compiler = new Perl5Compiler(); try { __matchPattern = compiler.compile(__matchExpression, Perl5Compiler.SINGLELINE_MASK); } catch(MalformedPatternException e) { // This should only happen during debugging. //e.printStackTrace(); throw new RuntimeException(e.getMessage()); } } /** * Parses a match expression and returns a compiled pattern. * First checks the expression cache and if the pattern is not found, * then parses the expression and fetches a compiled pattern from the * pattern cache. Otherwise, just uses the pattern found in the * expression cache. __matchPattern is used to parse the expression. * <p> * @param pattern The Perl5 match expression to parse. * @exception MalformedPerl5PatternException If there is an error parsing * the expression. */ private Pattern __parseMatchExpression(String pattern) throws MalformedPerl5PatternException { int index, compileOptions; String options, regex; MatchResult result; Object obj; Pattern ret; obj = __expressionCache.getElement(pattern); // Must catch ClassCastException because someone might incorrectly // pass an s/// expression. try block is cheaper than checking // instanceof try { if(obj != null) return (Pattern)obj; } catch(ClassCastException e) { // Fall through and parse expression } if(!__matcher.matches(pattern, __matchPattern)) throw new MalformedPerl5PatternException("Invalid expression: " + pattern); result = __matcher.getMatch(); regex = result.group(2); compileOptions = Perl5Compiler.DEFAULT_MASK; options = result.group(3); if(options != null) { index = options.length(); while(index-- > 0) { switch(options.charAt(index)) { case 'i' : compileOptions |= Perl5Compiler.CASE_INSENSITIVE_MASK; break; case 'm' : compileOptions |= Perl5Compiler.MULTILINE_MASK; break; case 's' : compileOptions |= Perl5Compiler.SINGLELINE_MASK; break; case 'x' : compileOptions |= Perl5Compiler.EXTENDED_MASK; break; default : throw new MalformedPerl5PatternException("Invalid options: " + options); } } } ret = __patternCache.getPattern(regex, compileOptions); __expressionCache.addElement(pattern, ret); return ret; } /** * Searches for the first pattern match somewhere in a character array * taking a pattern specified in Perl5 native format: * <blockquote><pre> * [m]/pattern/[i][m][s][x] * </pre></blockquote> * The <code>m</code> prefix is optional and the meaning of the optional * trailing options are: * <dl compact> * <dt> i <dd> case insensitive match * <dt> m <dd> treat the input as consisting of multiple lines * <dt> s <dd> treat the input as consisting of a single line * <dt> x <dd> enable extended expression syntax incorporating whitespace * and comments * </dl> * As with Perl, any non-alphanumeric character can be used in lieu of * the slashes. * <p> * If the input contains the pattern, the org.apache.oro.text.regex.MatchResult * can be obtained by calling {@link #getMatch()}. * However, Perl5Util implements the MatchResult interface as a wrapper * around the last MatchResult found, so you can call its methods to * access match information. * <p> * @param pattern A Perl5 regular expression to compile and search for. * @param input The char[] input to search. * @return True if the input contains the pattern, false otherwise. * @exception MalformedPerl5PatternException If there is an error in * the pattern. You are not forced to catch this exception * because it is derived from RuntimeException. */ public synchronized boolean match(String pattern, char[] input) throws MalformedPerl5PatternException { boolean result; __parseMatchExpression(pattern); result = __matcher.contains(input, __parseMatchExpression(pattern)); if(result) { ThreadState state = __getState(); state.lastMatch = __matcher.getMatch(); state.originalInput = input; state.inputBeginOffset = 0; state.inputEndOffset = input.length; } return result; } /** * Searches for the first pattern match in a String taking * a pattern specified in Perl5 native format: * <blockquote><pre> * [m]/pattern/[i][m][s][x] * </pre></blockquote> * The <code>m</code> prefix is optional and the meaning of the optional * trailing options are: * <dl compact> * <dt> i <dd> case insensitive match * <dt> m <dd> treat the input as consisting of multiple lines * <dt> s <dd> treat the input as consisting of a single line * <dt> x <dd> enable extended expression syntax incorporating whitespace * and comments * </dl> * As with Perl, any non-alphanumeric character can be used in lieu of * the slashes. * <p> * If the input contains the pattern, the * {@link org.apache.oro.text.regex.MatchResult MatchResult} * can be obtained by calling {@link #getMatch()}. * However, Perl5Util implements the MatchResult interface as a wrapper * around the last MatchResult found, so you can call its methods to * access match information. * <p> * @param pattern A Perl5 regular expression to compile and search for. * @param input The String input to search. * @return True if the input contains the pattern, false otherwise. * @exception MalformedPerl5PatternException If there is an error in * the pattern. You are not forced to catch this exception * because it is derived from RuntimeException. */ public synchronized boolean match(String pattern, String input) throws MalformedPerl5PatternException { return match(pattern, input.toCharArray()); } /** * Searches for the next pattern match somewhere in a * org.apache.oro.text.regex.PatternMatcherInput instance, taking * a pattern specified in Perl5 native format: * <blockquote><pre> * [m]/pattern/[i][m][s][x] * </pre></blockquote> * The <code>m</code> prefix is optional and the meaning of the optional * trailing options are: * <dl compact> * <dt> i <dd> case insensitive match * <dt> m <dd> treat the input as consisting of multiple lines * <dt> s <dd> treat the input as consisting of a single line * <dt> x <dd> enable extended expression syntax incorporating whitespace * and comments * </dl> * As with Perl, any non-alphanumeric character can be used in lieu of * the slashes. * <p> * If the input contains the pattern, the * {@link org.apache.oro.text.regex.MatchResult MatchResult} * can be obtained by calling {@link #getMatch()}. * However, Perl5Util implements the MatchResult interface as a wrapper * around the last MatchResult found, so you can call its methods to * access match information. * After the call to this method, the PatternMatcherInput current offset * is advanced to the end of the match, so you can use it to repeatedly * search for expressions in the entire input using a while loop as * explained in the {@link org.apache.oro.text.regex.PatternMatcherInput * PatternMatcherInput} documentation. * <p> * @param pattern A Perl5 regular expression to compile and search for. * @param input The PatternMatcherInput to search. * @return True if the input contains the pattern, false otherwise. * @exception MalformedPerl5PatternException If there is an error in * the pattern. You are not forced to catch this exception * because it is derived from RuntimeException. */ public synchronized boolean match(String pattern, PatternMatcherInput input) throws MalformedPerl5PatternException { boolean result; result = __matcher.contains(input, __parseMatchExpression(pattern)); if(result) { ThreadState state = __getState(); state.lastMatch = __matcher.getMatch(); state.originalInput = input.getInput(); state.inputBeginOffset = input.getBeginOffset(); state.inputEndOffset = input.getEndOffset(); } return result; } /** * Returns the last match found by a call to a match(), substitute(), or * split() method. This method is only intended for use to retrieve a match * found by the last match found by a match() method. This method should * be used when you want to save MatchResult instances. Otherwise, for * simply accessing match information, it is more convenient to use the * Perl5Util methods implementing the MatchResult interface. * <p> * @return The org.apache.oro.text.regex.MatchResult instance containing the * last match found. */ public synchronized MatchResult getMatch() { return __getState().lastMatch; } /** * Substitutes a pattern in a given input with a replacement string. * The substitution expression is specified in Perl5 native format: * <blockquote><pre> * s/pattern/replacement/[g][i][m][o][s][x] * </pre></blockquote> * The <code>s</code> prefix is mandatory and the meaning of the optional * trailing options are: * <dl compact> * <dt> g <dd> Substitute all occurrences of pattern with replacement. * The default is to replace only the first occurrence. * <dt> i <dd> perform a case insensitive match * <dt> m <dd> treat the input as consisting of multiple lines * <dt> o <dd> If variable interopolation is used, only evaluate the * interpolation once (the first time). This is equivalent * to using a numInterpolations argument of 1 in * {@link org.apache.oro.text.regex.Util#substitute Util.substitute()}. * The default is to compute each interpolation independently. * See * {@link org.apache.oro.text.regex.Util#substitute Util.substitute()} * and {@link org.apache.oro.text.regex.Perl5Substitution Perl5Substitution} * for more details on variable interpolation in * substitutions. * <dt> s <dd> treat the input as consisting of a single line * <dt> x <dd> enable extended expression syntax incorporating whitespace * and comments * </dl> * As with Perl, any non-alphanumeric character can be used in lieu of * the slashes. This is helpful to avoid backslashing. For example, * using slashes you would have to do: * <blockquote><pre> * numSubs = util.substitute(result, "s/foo\\/bar/goo\\/\\/baz/", input); * </pre></blockquote> * when you could more easily write: * <blockquote><pre> * numSubs = util.substitute(result, "s#foo/bar#goo//baz#", input); * </pre></blockquote> * where the hashmarks are used instead of slashes. * <p> * There is a special case of backslashing that you need to pay attention * to. As demonstrated above, to denote a delimiter in the substituted * string it must be backslashed. However, this can be a problem * when you want to denote a backslash at the end of the substituted * string. As of PerlTools 1.3, a new means of handling this * situation has been implemented. * In previous versions, the behavior was that * <blockquote> * "... a double backslash (quadrupled in the Java String) always * represents two backslashes unless the second backslash is followed * by the delimiter, in which case it represents a single backslash." * </blockquote> * <p> * The new behavior is that a backslash is always a backslash * in the substitution portion of the expression unless it is used to * escape a delimiter. A backslash is considered to escape a delimiter * if an even number of contiguous backslashes preceed the backslash * and the delimiter following the backslash is not the FINAL delimiter * in the expression. Therefore, backslashes preceding final delimiters * are never considered to escape the delimiter. The following, which * used to be an invalid expression and require a special-case extra * backslash, will now replace all instances of / with \: * <blockquote><pre> * numSubs = util.substitute(result, "s#/#\\#g", input); * </pre></blockquote> * <p> * @param result The StringBuffer in which to store the result of the * substitutions. The buffer is only appended to. * @param expression The Perl5 substitution regular expression. * @param input The input on which to perform substitutions. * @return The number of substitutions made. * @exception MalformedPerl5PatternException If there is an error in * the expression. You are not forced to catch this exception * because it is derived from RuntimeException. * @since 2.0.6 */ // Expression parsing will have to be moved into a separate method if // there are going to be variations of this method. public synchronized int substitute(StringBuffer result, String expression, String input) throws MalformedPerl5PatternException { boolean backslash, finalDelimiter; int index, compileOptions, numSubstitutions, numInterpolations; int firstOffset, secondOffset, thirdOffset, subCount; StringBuffer replacement; Pattern compiledPattern; char exp[], delimiter; ParsedSubstitutionEntry entry; Perl5Substitution substitution; Object obj; obj = __expressionCache.getElement(expression); __nullTest: if(obj != null) { // Must catch ClassCastException because someone might incorrectly // pass an m// expression. try block is cheaper than checking // instanceof. We want to go ahead with parsing just in case so // we break. try { entry = (ParsedSubstitutionEntry)obj; } catch(ClassCastException e) { break __nullTest; } subCount = Util.substitute(result, __matcher, entry._pattern, entry._substitution, input, entry._numSubstitutions); __getState().lastMatch = __matcher.getMatch(); return subCount; } exp = expression.toCharArray(); // Make sure basic conditions for a valid substitution expression hold. if(exp.length < 4 || exp[0] != 's' || Character.isLetterOrDigit(exp[1]) || exp[1] == '-') throw new MalformedPerl5PatternException("Invalid expression: " + expression); delimiter = exp[1]; firstOffset = 2; secondOffset = thirdOffset = -1; backslash = false; // Parse pattern for(index = firstOffset; index < exp.length; index++) { if(exp[index] == '\\') backslash = !backslash; else if(exp[index] == delimiter && !backslash) { secondOffset = index; break; } else if(backslash) backslash = !backslash; } if(secondOffset == -1 || secondOffset == exp.length - 1) throw new MalformedPerl5PatternException("Invalid expression: " + expression); // Parse replacement string backslash = false; finalDelimiter = true; replacement = new StringBuffer(exp.length - secondOffset); for(index = secondOffset + 1; index < exp.length; index++) { if(exp[index] == '\\') { backslash = !backslash; // 05/05/99 dfs // We unbackslash backslashed delimiters in the replacement string // only if we're on an odd backslash and there is another occurrence // of a delimiter later in the string. if(backslash && index + 1 < exp.length && exp[index + 1] == delimiter && expression.lastIndexOf(delimiter, exp.length - 1) != (index + 1)) { finalDelimiter = false; continue; } } else if(exp[index] == delimiter && finalDelimiter) { thirdOffset = index; break; } else { backslash = false; finalDelimiter = true; } replacement.append(exp[index]); } if(thirdOffset == -1) throw new MalformedPerl5PatternException("Invalid expression: " + expression); compileOptions = Perl5Compiler.DEFAULT_MASK; numSubstitutions = 1; // Single quotes cause no interpolations to be performed in replacement if(delimiter != '\'') numInterpolations = Perl5Substitution.INTERPOLATE_ALL; else numInterpolations = Perl5Substitution.INTERPOLATE_NONE; // Parse options for(index = thirdOffset + 1; index < exp.length; index++) { switch(exp[index]) { case 'i' : compileOptions |= Perl5Compiler.CASE_INSENSITIVE_MASK; break; case 'm' : compileOptions |= Perl5Compiler.MULTILINE_MASK; break; case 's' : compileOptions |= Perl5Compiler.SINGLELINE_MASK; break; case 'x' : compileOptions |= Perl5Compiler.EXTENDED_MASK; break; case 'g' : numSubstitutions = Util.SUBSTITUTE_ALL; break; case 'o' : numInterpolations = 1; break; default : throw new MalformedPerl5PatternException("Invalid option: " + exp[index]); } } compiledPattern = __patternCache.getPattern(new String(exp, firstOffset, secondOffset - firstOffset), compileOptions); substitution = new Perl5Substitution(replacement.toString(), numInterpolations); entry = new ParsedSubstitutionEntry(compiledPattern, substitution, numSubstitutions); __expressionCache.addElement(expression, entry); subCount = Util.substitute(result, __matcher, compiledPattern, substitution, input, numSubstitutions); __getState().lastMatch = __matcher.getMatch(); return subCount; } /** * Substitutes a pattern in a given input with a replacement string. * The substitution expression is specified in Perl5 native format. * <dl compact> * <dt>Calling this method is the same as:</dt> * <dd> * <blockquote><pre> * String result; * StringBuffer buffer = new StringBuffer(); * perl.substitute(buffer, expression, input); * result = buffer.toString(); * </pre></blockquote> * </dd> * </dl> * @param expression The Perl5 substitution regular expression. * @param input The input on which to perform substitutions. * @return The input as a String after substitutions have been performed. * @exception MalformedPerl5PatternException If there is an error in * the expression. You are not forced to catch this exception * because it is derived from RuntimeException. * @since 1.0 * @see #substitute */ public synchronized String substitute(String expression, String input) throws MalformedPerl5PatternException { StringBuffer result = new StringBuffer(); substitute(result, expression, input); return result.toString(); } /** * Splits a String into strings that are appended to a List, but no more * than a specified limit. The String is split using a regular expression * as the delimiter. The regular expression is a pattern specified * in Perl5 native format: * <blockquote><pre> * [m]/pattern/[i][m][s][x] * </pre></blockquote> * The <code>m</code> prefix is optional and the meaning of the optional * trailing options are: * <dl compact> * <dt> i <dd> case insensitive match * <dt> m <dd> treat the input as consisting of multiple lines * <dt> s <dd> treat the input as consisting of a single line * <dt> x <dd> enable extended expression syntax incorporating whitespace * and comments * </dl> * As with Perl, any non-alphanumeric character can be used in lieu of * the slashes. * <p> * The limit parameter causes the string to be split on at most the first * <b>limit - 1</b> number of pattern occurences. * <p> * Of special note is that this split method performs EXACTLY the same * as the Perl split() function. In other words, if the split pattern * contains parentheses, additional Vector elements are created from * each of the matching subgroups in the pattern. Using an example * similar to the one from the Camel book: * <blockquote><pre> * split(list, "/([,-])/", "8-12,15,18") * </pre></blockquote> * produces the Vector containing: * <blockquote><pre> * { "8", "-", "12", ",", "15", ",", "18" } * </pre></blockquote> * Furthermore, the following Perl behavior is observed: "leading empty * fields are preserved, and empty trailing one are deleted." This * has the effect that a split on a zero length string returns an empty * list. * The {@link org.apache.oro.text.regex.Util#split Util.split()} method * does NOT implement these behaviors because it is intended to * be a general self-consistent and predictable split function usable * with Pattern instances other than Perl5Pattern. * <p> * @param results * A <code> Collection </code> to which the substrings of the input * that occur between the regular expression delimiter occurences * are appended. The input will not be split into any more substrings * than the specified * limit. A way of thinking of this is that only the first * <b>limit - 1</b> * matches of the delimiting regular expression will be used to split the * input. The Collection must support the * <code>addAll(Collection)</code> operation. * @param pattern The regular expression to use as a split delimiter. * @param input The String to split. * @param limit The limit on the size of the returned <code>Vector</code>. * Values <= 0 produce the same behavior as the SPLIT_ALL constant which * causes the limit to be ignored and splits to be performed on all * occurrences of the pattern. You should use the SPLIT_ALL constant * to achieve this behavior instead of relying on the default behavior * associated with non-positive limit values. * @exception MalformedPerl5PatternException If there is an error in * the expression. You are not forced to catch this exception * because it is derived from RuntimeException. */ public synchronized void split(Collection results, String pattern, String input, int limit) throws MalformedPerl5PatternException { int beginOffset, groups, index; String group; MatchResult currentResult = null; PatternMatcherInput pinput; Pattern compiledPattern; compiledPattern = __parseMatchExpression(pattern); pinput = new PatternMatcherInput(input); beginOffset = 0; while(--limit != 0 && __matcher.contains(pinput, compiledPattern)) { currentResult = __matcher.getMatch(); __splitList.add(input.substring(beginOffset, currentResult.beginOffset(0))); if((groups = currentResult.groups()) > 1) { for(index = 1; index < groups; ++index) { group = currentResult.group(index); if(group != null && group.length() > 0) __splitList.add(group); } } beginOffset = currentResult.endOffset(0); } __splitList.add(input.substring(beginOffset, input.length())); // Remove all trailing empty fields. for(int i = __splitList.size() - 1; i >= 0; --i) { String str; str = (String)__splitList.get(i); if(str.length() == 0) __splitList.remove(i); else break; } results.addAll(__splitList); __splitList.clear(); // Just for the sake of completeness __getState().lastMatch = currentResult; } /** * This method is identical to calling: * <blockquote><pre> * split(results, pattern, input, SPLIT_ALL); * </pre></blockquote> */ public synchronized void split(Collection results, String pattern, String input) throws MalformedPerl5PatternException { split(results, pattern, input, SPLIT_ALL); } /** * Splits input in the default Perl manner, splitting on all whitespace. * This method is identical to calling: * <blockquote><pre> * split(results, "/\\s+/", input); * </pre></blockquote> */ public synchronized void split(Collection results, String input) throws MalformedPerl5PatternException { split(results, "/\\s+/", input); } /** * Splits a String into strings contained in a Vector of size no greater * than a specified limit. The String is split using a regular expression * as the delimiter. The regular expression is a pattern specified * in Perl5 native format: * <blockquote><pre> * [m]/pattern/[i][m][s][x] * </pre></blockquote> * The <code>m</code> prefix is optional and the meaning of the optional * trailing options are: * <dl compact> * <dt> i <dd> case insensitive match * <dt> m <dd> treat the input as consisting of multiple lines * <dt> s <dd> treat the input as consisting of a single line * <dt> x <dd> enable extended expression syntax incorporating whitespace * and comments * </dl> * As with Perl, any non-alphanumeric character can be used in lieu of * the slashes. * <p> * The limit parameter causes the string to be split on at most the first * <b>limit - 1</b> number of pattern occurences. * <p> * Of special note is that this split method performs EXACTLY the same * as the Perl split() function. In other words, if the split pattern * contains parentheses, additional Vector elements are created from * each of the matching subgroups in the pattern. Using an example * similar to the one from the Camel book: * <blockquote><pre> * split("/([,-])/", "8-12,15,18") * </pre></blockquote> * produces the Vector containing: * <blockquote><pre> * { "8", "-", "12", ",", "15", ",", "18" } * </pre></blockquote> * The {@link org.apache.oro.text.regex.Util#split Util.split()} method * does NOT implement this particular behavior because it is intended to * be usable with Pattern instances other than Perl5Pattern. * <p> * @deprecated Use * {@link #split(Collection results, String pattern, String input, int limit)} * instead. * @param pattern The regular expression to use as a split delimiter. * @param input The String to split. * @param limit The limit on the size of the returned <code>Vector</code>. * Values <= 0 produce the same behavior as the SPLIT_ALL constant which * causes the limit to be ignored and splits to be performed on all * occurrences of the pattern. You should use the SPLIT_ALL constant * to achieve this behavior instead of relying on the default behavior * associated with non-positive limit values. * @return A <code> Vector </code> containing the substrings of the input * that occur between the regular expression delimiter occurences. The * input will not be split into any more substrings than the specified * limit. A way of thinking of this is that only the first * <b>limit - 1</b> * matches of the delimiting regular expression will be used to split the * input. * @exception MalformedPerl5PatternException If there is an error in * the expression. You are not forced to catch this exception * because it is derived from RuntimeException. */ public synchronized Vector split(String pattern, String input, int limit) throws MalformedPerl5PatternException { Vector results = new Vector(20); split(results, pattern, input, limit); return results; } /** * This method is identical to calling: * <blockquote><pre> * split(pattern, input, SPLIT_ALL); * </pre></blockquote> * @deprecated Use * {@link #split(Collection results, String pattern, String input)} instead. */ public synchronized Vector split(String pattern, String input) throws MalformedPerl5PatternException { return split(pattern, input, SPLIT_ALL); } /** * Splits input in the default Perl manner, splitting on all whitespace. * This method is identical to calling: * <blockquote><pre> * split("/\\s+/", input); * </pre></blockquote> * @deprecated Use * {@link #split(Collection results, String input)} instead. */ public synchronized Vector split(String input) throws MalformedPerl5PatternException { return split("/\\s+/", input); } // // MatchResult interface methods. // /** * Returns the length of the last match found. * <p> * @return The length of the last match found. */ public synchronized int length() { return getMatch().length(); } /** * @return The number of groups contained in the last match found. * This number includes the 0th group. In other words, the * result refers to the number of parenthesized subgroups plus * the entire match itself. */ public synchronized int groups() { return getMatch().groups(); } /** * Returns the contents of the parenthesized subgroups of the last match * found according to the behavior dictated by the MatchResult interface. * <p> * @param group The pattern subgroup to return. * @return A string containing the indicated pattern subgroup. Group * 0 always refers to the entire match. If a group was never * matched, it returns null. This is not to be confused with * a group matching the null string, which will return a String * of length 0. */ public synchronized String group(int group) { return getMatch().group(group); } /** * Returns the begin offset of the subgroup of the last match found * relative the beginning of the match. * <p> * @param group The pattern subgroup. * @return The offset into group 0 of the first token in the indicated * pattern subgroup. If a group was never matched or does * not exist, returns -1. Be aware that a group that matches * the null string at the end of a match will have an offset * equal to the length of the string, so you shouldn't blindly * use the offset to index an array or String. */ public synchronized int begin(int group) { return getMatch().begin(group); } /** * Returns the end offset of the subgroup of the last match found * relative the beginning of the match. * <p> * @param group The pattern subgroup. * @return Returns one plus the offset into group 0 of the last token in * the indicated pattern subgroup. If a group was never matched * or does not exist, returns -1. A group matching the null * string will return its start offset. */ public synchronized int end(int group) { return getMatch().end(group); } /** * Returns an offset marking the beginning of the last pattern match * found relative to the beginning of the input from which the match * was extracted. * <p> * @param group The pattern subgroup. * @return The offset of the first token in the indicated * pattern subgroup. If a group was never matched or does * not exist, returns -1. */ public synchronized int beginOffset(int group) { return getMatch().beginOffset(group); } /** * Returns an offset marking the end of the last pattern match found * relative to the beginning of the input from which the match was * extracted. * <p> * @param group The pattern subgroup. * @return Returns one plus the offset of the last token in * the indicated pattern subgroup. If a group was never matched * or does not exist, returns -1. A group matching the null * string will return its start offset. */ public synchronized int endOffset(int group) { return getMatch().endOffset(group); } /** * Returns the same as group(0). * <p> * @return A string containing the entire match. */ public synchronized String toString() { MatchResult match = getMatch(); if(match == null) return null; return match.toString(); } /** * Returns the part of the input preceding the last match found. * <p> * @return The part of the input following the last match found. */ public synchronized String preMatch() { ThreadState state = __getState(); if(state.originalInput == null) return __nullString; int begin = beginOffset(0); if(begin <= 0) return __nullString; if(state.originalInput instanceof char[]) { char[] input; input = (char[])state.originalInput; // Just in case we make sure begin offset is in bounds. It should // be but we're paranoid. if(begin > input.length) begin = input.length; return new String(input, state.inputBeginOffset, begin); } else if(state.originalInput instanceof String) { String input; input = (String)state.originalInput; // Just in case we make sure begin offset is in bounds. It should // be but we're paranoid. if(begin > input.length()) begin = input.length(); return input.substring(state.inputBeginOffset, begin); } return __nullString; } /** * Returns the part of the input following the last match found. * <p> * @return The part of the input following the last match found. */ public synchronized String postMatch() { ThreadState state = __getState(); if(state.originalInput == null) return __nullString; int end = endOffset(0); if(end < 0) return __nullString; if(state.originalInput instanceof char[]) { char[] input; input = (char[])state.originalInput; // Just in case we make sure begin offset is in bounds. It should // be but we're paranoid. if(end >= input.length) return __nullString; return new String(input, end, state.inputEndOffset - end); } else if(state.originalInput instanceof String) { String input; input = (String)state.originalInput; // Just in case we make sure begin offset is in bounds. It should // be but we're paranoid. if(end >= input.length()) return __nullString; return input.substring(end, state.inputEndOffset); } return __nullString; } /** * Returns the part of the input preceding the last match found as a * char array. This method eliminates the extra * buffer copying caused by preMatch().toCharArray(). * <p> * @return The part of the input preceding the last match found as a char[]. * If the result is of zero length, returns null instead of a zero * length array. */ public synchronized char[] preMatchCharArray() { ThreadState state = __getState(); int begin; char[] result = null; if(state.originalInput == null) return null; begin = beginOffset(0); if(begin <= 0) return null; if(state.originalInput instanceof char[]) { char[] input; input = (char[])state.originalInput; // Just in case we make sure begin offset is in bounds. It should // be but we're paranoid. if(begin >= input.length) begin = input.length; result = new char[begin - state.inputBeginOffset]; System.arraycopy(input, state.inputBeginOffset, result, 0, result.length); } else if(state.originalInput instanceof String) { String input; input = (String)state.originalInput; // Just in case we make sure begin offset is in bounds. It should // be but we're paranoid. if(begin >= input.length()) begin = input.length(); result = new char[begin - state.inputBeginOffset]; input.getChars(state.inputBeginOffset, begin, result, 0); } return result; } /** * Returns the part of the input following the last match found as a char * array. This method eliminates the extra buffer copying caused by * preMatch().toCharArray(). * <p> * @return The part of the input following the last match found as a char[]. * If the result is of zero length, returns null instead of a zero * length array. */ public synchronized char[] postMatchCharArray() { ThreadState state = __getState(); int end; char[] result = null; if(state.originalInput == null) return null; end = endOffset(0); if(end < 0) return null; if(state.originalInput instanceof char[]) { int length; char[] input; input = (char[])state.originalInput; // Just in case we make sure begin offset is in bounds. It should // be but we're paranoid. if(end >= input.length) return null; length = state.inputEndOffset - end; result = new char[length]; System.arraycopy(input, end, result, 0, length); } else if(state.originalInput instanceof String) { String input; input = (String)state.originalInput; // Just in case we make sure begin offset is in bounds. It should // be but we're paranoid. if(end >= state.inputEndOffset) return null; result = new char[state.inputEndOffset - end]; input.getChars(end, state.inputEndOffset, result, 0); } return result; } }

The table below shows all metrics for Perl5Util.java.

MetricValueDescription
BLOCKS61.00Number of blocks
BLOCK_COMMENT17.00Number of block comment lines
COMMENTS691.00Comment lines
COMMENT_DENSITY 1.89Comment density
COMPARISONS49.00Number of comparison operators
CYCLOMATIC107.00Cyclomatic complexity
DECL_COMMENTS44.00Comments in declarations
DOC_COMMENT632.00Number of javadoc comment lines
ELOC366.00Effective lines of code
EXEC_COMMENTS20.00Comments in executable code
EXITS51.00Procedure exits
FUNCTIONS30.00Number of function declarations
HALSTEAD_DIFFICULTY120.50Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY102.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 1.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 3.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 6.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 2.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
JAVA003429.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 1.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 1.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 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 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 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 2.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 0.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 9.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 4.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 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 4.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
JAVA012612.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA014325.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA0145100.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA017744.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 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
LINES1274.00Number of lines in the source file
LINE_COMMENT42.00Number of line comments
LOC434.00Lines of code
LOGICAL_LINES248.00Number of statements
LOOPS 7.00Number of loops
NEST_DEPTH 4.00Maximum nesting depth
OPERANDS960.00Number of operands
OPERATORS1753.00Number of operators
PARAMS33.00Number of formal parameter declarations
PROGRAM_LENGTH2713.00Halstead program length
PROGRAM_VOCAB299.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS69.00Number of return points from functions
SIZE46624.00Size of the file in bytes
UNIQUE_OPERANDS239.00Number of unique operands
UNIQUE_OPERATORS60.00Number of unique operators
WHITESPACE149.00Number of whitespace lines