public final class Util
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.regex.Pattern |
NEVER_MATCH
A pattern that never matches (and does so efficiently)
|
static java.nio.charset.Charset |
UTF8
Constant for UTF-8 charset; can be replaced with StandardCharsets.UTF_8 after moving to Java 7
|
Modifier and Type | Method and Description |
---|---|
static java.io.File |
canonize(java.io.File pFile)
Calls getCanonicalFile() on the given File; if that doesn't work, call getAbsoluteFile() on it.
|
static void |
closeQuietly(java.io.Closeable pCloseable)
Quietly close the given resource, ignoring any exceptions.
|
static boolean |
containsString(java.lang.Iterable<java.lang.String> pIterable,
java.lang.String pSearched,
boolean pCaseSensitive)
Search for a String in a collection.
|
static com.puppycrawl.tools.checkstyle.api.DetailAST |
findLeftMostTokenInLine(com.puppycrawl.tools.checkstyle.api.DetailAST pAst)
Find the left-most token in the given AST.
|
static java.lang.String |
getFirstIdent(com.puppycrawl.tools.checkstyle.api.DetailAST pAst)
Determine the text of the first direct IDENT child node.
|
static java.lang.String |
getFullIdent(com.puppycrawl.tools.checkstyle.api.DetailAST pAst)
Determine the full identifier of the current element on the AST.
|
static byte[] |
readBytes(java.io.InputStream pInputStream)
Read all bytes from an InputStream into a byte array.
|
static java.lang.String |
standardizeSlashes(java.lang.String pPath)
Standardizes all slashes and backslashes in the given String to
File.separatorChar . |
static boolean |
stringEquals(java.lang.String pStr1,
java.lang.String pStr2,
boolean pCaseSensitive)
Determine the equality of two Strings, optionally ignoring case.
|
static <E> java.util.Set<E> |
union(java.util.Set<E> pColl1,
java.util.Set<E> pColl2)
Creates a new immutable
HashSet which contains a union of the two given sets. |
static <E extends java.lang.Enum<E>> |
valueOfIgnoreCase(java.lang.String pValue,
java.lang.Class<E> pEnumClass)
Variant of
Enum.valueOf(java.lang.Class<T>, java.lang.String) that ignores value case. |
public static final java.util.regex.Pattern NEVER_MATCH
public static final java.nio.charset.Charset UTF8
@Nonnull public static java.io.File canonize(@Nonnull java.io.File pFile)
File.separatorChar
.pFile
- a filepublic static void closeQuietly(@Nullable java.io.Closeable pCloseable)
pCloseable
- the resource to closepublic static boolean containsString(@Nullable java.lang.Iterable<java.lang.String> pIterable, @Nullable java.lang.String pSearched, boolean pCaseSensitive)
pIterable
- the list of String to be searchedpSearched
- the String to search forpCaseSensitive
- if comparisons should be case sensitivetrue
if found, false
otherwise@Nonnull public static com.puppycrawl.tools.checkstyle.api.DetailAST findLeftMostTokenInLine(@Nonnull com.puppycrawl.tools.checkstyle.api.DetailAST pAst)
pAst
- the root of a subtree. This token is also considered for the result.@CheckForNull public static java.lang.String getFirstIdent(@Nonnull com.puppycrawl.tools.checkstyle.api.DetailAST pAst)
pAst
- an ASTnull
if none was found@CheckForNull public static java.lang.String getFullIdent(@Nonnull com.puppycrawl.tools.checkstyle.api.DetailAST pAst)
pAst
- an ASTnull
if no
identifier could be constructedpublic static byte[] readBytes(@Nonnull java.io.InputStream pInputStream) throws java.io.IOException
Files.readAllBytes()
once
the code is migrated to Java 7.pInputStream
- the input streamjava.io.IOException
- I/O error@Nonnull public static java.lang.String standardizeSlashes(@Nonnull java.lang.String pPath)
File.separatorChar
.pPath
- a StringpPath
with standardized path separator characterspublic static boolean stringEquals(@Nullable java.lang.String pStr1, @Nullable java.lang.String pStr2, boolean pCaseSensitive)
pStr1
- the first StringpStr2
- the second StringpCaseSensitive
- if the comparison should be case sensitivetrue
if the String are equal, false
otherwise@Nonnull public static <E> java.util.Set<E> union(@Nullable java.util.Set<E> pColl1, @Nullable java.util.Set<E> pColl2)
HashSet
which contains a union of the two given sets.E
- type of all contained elementspColl1
- first setpColl2
- second set@Nonnull public static <E extends java.lang.Enum<E>> E valueOfIgnoreCase(@Nonnull java.lang.String pValue, @Nonnull java.lang.Class<E> pEnumClass)
Enum.valueOf(java.lang.Class<T>, java.lang.String)
that ignores value case.E
- the enum typepValue
- the String valuepEnumClass
- the class object of the enum typejava.lang.IllegalArgumentException
- the given String value does not match a valid enum value