Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.puppycrawl.tools.checkstyle.api
Class Utils

    java.lang.Object
      com.puppycrawl.tools.checkstyle.api.Utils

    public final class Utils

extends Object

Contains utility methods.

Version:
  1.0
Author:
  Oliver Burn

Method Summary
`static String` | `baseClassname(String aType)`
`static Pattern` | `createPattern(String aPattern)` Helper method to create a regular expression.
`static File[]` | `filterFilesByExtension(File[] aFiles, String[] aFileExtensions)` Filter a set of files by their extension.
`static org.apache.commons.logging.Log` | `getExceptionLogger()` Accessor for shared instance of logger which should be used to log all exceptions occured during `FileSetCheck` work (`debug()` should be used).
`static String[]` | `getLines(String aFileName)` Loads the contents of a file in a String array.
`static String[]` | `getLines(String aFileName, String aCharsetName)` Loads the contents of a file in a String array using the named charset.
`static Pattern` | `getPattern(String aPattern)` This is a factory method to return an Pattern object for the specified regular expression.
`static Pattern` | `getPattern(String aPattern, int aCompileFlags)` This is a factory method to return an Pattern object for the specified regular expression and compile flags.
`static String` | `getStrippedFileName(String aBasedir, String aFileName)` Create a stripped down version of a filename.
`static int` | `lengthExpandedTabs(String aString, int aToIdx, int aTabWidth)` Returns the length of a String prefix with tabs expanded.
`static int` | `lengthMinusTrailingWhitespace(String aLine)` Returns the length of a string ignoring all trailing whitespace.
`static boolean` | `whitespaceBefore(int aIndex, String aLine)` Returns whether the specified string contains only whitespace up to the specified index.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Method Detail

### getExceptionLogger

    public static org.apache.commons.logging.Log getExceptionLogger()

  Accessor for shared instance of logger which should be used to log all exceptions occured during `FileSetCheck` work (`debug()` should be used).

  Returns:
    shared exception logger.

### whitespaceBefore

    public static boolean whitespaceBefore(int aIndex,
                                           String aLine)

  Returns whether the specified string contains only whitespace up to the specified index.

  Parameters:
    `aIndex` - index to check up to
    `aLine` - the line to check
  Returns:
    whether there is only whitespace

### lengthMinusTrailingWhitespace

    public static int lengthMinusTrailingWhitespace(String aLine)

  Returns the length of a string ignoring all trailing whitespace. It is a pity that there is not a trim() like method that only removed the trailing whitespace.

  Parameters:
    `aLine` - the string to process
  Returns:
    the length of the string ignoring all trailing whitespace

### lengthExpandedTabs

    public static int lengthExpandedTabs(String aString,
                                         int aToIdx,
                                         int aTabWidth)

  Returns the length of a String prefix with tabs expanded. Each tab is counted as the number of characters is takes to jump to the next tab stop.

  Parameters:
    `aString` - the input String
    `aToIdx` - index in aString (exclusive) where the calculation stops
    `aTabWidth` - the distance betweeen tab stop position.
  Returns:
    the length of aString.substring(0, aToIdx) with tabs expanded.

### getPattern

    public static Pattern getPattern(String aPattern)
                              throws PatternSyntaxException

  This is a factory method to return an Pattern object for the specified regular expression. It calls `getPattern(String, int)` with the compile flags defaults to 0.

  Parameters:
    `aPattern` - the regular expression pattern
  Returns:
    an Pattern object for the supplied pattern
  Throws:
    `PatternSyntaxException` - an invalid pattern was supplied

### getPattern

    public static Pattern getPattern(String aPattern,
                                     int aCompileFlags)
                              throws PatternSyntaxException

  This is a factory method to return an Pattern object for the specified regular expression and compile flags.

  This method is not MT safe, but neither are the returned Pattern objects.

  Parameters:
    `aPattern` - the regular expression pattern
    `aCompileFlags` - the compilation flags
  Returns:
    an Pattern object for the supplied pattern
  Throws:
    `PatternSyntaxException` - an invalid pattern was supplied

### getLines

    public static String[] getLines(String aFileName)
                             throws IOException

  Loads the contents of a file in a String array.

  Parameters:
    `aFileName` - the name of the file to load
  Returns:
    the lines in the file
  Throws:
    `IOException` - error occurred

### getLines

    public static String[] getLines(String aFileName,
                                    String aCharsetName)
                             throws IOException

  Loads the contents of a file in a String array using the named charset.

  Parameters:
    `aFileName` - the name of the file to load
    `aCharsetName` - the name of a supported charset
  Returns:
    the lines in the file
  Throws:
    `IOException` - error occurred

### createPattern

    public static Pattern createPattern(String aPattern)
                                 throws org.apache.commons.beanutils.ConversionException

  Helper method to create a regular expression.

  Parameters:
    `aPattern` - the pattern to match
  Returns:
    a created regexp object
  Throws:
    `org.apache.commons.beanutils.ConversionException` - if unable to create Pattern object.

### baseClassname

    public static String baseClassname(String aType)

  Parameters:
    `aType` - the fully qualified name. Cannot be null
  Returns:
    the base class name from a fully qualified name

### getStrippedFileName

    public static String getStrippedFileName(String aBasedir,
                                             String aFileName)

  Create a stripped down version of a filename.

  Parameters:
    `aBasedir` - the prefix to strip off the original filename
    `aFileName` - the original filename
  Returns:
    the filename where an initial prefix of basedir is stripped

### filterFilesByExtension

    public static File[] filterFilesByExtension(File[] aFiles,
                                                String[] aFileExtensions)

  Filter a set of files by their extension.

  Parameters:
    `aFiles` - a set of files
    `aFileExtensions` - a set of file extension, like ".txt" or ".java"
  Returns:
    aFiles if aFileExtensions is null or empty, the subset of aFiles that have extensions in aFileExtensions otherwise

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Back to the Checkstyle Home Page
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD