Class Utils


  • public class Utils
    extends Object
    Any kind of utility.
    Author:
    Federico Tomassetti
    • Field Detail

      • EOL

        public static final String EOL
    • Constructor Detail

      • Utils

        public Utils()
    • Method Detail

      • ensureNotNull

        public static <T> List<T> ensureNotNull​(List<T> list)
        Deprecated.
        This is no longer in use by JavaParser, please write your own replacement.
      • isNullOrEmpty

        public static <E> boolean isNullOrEmpty​(Collection<E> collection)
      • assertNotNull

        public static <T> T assertNotNull​(T o)
      • assertNonEmpty

        public static String assertNonEmpty​(String string)
      • assertNonNegative

        public static <T extends Number> T assertNonNegative​(T number)
      • assertPositive

        public static <T extends Number> T assertPositive​(T number)
      • escapeEndOfLines

        public static String escapeEndOfLines​(String string)
        Returns:
        string with ASCII characters 10 and 13 replaced by the text "\n" and "\r".
      • arrayToList

        @Deprecated
        public static <T> List<T> arrayToList​(T[] array)
        Deprecated.
        This is no longer in use by JavaParser, please write your own replacement.
        Puts varargs in a mutable list. This does not have the disadvantage of Arrays#asList that it has a static size.
      • toCamelCase

        public static String toCamelCase​(String original)
        Deprecated.
        use screamingToCamelCase
      • screamingToCamelCase

        public static String screamingToCamelCase​(String original)
        Transform a string to the camel case conversion.

        For example "ABC_DEF" becomes "abcDef"

      • camelCaseToScreaming

        public static String camelCaseToScreaming​(String input)
        Parameters:
        input - "aCamelCaseString"
        Returns:
        "A_CAMEL_CASE_STRING"
      • nextWord

        public static String nextWord​(String string)
        Return the next word of the string, in other words it stops when a space is encountered.
      • indent

        public static StringBuilder indent​(StringBuilder builder,
                                           int indentLevel)
        Make an indent by appending indentLevel tab characters to the builder.
      • capitalize

        public static String capitalize​(String s)
        Capitalizes the first character in the string.
      • decapitalize

        public static String decapitalize​(String s)
        Lower-cases the first character in the string.
      • valueIsNullOrEmpty

        public static boolean valueIsNullOrEmpty​(Object value)
        Returns:
        true if the value is null, an empty Optional, or an empty String.
      • valueIsNullOrEmptyStringOrOptional

        public static boolean valueIsNullOrEmptyStringOrOptional​(Object value)
      • set

        public static <T> Set<T> set​(T... items)
        Returns:
        a set of the items.
      • normalizeEolInTextBlock

        public static String normalizeEolInTextBlock​(String content,
                                                     String endOfLineCharacter)
        Returns:
        content with all kinds of EOL characters replaced by endOfLineCharacter
      • removeFileExtension

        public static String removeFileExtension​(String filename)
        Returns:
        the filename with the last "." and everything following it removed.
      • trimTrailingSpaces

        public static String trimTrailingSpaces​(String line)
        Like String.trim(), but only the trailing spaces.