public final class CommonUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
baseClassName(String type) |
static void |
close(Closeable closeable)
Closes a stream re-throwing IOException as IllegalStateException.
|
static Pattern |
createPattern(String pattern)
Helper method to create a regular expression.
|
static boolean |
endsWithChar(String value,
char suffix)
Tests if this string ends with the specified suffix.
|
static Constructor<?> |
getConstructor(Class<?> targetClass,
Class<?>... parameterTypes)
Gets constructor of targetClass.
|
static URI |
getUriByFilename(String filename)
Resolve the specified filename to a URI.
|
static boolean |
hasWhitespaceBefore(int index,
String line)
Returns whether the specified string contains only whitespace up to the specified index.
|
static <T> T |
invokeConstructor(Constructor<T> constructor,
Object... parameters) |
static boolean |
isPatternValid(String pattern)
Validates whether passed string is a valid pattern or not.
|
static int |
lengthExpandedTabs(String inputString,
int toIdx,
int tabWidth)
Returns the length of a String prefix with tabs expanded.
|
static int |
lengthMinusTrailingWhitespace(String line)
Returns the length of a string ignoring all trailing whitespace.
|
static boolean |
matchesFileExtension(File file,
String... fileExtensions)
Returns whether the file extension matches what we are meant to process.
|
static String |
relativizeAndNormalizePath(String baseDirectory,
String path)
Constructs a normalized relative path between base directory and a given path.
|
static boolean |
startsWithChar(String value,
char prefix)
Tests if this string starts with the specified prefix.
|
public static boolean matchesFileExtension(File file, String... fileExtensions)
file - the file to be checked.fileExtensions - files extensions, empty property in config makes it matches to all.public static boolean hasWhitespaceBefore(int index, String line)
index - index to check up toline - the line to checkpublic static int lengthMinusTrailingWhitespace(String line)
line - the string to processpublic static int lengthExpandedTabs(String inputString, int toIdx, int tabWidth)
inputString - the input StringtoIdx - index in string (exclusive) where the calculation stopstabWidth - the distance between tab stop position.public static boolean isPatternValid(String pattern)
pattern - string to validatepublic static Pattern createPattern(String pattern)
pattern - the pattern to matchorg.apache.commons.beanutils.ConversionException - if unable to create Pattern object.public static String baseClassName(String type)
type - the fully qualified name. Cannot be nullpublic static String relativizeAndNormalizePath(String baseDirectory, String path)
baseDirectory - the base path to which given path is relativizedpath - the path to relativize against base directorypublic static boolean startsWithChar(String value, char prefix)
It is faster version of String.startsWith(String) optimized for
one-character prefixes at the expense of
some readability. Suggested by SimplifyStartsWith PMD rule:
http://pmd.sourceforge.net/pmd-5.3.1/pmd-java/rules/java/optimizations.html#SimplifyStartsWith
value - the String to checkprefix - the prefix to findtrue if the char is a prefix of the given String;
false otherwise.public static boolean endsWithChar(String value, char suffix)
It is faster version of String.endsWith(String) optimized for
one-character suffixes at the expense of
some readability. Suggested by SimplifyStartsWith PMD rule:
http://pmd.sourceforge.net/pmd-5.3.1/pmd-java/rules/java/optimizations.html#SimplifyStartsWith
value - the String to checksuffix - the suffix to findtrue if the char is a suffix of the given String;
false otherwise.public static Constructor<?> getConstructor(Class<?> targetClass, Class<?>... parameterTypes)
targetClass - from which constructor is returnedparameterTypes - of constructorIllegalStateException if any exception occursClass.getConstructor(Class[])public static <T> T invokeConstructor(Constructor<T> constructor, Object... parameters)
T - type of constructorconstructor - to invokeparameters - to pass to constructorIllegalStateException if any exception occursConstructor.newInstance(Object...)public static void close(Closeable closeable)
closeable - Closeable objectpublic static URI getUriByFilename(String filename) throws CheckstyleException
filename - name os the fileCheckstyleException - on failureCopyright © 2001-2015. All Rights Reserved.