public final class Util extends Object
Modifier and Type | Field and Description |
---|---|
static Pattern |
NEVER_MATCH
A pattern that never matches (and does so efficiently)
|
static 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 File |
canonize(File pFile)
Calls getCanonicalFile() on the given File; if that doesn't work, call getAbsoluteFile() on it.
|
static void |
closeQuietly(Closeable pCloseable)
Quietly close the given resource, ignoring any exceptions.
|
static boolean |
containsString(Iterable<String> pIterable,
String pSearched,
boolean pCaseSensitive)
Search for a String in a collection.
|
static DetailAST |
findLeftMostTokenInLine(DetailAST pAst)
Find the left-most token in the given AST.
|
static String |
getFirstIdent(DetailAST pAst)
Determine the text of the first direct IDENT child node.
|
static String |
getFullIdent(DetailAST pAst)
Determine the full identifier of the current element on the AST.
|
static byte[] |
readBytes(InputStream pInputStream)
Read all bytes from an InputStream into a byte array.
|
static String |
standardizeSlashes(String pPath)
Standardizes all slashes and backslashes in the given String to
File.separatorChar . |
static boolean |
stringEquals(String pStr1,
String pStr2,
boolean pCaseSensitive)
Determine the equality of two Strings, optionally ignoring case.
|
static <E> Set<E> |
union(Set<E> pColl1,
Set<E> pColl2)
Creates a new immutable
HashSet which contains a union of the two given sets. |
static <E extends Enum<E>> |
valueOfIgnoreCase(String pValue,
Class<E> pEnumClass)
Variant of
Enum.valueOf(java.lang.Class<T>, java.lang.String) that ignores value case. |
public static final Pattern NEVER_MATCH
public static final Charset UTF8
@Nonnull public static File canonize(@Nonnull File pFile)
File.separatorChar
.pFile
- a filepublic static void closeQuietly(@Nullable Closeable pCloseable)
pCloseable
- the resource to closepublic static boolean containsString(@Nullable Iterable<String> pIterable, @Nullable 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 DetailAST findLeftMostTokenInLine(@Nonnull DetailAST pAst)
pAst
- the root of a subtree. This token is also considered for the result.@CheckForNull public static String getFirstIdent(@Nonnull DetailAST pAst)
pAst
- an ASTnull
if none was found@CheckForNull public static String getFullIdent(@Nonnull DetailAST pAst)
pAst
- an ASTnull
if no
identifier could be constructedpublic static byte[] readBytes(@Nonnull InputStream pInputStream) throws IOException
Files.readAllBytes()
once
the code is migrated to Java 7.pInputStream
- the input streamIOException
- I/O error@Nonnull public static String standardizeSlashes(@Nonnull String pPath)
File.separatorChar
.pPath
- a StringpPath
with standardized path separator characterspublic static boolean stringEquals(@Nullable String pStr1, @Nullable 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> Set<E> union(@Nullable Set<E> pColl1, @Nullable 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 Enum<E>> E valueOfIgnoreCase(@Nonnull String pValue, @Nonnull 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 typeIllegalArgumentException
- the given String value does not match a valid enum value