public final class CommonUtils extends Object
Modifier and Type | Field and Description |
---|---|
static byte[] |
EMPTY_BYTE_ARRAY
Copied from org.apache.commons.lang3.ArrayUtils.
|
static double[] |
EMPTY_DOUBLE_ARRAY
Copied from org.apache.commons.lang3.ArrayUtils.
|
static int[] |
EMPTY_INT_ARRAY
Copied from org.apache.commons.lang3.ArrayUtils.
|
static Integer[] |
EMPTY_INTEGER_OBJECT_ARRAY
Copied from org.apache.commons.lang3.ArrayUtils.
|
static Object[] |
EMPTY_OBJECT_ARRAY
Copied from org.apache.commons.lang3.ArrayUtils.
|
static String[] |
EMPTY_STRING_ARRAY
Copied from org.apache.commons.lang3.ArrayUtils.
|
Modifier and Type | Method and Description |
---|---|
static String |
baseClassName(String type)
Returns base class name from qualified name.
|
static void |
close(Closeable closeable)
Closes a stream re-throwing IOException as IllegalStateException.
|
static DetailAST |
createBlockCommentNode(String content)
Create block comment from string content.
|
static DetailAST |
createBlockCommentNode(antlr.Token token)
Create block comment from token.
|
static Pattern |
createPattern(String pattern)
Helper method to create a regular expression.
|
static Pattern |
createPattern(String pattern,
int flags)
Helper method to create a regular expression with a specific flags.
|
static boolean |
endsWithChar(String value,
char suffix)
Tests if this string ends with the specified suffix.
|
static String |
fillTemplateWithStringsByRegexp(String template,
String lineToPlaceInTemplate,
Pattern regexp)
Puts part of line, which matches regexp into given template
on positions $n where 'n' is number of matched part in line.
|
static <T> Constructor<T> |
getConstructor(Class<T> targetClass,
Class<?>... parameterTypes)
Gets constructor of targetClass.
|
static String |
getFileExtension(String fileNameWithExtension)
Returns file extension for the given file name
or empty string if file does not have an extension.
|
static String |
getFileNameWithoutExtension(String fullFilename)
Returns file name without extension.
|
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)
Returns new instance of a class.
|
static boolean |
isBlank(String value)
Checks if the value arg is blank by either being null,
empty, or contains only whitespace characters.
|
static boolean |
isIdentifier(String str)
Checks whether the given string is a valid identifier.
|
static boolean |
isInt(String str)
Checks whether the string contains an integer value.
|
static boolean |
isName(String str)
Checks whether the given string is a valid name.
|
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 final String[] EMPTY_STRING_ARRAY
public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY
public static final Object[] EMPTY_OBJECT_ARRAY
public static final int[] EMPTY_INT_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY
public static final double[] EMPTY_DOUBLE_ARRAY
public static Pattern createPattern(String pattern)
pattern
- the pattern to matchorg.apache.commons.beanutils.ConversionException
- if unable to create Pattern object.public static Pattern createPattern(String pattern, int flags)
pattern
- the pattern to matchflags
- the flags to setIllegalArgumentException
- if unable to create Pattern object.public static DetailAST createBlockCommentNode(String content)
content
- comment content.public static DetailAST createBlockCommentNode(antlr.Token token)
token
- Token object.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 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 <T> Constructor<T> getConstructor(Class<T> targetClass, Class<?>... parameterTypes)
T
- type of the target class object.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 failurepublic static String fillTemplateWithStringsByRegexp(String template, String lineToPlaceInTemplate, Pattern regexp)
template
- the string to expand.lineToPlaceInTemplate
- contains expression which should be placed into string.regexp
- expression to find in comment.public static String getFileNameWithoutExtension(String fullFilename)
fullFilename
- file name with extension.public static String getFileExtension(String fileNameWithExtension)
fileNameWithExtension
- file name with extension.public static boolean isIdentifier(String str)
str
- A string to check.public static boolean isName(String str)
str
- A string to check.public static boolean isBlank(String value)
value
- A string to check.Copyright © 2001–2018. All rights reserved.