Class Util


  • public final class Util
    extends Object
    Utility class.
    • Field Detail

      • NEVER_MATCH

        public static final Pattern NEVER_MATCH
        A pattern that never matches (and does so efficiently)
    • Method Detail

      • getFirstIdent

        @CheckForNull
        public static String getFirstIdent​(@Nonnull
                                           DetailAST pAst)
        Determine the text of the first direct IDENT child node.
        Parameters:
        pAst - an AST
        Returns:
        the first encountered IDENT text, or null if none was found
      • getFullIdent

        @CheckForNull
        public static String getFullIdent​(@Nonnull
                                          DetailAST pAst)
        Determine the full identifier of the current element on the AST. The identifier is built from DOT and IDENT elements found directly below the specified element. Other elements encountered are ignored.
        Parameters:
        pAst - an AST
        Returns:
        the full identifier constructed from either the first encountered IDENT or DOT; null if no identifier could be constructed
      • closeQuietly

        public static void closeQuietly​(@Nullable
                                        Closeable pCloseable)
        Quietly close the given resource, ignoring any exceptions.
        Parameters:
        pCloseable - the resource to close
      • readBytes

        public static byte[] readBytes​(@Nonnull
                                       InputStream pInputStream)
                                throws IOException
        Read all bytes from an InputStream into a byte array. Can be replaced with Files.readAllBytes() once the code is migrated to Java 7.
        Parameters:
        pInputStream - the input stream
        Returns:
        the complete contents read from the input stream
        Throws:
        IOException - I/O error
      • canonize

        @Nonnull
        public static File canonize​(@Nonnull
                                    File pFile)
        Calls getCanonicalFile() on the given File; if that doesn't work, call getAbsoluteFile() on it. Thus, the resulting file is not guaranteed to exist. Separator characters are standardized to File.separatorChar.
        Parameters:
        pFile - a file
        Returns:
        the canonical representation, or the absolute representation
      • standardizeSlashes

        @Nonnull
        public static String standardizeSlashes​(@Nonnull
                                                String pPath)
        Standardizes all slashes and backslashes in the given String to File.separatorChar.
        Parameters:
        pPath - a String
        Returns:
        a new String which is pPath with standardized path separator characters
      • containsString

        public static boolean containsString​(@Nullable
                                             Iterable<String> pIterable,
                                             @Nullable
                                             String pSearched,
                                             boolean pCaseSensitive)
        Search for a String in a collection.
        Parameters:
        pIterable - the list of String to be searched
        pSearched - the String to search for
        pCaseSensitive - if comparisons should be case sensitive
        Returns:
        true if found, false otherwise
      • stringEquals

        public static boolean stringEquals​(@Nullable
                                           String pStr1,
                                           @Nullable
                                           String pStr2,
                                           boolean pCaseSensitive)
        Determine the equality of two Strings, optionally ignoring case.
        Parameters:
        pStr1 - the first String
        pStr2 - the second String
        pCaseSensitive - if the comparison should be case sensitive
        Returns:
        true if the String are equal, false otherwise
      • union

        @Nonnull
        public static <E> Set<E> union​(@Nullable
                                       Set<E> pColl1,
                                       @Nullable
                                       Set<E> pColl2)
        Creates a new immutable HashSet which contains a union of the two given sets.
        Type Parameters:
        E - type of all contained elements
        Parameters:
        pColl1 - first set
        pColl2 - second set
        Returns:
        union set
      • findLeftMostTokenInLine

        @Nonnull
        public static DetailAST findLeftMostTokenInLine​(@Nonnull
                                                        DetailAST pAst)
        Find the left-most token in the given AST. The left-most token is the token with the smallest column number. Only tokens which are located on the same line as the given AST are considered.
        Parameters:
        pAst - the root of a subtree. This token is also considered for the result.
        Returns:
        the left-most token